|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - next |
| 7 | + schedule: |
| 8 | + - cron: "0 9 * * 1" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: release-${{ github.event_name == 'schedule' && 'main' || github.ref_name }} |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + release: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Guard workflow_dispatch caller permissions |
| 24 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 25 | + uses: actions/github-script@v8 |
| 26 | + with: |
| 27 | + script: | |
| 28 | + const { owner, repo } = context.repo; |
| 29 | + const username = context.actor; |
| 30 | + const result = await github.rest.repos.getCollaboratorPermissionLevel({ |
| 31 | + owner, |
| 32 | + repo, |
| 33 | + username, |
| 34 | + }); |
| 35 | +
|
| 36 | + const role = result.data.role_name ?? result.data.permission; |
| 37 | + const allowed = new Set(["maintain", "admin"]); |
| 38 | +
|
| 39 | + if (!allowed.has(role)) { |
| 40 | + core.setFailed( |
| 41 | + `User ${username} has role '${role}'. Only maintain/admin may invoke workflow_dispatch releases.`, |
| 42 | + ); |
| 43 | + return; |
| 44 | + } |
| 45 | +
|
| 46 | + core.info(`workflow_dispatch authorized for ${username} (${role})`); |
| 47 | +
|
| 48 | + - name: Resolve and validate target branch |
| 49 | + id: target |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + if [ "${{ github.event_name }}" = "schedule" ]; then |
| 53 | + branch="main" |
| 54 | + else |
| 55 | + branch="${{ github.ref_name }}" |
| 56 | + fi |
| 57 | +
|
| 58 | + case "$branch" in |
| 59 | + main|next) ;; |
| 60 | + *) |
| 61 | + echo "Unsupported release branch: $branch" |
| 62 | + echo "Allowed branches: main, next" |
| 63 | + exit 1 |
| 64 | + ;; |
| 65 | + esac |
| 66 | +
|
| 67 | + echo "branch=$branch" >> "$GITHUB_OUTPUT" |
| 68 | + echo "Releasing from branch: $branch" |
| 69 | +
|
| 70 | + - name: Checkout code |
| 71 | + uses: actions/checkout@v6 |
| 72 | + with: |
| 73 | + fetch-depth: 0 |
| 74 | + ref: ${{ steps.target.outputs.branch }} |
| 75 | + |
| 76 | + - name: Setup Node.js |
| 77 | + uses: actions/setup-node@v6 |
| 78 | + with: |
| 79 | + node-version: 22 |
| 80 | + cache: npm |
| 81 | + registry-url: https://registry.npmjs.org |
| 82 | + |
| 83 | + - name: Install dependencies |
| 84 | + run: npm ci |
| 85 | + |
| 86 | + - name: Build |
| 87 | + run: npm run build |
| 88 | + |
| 89 | + - name: Unit tests |
| 90 | + run: npm test |
| 91 | + |
| 92 | + - name: Lint and format check |
| 93 | + run: npm run check:ci |
| 94 | + |
| 95 | + - name: Type check |
| 96 | + run: npx tsc --noEmit |
| 97 | + |
| 98 | + - name: Run semantic-release |
| 99 | + env: |
| 100 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 102 | + GITHUB_REF: refs/heads/${{ steps.target.outputs.branch }} |
| 103 | + GITHUB_REF_NAME: ${{ steps.target.outputs.branch }} |
| 104 | + run: npm run release:run |
0 commit comments