|
| 1 | +# Based on https://github.com/directus/eslint-config/blob/main/.github/workflows/release.yml |
| 2 | + |
| 3 | +name: Release |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: SemVer for the release, for example "1.0.0" |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + check-version: |
| 15 | + name: Check Version |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + version: ${{ steps.version.outputs.release }} |
| 19 | + is-prerelease: ${{ steps.version.outputs.prerelease && true || false }} |
| 20 | + steps: |
| 21 | + - name: Check version |
| 22 | + uses: madhead/semver-utils@v4 |
| 23 | + id: version |
| 24 | + with: |
| 25 | + version: ${{ inputs.version }} |
| 26 | + lenient: false |
| 27 | + |
| 28 | + create-version: |
| 29 | + name: Create Version |
| 30 | + needs: check-version |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: write |
| 34 | + steps: |
| 35 | + - name: Checkout repository |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Setup env |
| 39 | + uses: ./.github/actions/setup |
| 40 | + |
| 41 | + - name: Bump version |
| 42 | + run: pnpm version --no-git-tag-version '${{ needs.check-version.outputs.version }}' |
| 43 | + |
| 44 | + - name: Create version commit & tag |
| 45 | + run: | |
| 46 | + author='${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>' |
| 47 | + version='v${{ needs.check-version.outputs.version }}' |
| 48 | + branch='${{ github.ref }}' |
| 49 | +
|
| 50 | + git config user.name 'github-actions[bot]' |
| 51 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 52 | +
|
| 53 | + git commit --all --author "$author" --message "$version" |
| 54 | +
|
| 55 | + git tag --annotate "$version" --message "$version" |
| 56 | +
|
| 57 | + git push --atomic origin "$branch" "refs/tags/${version}" |
| 58 | +
|
| 59 | + create-release: |
| 60 | + name: Create Release |
| 61 | + needs: |
| 62 | + - check-version |
| 63 | + - create-version |
| 64 | + runs-on: ubuntu-latest |
| 65 | + permissions: |
| 66 | + contents: write |
| 67 | + steps: |
| 68 | + - name: Checkout repository |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Create release |
| 72 | + env: |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + run: | |
| 75 | + gh release create \ |
| 76 | + 'v${{ needs.check-version.outputs.version }}' \ |
| 77 | + --verify-tag \ |
| 78 | + --generate-notes \ |
| 79 | + ${{ needs.check-version.outputs.is-prerelease == 'true' && '--prerelease' || '' }} |
| 80 | +
|
| 81 | + publish-npm: |
| 82 | + name: Publish to NPM |
| 83 | + needs: |
| 84 | + - check-version |
| 85 | + - create-version |
| 86 | + runs-on: ubuntu-latest |
| 87 | + permissions: |
| 88 | + id-token: write |
| 89 | + steps: |
| 90 | + - name: Checkout repository |
| 91 | + uses: actions/checkout@v4 |
| 92 | + with: |
| 93 | + ref: refs/tags/v${{ needs.check-version.outputs.version }} |
| 94 | + |
| 95 | + - name: Setup env |
| 96 | + uses: ./.github/actions/setup |
| 97 | + with: |
| 98 | + registry: https://registry.npmjs.org |
| 99 | + |
| 100 | + - name: Build |
| 101 | + run: pnpm run build |
| 102 | + |
| 103 | + - name: Publish |
| 104 | + env: |
| 105 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 106 | + NPM_CONFIG_PROVENANCE: true |
| 107 | + run: | |
| 108 | + pnpm publish \ |
| 109 | + --access=public \ |
| 110 | + --no-git-checks \ |
| 111 | + --tag ${{ needs.check-version.outputs.is-prerelease == 'true' && 'canary' || 'latest' }} |
0 commit comments