generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from layer5io/344-create-prerelease
ci(repo): create pre-release.yml workflow
- Loading branch information
Showing
4 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
11 changes: 1 addition & 10 deletions
11
.github/workflows/release.yml → .github/workflows/_release.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |