Repository navigation
Release: Pre-Release Testing #2
Workflow file for this run
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: Pre-release Tag | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: [feat/semantic-release] | |
| jobs: | |
| pre-release: | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get PR type from description | |
| id: pr-type | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const body = context.payload.pull_request.body || ''; | |
| const typeMatch = body.match(/type:\s*(feat|fix|chore|docs|refactor)/i); | |
| if (!typeMatch) { | |
| core.setOutput('type', 'fix'); | |
| return; | |
| } | |
| const type = typeMatch[1].toLowerCase(); | |
| core.setOutput('type', type); | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Install semantic-release | |
| run: | | |
| npm install -g \ | |
| semantic-release \ | |
| @semantic-release/commit-analyzer \ | |
| @semantic-release/release-notes-generator \ | |
| @semantic-release/github | |
| - name: Create conventional commit | |
| env: | |
| COMMIT_TYPE: ${{ steps.pr-type.outputs.type }} | |
| run: | | |
| git config user.email "ci@github.com" | |
| git config user.name "GitHub CI" | |
| ORIGINAL_MSG=$(git log -1 --pretty=%s) | |
| git commit --allow-empty -m "${COMMIT_TYPE}: ${ORIGINAL_MSG}" | |
| - name: Run semantic-release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: npx semantic-release | |
| - name: Update PR labels | |
| if: success() | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const prNumber = context.payload.pull_request.number; | |
| const labelsToCreate = [ | |
| { name: 'released', color: '0075ca' }, | |
| { name: 'released on @main', color: '0052cc' } | |
| ]; | |
| for (const label of labelsToCreate) { | |
| try { | |
| await github.rest.issues.getLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: label.name | |
| }); | |
| } catch { | |
| await github.rest.issues.createLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: label.name, | |
| color: label.color | |
| }); | |
| } | |
| } | |
| await github.rest.issues.removeAllLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber | |
| }); | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: ['released', 'released on @main'] | |
| }); |