|
| 1 | +## If you allow direct pushes to the main branch |
| 2 | + |
| 3 | +```yaml |
| 4 | + |
| 5 | +name: release |
| 6 | + |
| 7 | +on: workflow_dispatch |
| 8 | + |
| 9 | +jobs: |
| 10 | + |
| 11 | + release: |
| 12 | + name: Release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + needs: build |
| 15 | + |
| 16 | + # (1) Give GIT_TOKEN permission to push to the repository |
| 17 | + # By default, the GITHUB_TOKEN does not have permission to push to the repository |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + # This is a custom action that sets up the environment |
| 26 | + - name: Setup |
| 27 | + uses: ./.github/actions/setup |
| 28 | + |
| 29 | + # (2) Configure a git user to make the release |
| 30 | + # This is required to identify the user |
| 31 | + - name: Configure Git User |
| 32 | + run: | |
| 33 | + git config --global user.name "${GITHUB_ACTOR}" |
| 34 | + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 35 | +
|
| 36 | + - name: Release |
| 37 | + run: yarn release |
| 38 | + env: |
| 39 | + # (3) Provide the GITHUB_TOKEN to release-it |
| 40 | + # This is required to identify the user who made the release |
| 41 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | +``` |
| 44 | + |
| 45 | +## If you don't allow direct pushes to the main branch |
| 46 | + |
| 47 | +You need to create a GitHub App and add it to the bypass list in your rules. |
| 48 | +See [here](https://github.com/orgs/community/discussions/13836#discussioncomment-8535364) |
| 49 | + |
| 50 | +```yaml |
| 51 | + |
| 52 | +name: release |
| 53 | + |
| 54 | +on: workflow_dispatch |
| 55 | + |
| 56 | +jobs: |
| 57 | + |
| 58 | + release: |
| 59 | + name: Release |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: build |
| 62 | + |
| 63 | + steps: |
| 64 | + # (1) This action creates a token using the GitHub App |
| 65 | + - uses: actions/create-github-app-token@v1 |
| 66 | + id: app-token |
| 67 | + with: |
| 68 | + # (1.1) Provide the App ID and Private Key |
| 69 | + # Be sure to read the private key value from the .pem file that you downloaded from the GitHub App web page |
| 70 | + # upon private key creation. (Not the SHA that you see in the GitHub App web page!!) |
| 71 | + app-id: ${{ vars.APP_ID }} |
| 72 | + private-key: ${{ secrets.PRIVATE_KEY }} |
| 73 | + |
| 74 | + - name: Checkout |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + # (2) Tell checkout to use the token created by the GitHub App |
| 78 | + token: ${{ steps.app-token.outputs.token }} |
| 79 | + |
| 80 | + # This is a custom action that sets up the environment |
| 81 | + - name: Setup |
| 82 | + uses: ./.github/actions/setup |
| 83 | + |
| 84 | + # (3) Configure a git user to make the release |
| 85 | + # This is required to identify the user |
| 86 | + - name: Configure Git User |
| 87 | + run: | |
| 88 | + git config --global user.name "${GITHUB_ACTOR}" |
| 89 | + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 90 | + |
| 91 | + - name: Release |
| 92 | + run: yarn release |
| 93 | + env: |
| 94 | + # (4) Provide the GITHUB_TOKEN to release-it but use the token created by the GitHub App |
| 95 | + # This is required to identify the user who made the release |
| 96 | + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |
| 97 | + |
| 98 | +``` |
| 99 | + |
| 100 | + |
| 101 | + |
0 commit comments