Skip to content

Commit

Permalink
feat: use release type from message
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Nov 3, 2023
1 parent 551093e commit 2803060
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,27 +403,35 @@ jobs:
run: |
npm config set provenance true
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 git log -1 --pretty=%B | grep -E "^[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 -E "^[0-9]+\.[0-9]+\.[0-9]+"; 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 next --access public
pnpm publish --tag $RELEASE_TYPE --access public
else
echo "Not a release, skipping publish"
echo "Commit does not start with 'release', skipping publish"
fi
elif [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
if git log -1 --pretty=%B | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$"; 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 canary --access public --no-git-checks
pnpm publish --tag $RELEASE_TYPE --access public --no-git-checks
else
echo "Not a release, skipping publish"
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 2803060

Please sign in to comment.