fix: Using a temporary PR branch for prereleases (#135) #25
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 Pipeline | |
| on: | |
| push: | |
| branches: | |
| - alpha | |
| - beta | |
| - rc | |
| - main | |
| paths-ignore: | |
| - ".changeset/**" | |
| - "CHANGELOG.md" | |
| workflow_dispatch: | |
| inputs: | |
| release_type: | |
| description: "Release type for manual trigger" | |
| required: true | |
| default: "stable" | |
| type: choice | |
| options: | |
| - rc | |
| - stable | |
| confirm_release: | |
| description: "Type 'CONFIRM' to proceed with release" | |
| required: true | |
| type: string | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| # Allow concurrent prereleases but serialize stable ones | |
| cancel-in-progress: ${{ contains(fromJson('["alpha","beta"]'), github.ref_name) }} | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| id-token: write | |
| packages: write | |
| jobs: | |
| # Automated pre-release job for alpha and beta branches | |
| prerelease: | |
| runs-on: ubuntu-latest | |
| if: contains(fromJson('["alpha", "beta"]'), github.ref_name) && !contains(github.event.head_commit.message, '[skip ci]') | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9.12.0 | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "pnpm" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run validation | |
| run: pnpm run validate | |
| - name: Check bundle size | |
| run: pnpm run size | |
| - name: Build packages | |
| run: pnpm run build:production | |
| - name: Semantic Release (Prerelease) | |
| id: semantic | |
| run: pnpm run release:semantic | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create or Update Release PR | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "chore(release): automated prerelease update" | |
| title: "chore(release): ${{ github.ref_name }} prerelease" | |
| branch: release/${{ github.ref_name }}-pr | |
| base: release/${{ github.ref_name }} | |
| body: | | |
| Automated release PR containing updated CHANGELOG and package versions. | |
| Generated by semantic-release. | |
| labels: release | |
| add-paths: | | |
| CHANGELOG.md | |
| package.json | |
| pnpm-lock.yaml | |
| - name: Build documentation | |
| if: success() | |
| run: pnpm run docs:build | |
| - name: Upload build artifacts | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: prerelease-artifacts-${{ github.ref_name }} | |
| path: | | |
| dist/ | |
| ui/dist/ | |
| docs/ | |
| storybook-static/ | |
| retention-days: 30 | |
| # Manual release job for rc and main branches | |
| stable-release: | |
| runs-on: ubuntu-latest | |
| if: > | |
| (github.event_name == 'workflow_dispatch') || | |
| (contains(fromJson('["rc","main"]'), github.ref_name) && | |
| !contains(github.event.head_commit.message, '[skip ci]')) | |
| outputs: | |
| published: ${{ steps.changesets.outputs.published }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9.12.0 | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "pnpm" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run validation | |
| run: pnpm run validate | |
| - name: Check bundle size | |
| run: pnpm run size | |
| - name: Validate Manual Release | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| if [ "${{ github.event.inputs.confirm_release }}" != "CONFIRM" ]; then | |
| echo "Release not confirmed. Please type 'CONFIRM' to proceed." | |
| exit 1 | |
| fi | |
| echo "Release confirmed for ${{ github.event.inputs.release_type }} on branch ${{ github.ref_name }}" | |
| - name: Setup Git | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| - name: Build packages | |
| run: pnpm run build:production | |
| - name: Create Release Pull Request or Publish (Stable) | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| publish: pnpm changeset:publish | |
| version: pnpm changeset:version | |
| commit: "chore: release stable version" | |
| title: "chore: release stable version" | |
| createGithubReleases: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Build documentation | |
| if: steps.changesets.outputs.published == 'true' | |
| run: pnpm run docs:build | |
| - name: Upload build artifacts | |
| if: steps.changesets.outputs.published == 'true' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: stable-artifacts-${{ github.ref_name }} | |
| path: | | |
| dist/ | |
| ui/dist/ | |
| docs/ | |
| storybook-static/ | |
| retention-days: 90 | |
| # Notify on failures | |
| notify-failure: | |
| needs: [prerelease, stable-release] | |
| runs-on: ubuntu-latest | |
| if: always() && (needs.prerelease.result == 'failure' || needs.stable-release.result == 'failure') | |
| steps: | |
| - name: Notify on failure | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const branch = '${{ github.ref_name }}'; | |
| const runUrl = `${context.payload.repository.html_url}/actions/runs/${context.runId}`; | |
| github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `🚨 Release Failed on ${branch}`, | |
| body: `The release workflow failed on branch \`${branch}\`.\n\n**Workflow Run:** ${runUrl}\n\nPlease check the logs for details.`, | |
| labels: ['bug', 'release', `branch:${branch}`] | |
| }); | |
| # Update dev branch after stable release | |
| sync-dev: | |
| needs: stable-release | |
| runs-on: ubuntu-latest | |
| if: needs.stable-release.result == 'success' && github.ref_name == 'main' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Sync main back to dev | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git checkout dev | |
| git merge main --no-ff -m "chore: sync main back to dev after stable release" || true | |
| git push origin dev |