Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(repo): create pre-release.yml workflow #345

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions .github/workflows/release.yml → .github/workflows/_release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
name: Publish NPM Package

on:
release:
types: [published]
branches:
- 'v-*'
- master
workflow_dispatch:
inputs:
release-type:
required: true
on: workflow_dispatch

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Pre-release and Publish to NPM

on: workflow_dispatch

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install deps and build
run: |
yarn
yarn build-all

publish-gpr:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
scope: "@layer5"

- name: Identify changed packages
run: |
CHANGED_PACKAGES=$(yarn lerna changed --json | jq -r '.[].name')
echo $CHANGED_PACKAGES

- name: Version packages
run: ./version-prerelease-packages.sh $CHANGED_PACKAGES

- name: Commit changes
run: |
if [ -n "$(git status --porcelain)" ]; then
git add .
git commit -m "chore: publish"
git push origin HEAD
else
echo "No changes to commit."
fi

- name: Create Git tags
run: ./create-multiple-git-tag.sh

- name: Publish packages
run: yarn lerna publish from-package --yes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
19 changes: 19 additions & 0 deletions scripts/create-multiple-git-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

for dir in $(HUSKY=0 yarn lerna ls --json --all | jq -r '.[].location'); do
VERSION=$(node -e "console.log(require('$dir/package.json').version)")
NAME=$(node -e "console.log(require('$dir/package.json').name)")
TAG="$NAME@v$VERSION"

# Check if the tag already exists
if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null; then
echo "Git tag $TAG already exists. Skipping tag creation."
else
# Tag doesn't exist, create it
git tag -a "$TAG" -m "Version $VERSION"
echo "Git tag $TAG created"
fi
done

# Push all tags
git push --tags
20 changes: 20 additions & 0 deletions scripts/version-prerelease-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Usage: version-prerelrease-packages.sh
# Example: version-prerelrease-packages.sh

# Get the list of changed packages using Lerna
CHANGED_PACKAGES=$(HUSKY=0 yarn lerna changed --json | jq -r '.[].name')

if [ -n "$CHANGED_PACKAGES" ]; then
echo "Changed packages detected: $CHANGED_PACKAGES"
HUSKY=0 yarn lerna version --no-private --conventional-commits --conventional-prerelease --include-merged-tags --no-git-tag-version --yes

# Stage changes to package.json files
for PACKAGE_NAME in $CHANGED_PACKAGES; do
PACKAGE_PATH="packages/$(echo $PACKAGE_NAME | tr -d '@' | sed 's/\//-/')"
grep -q "\"name\": \"$PACKAGE_NAME\"" "$PACKAGE_PATH/package.json" && git add "$PACKAGE_PATH/package.json"
done
else
echo "No changed packages detected. Skipping lerna version."
fi