Publish packages and create tags #193
This file contains hidden or 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
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: "Type of release (prerelease, prepatch, patch, minor, preminor, major)" | |
required: true | |
default: "patch" | |
dry_run: | |
description: "Dry run (no actual publishing or commits)" | |
required: false | |
default: false | |
type: boolean | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: pnpm/action-setup@v3 | |
with: | |
version: 10.0.0 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 'lts/*' | |
cache: 'pnpm' | |
- name: Configure Git | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: "Setup npm for npmjs" | |
run: | | |
npm config set registry https://registry.npmjs.org/ | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Install Protobuf Compiler | |
run: sudo apt-get install -y protobuf-compiler | |
- name: Install dependencies | |
run: pnpm install | |
- name: Check for packages to be bumped | |
id: check-status | |
run: | | |
# Run changeset status and capture output | |
STATUS=$(pnpm changeset status) | |
echo "Changeset status:" | |
echo "$STATUS" | |
# Count occurrences of "NO packages to be bumped" | |
COUNT=$(echo "$STATUS" | grep -c "NO packages to be bumped") | |
if [ "$COUNT" -eq 3 ]; then | |
exit 0 | |
else | |
echo "Packages need to be bumped. Exiting workflow." | |
fi | |
- name: Version packages | |
id: changesets-version | |
run: | | |
# Apply version bump based on release type | |
pnpm changeset version | |
# Store the new version | |
NEW_VERSION=$(node -p "require('./package.json').version") | |
echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
# If this is a dry run, revert the version changes | |
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then | |
echo "DRY RUN: Would version packages to ${NEW_VERSION}" | |
git checkout -- . | |
fi | |
- name: Build packages | |
run: pnpm build | |
- name: Publish to npm | |
if: ${{ github.event.inputs.dry_run != 'true' }} | |
run: pnpm publish --no-git-checks | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Dry run - Show npm publish | |
if: ${{ github.event.inputs.dry_run == 'true' }} | |
run: | | |
echo "DRY RUN: Would publish the following packages to npm:" | |
echo "Version: ${{ steps.changesets-version.outputs.new_version }}" | |
pnpm publish --dry-run | |
- name: Commit changes | |
if: ${{ github.event.inputs.dry_run != 'true' }} | |
run: | | |
git add . | |
git commit -m "chore: release v${{ steps.changesets-version.outputs.new_version }}" || echo "No changes to commit" | |
- name: Create and push tag | |
if: ${{ github.event.inputs.dry_run != 'true' }} | |
run: | | |
git tag v${{ steps.changesets-version.outputs.new_version }} | |
git push origin v${{ steps.changesets-version.outputs.new_version }} | |
git push origin main | |
- name: Dry run - Show git changes | |
if: ${{ github.event.inputs.dry_run == 'true' }} | |
run: | | |
echo "DRY RUN: Would commit changes with message: chore: release v${{ steps.changesets-version.outputs.new_version }}" | |
echo "DRY RUN: Would create and push tag: v${{ steps.changesets-version.outputs.new_version }}" | |
git status | |
- name: Generate release notes | |
id: generate-notes | |
run: | | |
pnpm exec changeset changelog | |
RELEASE_NOTES=$(cat CHANGELOG.md | sed -n -e '/^## /{n;:a;n;/^## /q;p;ba}' | tr -d '\n') | |
echo "release_notes<<EOF" >> $GITHUB_OUTPUT | |
echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
# If this is a dry run, revert the changelog changes | |
if [ "${{ github.event.inputs.dry_run }}" == "true" ]; then | |
git checkout -- CHANGELOG.md | |
fi | |
- name: Create GitHub Release | |
if: ${{ github.event.inputs.dry_run != 'true' }} | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ steps.changesets-version.outputs.new_version }} | |
release_name: Release v${{ steps.changesets-version.outputs.new_version }} | |
body: ${{ steps.generate-notes.outputs.release_notes }} | |
draft: false | |
prerelease: false | |
- name: Dry run - Show GitHub Release | |
if: ${{ github.event.inputs.dry_run == 'true' }} | |
run: | | |
echo "DRY RUN: Would create GitHub release with tag: v${{ steps.changesets-version.outputs.new_version }}" | |
echo "DRY RUN: Release notes would be:" | |
echo "${{ steps.generate-notes.outputs.release_notes }}" |