Skip to content

Commit

Permalink
fix: parse commit message correctly (#6)
Browse files Browse the repository at this point in the history
* fix: parse commit message correctly

* refactor: remove unused `--no-git-checks`
  • Loading branch information
nachoaldamav authored Nov 12, 2023
1 parent 81cdf74 commit 3b6fd07
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand Down Expand Up @@ -215,7 +215,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand Down Expand Up @@ -254,7 +254,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand Down Expand Up @@ -295,7 +295,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand Down Expand Up @@ -338,7 +338,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand Down Expand Up @@ -384,7 +384,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.10.0
version: 8.10.2
run_install: false
standalone: true

Expand All @@ -403,26 +403,46 @@ 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 it's a pull request event, use the PR title or the head commit message
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
COMMIT_MESSAGE=$(jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH")
else
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
fi
RELEASE_TYPE=$(echo $COMMIT_MESSAGE | grep -oE "\(([a-zA-Z]+)\)" | tr -d '()')
if [ "${GITHUB_REF##*/}" = "main" ]; then
if [[ $COMMIT_MESSAGE == release* ]]; then
if [[ $COMMIT_MESSAGE =~ ^release(\ \([a-zA-Z]+\))?:\ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; 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
npm 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
if [[ $COMMIT_MESSAGE =~ ^release(\ \([a-zA-Z]+\))?:\ v[0-9]+\.[0-9]+\.[0-9]+$ ]]; 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

# Extract the current version from package.json
CURRENT_VERSION=$(jq -r '.version' package.json)

# Create a new pre-release version by appending the commit hash to the current version
NEW_VERSION="$CURRENT_VERSION-canary.$COMMIT_HASH"

# Update package.json with the new version
jq --arg newVersion "$NEW_VERSION" '.version = $newVersion' package.json > temp.json && mv temp.json package.json

echo "Updated version to $NEW_VERSION"

pnpm run version

# Set up .npmrc config file for authentication
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
pnpm publish --tag $RELEASE_TYPE --access public --no-git-checks

# Publish the package with the new canary version
npm publish --tag $RELEASE_TYPE --access public
else
echo "PR does not start with 'release', skipping publish"
fi
Expand Down

0 comments on commit 3b6fd07

Please sign in to comment.