Skip to content

Commit

Permalink
feat: release canary versions from PRs (#4)
Browse files Browse the repository at this point in the history
* feat: release canary versions from PRs

* fix: only publish to canary if it's a release

* feat: use release type from message
  • Loading branch information
nachoaldamav committed Nov 3, 2023
1 parent 808dbb5 commit 7e00206
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,36 @@ jobs:
- name: Publish
run: |
npm config set provenance true
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
pnpm publish --access public
elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
then
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
pnpm publish --tag next --access public
COMMIT_HASH=$(git rev-parse --short HEAD)
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
RELEASE_TYPE=$(echo $COMMIT_MESSAGE | grep -oE "^release \(([a-zA-Z]+)\): [0-9]+\.[0-9]+\.[0-9]+$" | grep -oE "\(([a-zA-Z]+)\)" | tr -d '()')
if [ "${GITHUB_REF##*/}" = "main" ]; then
if [[ $COMMIT_MESSAGE == release* ]]; then
# Use a default release type of 'latest' if no type is specified in the commit message
RELEASE_TYPE=${RELEASE_TYPE:-latest}
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
pnpm publish --tag $RELEASE_TYPE --access public
else
echo "Commit does not start with 'release', skipping publish"
fi
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
if [[ $COMMIT_MESSAGE == release* ]]; then
# Use a default release type of 'canary' if no type is specified in the commit message
RELEASE_TYPE=${RELEASE_TYPE:-canary}
jq --arg hash "$COMMIT_HASH" '.version = $hash' package.json > temp.json && mv temp.json package.json
pnpm run version
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
pnpm publish --tag $RELEASE_TYPE --access public --no-git-checks
else
echo "PR does not start with 'release', skipping publish"
fi
else
echo "Not a release, skipping publish"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}



0 comments on commit 7e00206

Please sign in to comment.