Skip to content

Release

Release #2

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
type: choice
options:
- 'pre-release (next)'
- 'stable release'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Clean
run: npm run clean
- name: Build
run: npm run build
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Version packages (pre-release)
if: inputs.release_type == 'pre-release (next)'
run: |
npx changeset pre enter next || true
npx changeset version
- name: Version packages (stable)
if: inputs.release_type == 'stable release'
run: |
npx changeset pre exit || true
npx changeset version
- name: Update lock file
run: npm install --package-lock-only
- name: Publish to npm
id: publish
run: |
set +e
OUTPUT=$(npx changeset publish 2>&1)
EXIT_CODE=$?
echo "$OUTPUT"
set -e
if [ $EXIT_CODE -ne 0 ]; then
echo "::error::Changeset publish failed with exit code $EXIT_CODE"
exit $EXIT_CODE
fi
# Extract published packages for PR comment
PUBLISHED=$(echo "$OUTPUT" | grep -E "^@walkeros/|^walkeros" | head -20 || true)
echo "published<<EOF" >> $GITHUB_OUTPUT
echo "$PUBLISHED" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit version changes
run: |
git add -A
git commit -m "chore: version packages" || echo "No changes to commit"
git push
- name: Comment on PR
if: steps.publish.outputs.published != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=$(gh pr list --head "${{ github.ref_name }}" --state open --json number --jq '.[0].number' || true)
if [ -n "$PR_NUMBER" ] && [ "$PR_NUMBER" != "null" ]; then
if [ "${{ inputs.release_type }}" = "pre-release (next)" ]; then
EMOJI="📦"
TITLE="Pre-release published (next)"
INSTALL_TAG="@next"
else
EMOJI="🚀"
TITLE="Stable release published"
INSTALL_TAG="@latest"
fi
BODY="$EMOJI **$TITLE**
${{ steps.publish.outputs.published }}
Install: \`npm i @walkeros/core$INSTALL_TAG\`"
gh pr comment "$PR_NUMBER" --body "$BODY"
echo "Commented on PR #$PR_NUMBER"
else
echo "No open PR found for branch ${{ github.ref_name }}"
fi