|
1 | | -## If you allow direct pushes to the main branch |
| 1 | +# Release It Setup |
2 | 2 |
|
3 | | -```yaml |
| 3 | +This document describes how to set up [release-it](https://github.com/release-it/release-it) to run in a Github Actions workflow. |
4 | 4 |
|
5 | | -name: release |
| 5 | +## Prerequisites |
6 | 6 |
|
7 | | -on: workflow_dispatch |
| 7 | +- You have installed [release-it](https://github.com/release-it/release-it) in your project; |
| 8 | +- You have a `release` script in your `package.json` that runs `release-it` with --ci flag; |
8 | 9 |
|
9 | | -jobs: |
| 10 | +Depending on your repository settings, you may need to set up a [Github App](https://docs.github.com/en/apps/creating-github-apps/about-creating-github-apps/about-creating-github-apps) |
| 11 | +to create a token that allows release-it to push on main, bypassing the branch protection rules that require pull requests. |
| 12 | +The Github App needs to be installed on the repository and have the `Contents`, `Actions` and `Administration` permissions |
| 13 | +to properly work. |
10 | 14 |
|
11 | | - release: |
12 | | - name: Release |
13 | | - runs-on: ubuntu-latest |
14 | | - needs: build |
| 15 | +If you need to publish to npm too, you need to create an automation token to authenticate with npm and bypass the 2FA |
| 16 | +requirement. You can create an automation token directly in the [npm website](https://www.npmjs.com/). |
15 | 17 |
|
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 |
| 18 | +## Available Workflows |
20 | 19 |
|
21 | | - steps: |
22 | | - - name: Checkout |
23 | | - uses: actions/checkout@v4 |
| 20 | +### release-it-without-pr-only |
24 | 21 |
|
25 | | - # This is a custom action that sets up the environment |
26 | | - - name: Setup |
27 | | - uses: ./.github/actions/setup |
| 22 | +This workflow showcases how to set up release-it on a repository with an unprotected main branch. It doesn't require any |
| 23 | +particular setup, as the GITHUB_TOKEN, with content permissions set to write, is enough to push to the main branch. |
28 | 24 |
|
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" |
| 25 | +Take a look at the workflow here: [.github/workflows/release-it-without-pr-only.yml](../.github/workflows/release-it-without-pr-only.yml) |
35 | 26 |
|
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 }} |
| 27 | +### release-it-with-pr-only |
42 | 28 |
|
43 | | -``` |
| 29 | +This workflow showcases how to set up release-it on a repository with a ruleset that only allows PRs to the main branch. |
| 30 | +It needs a GitHub App added to the bypass list of the ruleset and a token created by the GitHub App to push to the |
| 31 | +main branch using the [actions/create-github-app-token](https://github.com/actions/create-github-app-token) action. |
| 32 | +This token is then used to checkout the main branch and push the changes made by release-it. |
44 | 33 |
|
45 | | -## If you don't allow direct pushes to the main branch |
| 34 | +Before running this workflow, you need to add both the GitHub App id and private key secrets to your repository with the |
| 35 | +values associated with the GitHub App you created. |
46 | 36 |
|
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) |
| 37 | +> [!IMPORTANT] |
| 38 | +> If you are using this workflow in a repository owned by an organization, you need to create an organization-wide GitHub |
| 39 | +> App. |
49 | 40 |
|
50 | | -```yaml |
| 41 | +Take a look at the workflow here: [.github/workflows/release-it-with-pr-only.yml](../.github/workflows/release-it-with-pr-only.yml) |
51 | 42 |
|
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 | | -``` |
| 43 | +### release-it-with-npm-and-pr-only |
99 | 44 |
|
| 45 | +This workflow is an extension of the `release-it-with-pr-only` workflow that also publishes the package to npm. It |
| 46 | +requires an automation token created in the npm website to authenticate with npm and bypass the 2FA requirement. |
| 47 | +It leverages the upload-artifact and download-artifact actions to pass additional build artifacts that needs to be |
| 48 | +published as well, like the `build` folder. |
100 | 49 |
|
| 50 | +Before running this workflow, you need to add the `NPM_ACCESS_TOKEN` secret to your repository with the value of the |
| 51 | +automation token. |
101 | 52 |
|
| 53 | +Take a look at the workflow here: [.github/workflows/release-it-with-npm-and-pr-only.yml](../.github/workflows/release-it-with-npm-and-pr-only.yml) |
0 commit comments