Skip to content

Commit

Permalink
Merge pull request #345 from layer5io/344-create-prerelease
Browse files Browse the repository at this point in the history
ci(repo): create pre-release.yml workflow
  • Loading branch information
nebula-aac authored Nov 17, 2023
2 parents d8647c2 + 068a01a commit 2823043
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 10 deletions.
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

0 comments on commit 2823043

Please sign in to comment.