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

feat: release canary versions from PRs #4

Merged
merged 3 commits into from
Nov 3, 2023
Merged
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
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 }}