Skip to content

Commit cb3f011

Browse files
authored
Use GitHub API for pushes by default and require explicit github-token when using custom tokens (#692)
* Ensure `github-token` wins for `git-cli` pushes * more shenanigans * Default to GitHub API commit mode * e2e auth tests * push missing utils * rename input * refactor * refactor * refactor * refactor * refactor * refactor * reuse helpers * refactor * refactor * simplify * add tests * refactor * improve comments * shift helper * add comments * extract test helpers * update docs and changesets * update one thing
1 parent 50de20a commit cb3f011

20 files changed

Lines changed: 766 additions & 129 deletions

‎.changeset/brave-pandas-commit.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@changesets/action": major
3+
---
4+
5+
Release commits and tags are now pushed using the GitHub API by default.
6+
7+
Replace the `commit-mode` input with the boolean `push-with-git-cli` input. Set `push-with-git-cli: true` to continue using the Git CLI.
8+
9+
Regardless of the push mode, custom GitHub tokens must be passed explicitly through the `github-token` input. The `GITHUB_TOKEN` environment variable and credentials configured by `actions/checkout` or embedded in remote URLs are not substitutes for this input. When the Git CLI is enabled, `github-token` takes precedence over those repository credentials.

‎README.md‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,32 @@ If using [trusted publishing](https://docs.npmjs.com/trusted-publishers), it's r
3636
> [!TIP]
3737
> Check out [the docs](https://changesets.dev/guide/automating#how-do-i-run-the-version-and-publish-commands) to learn how to set up the version and publish workflow.
3838
39+
> [!IMPORTANT]
40+
> To use a custom GitHub token, pass it explicitly through the `github-token` input:
41+
>
42+
> ```yaml
43+
> with:
44+
> github-token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
45+
> ```
46+
>
47+
> Setting the `GITHUB_TOKEN` environment variable does not configure the action. This applies whether release changes are pushed using the GitHub API or the Git CLI.
48+
3949
### API
4050
4151
<!-- api-start -->
4252
43-
| Inputs | Description |
44-
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
45-
| `github-token` | The GitHub token to use for authentication. Defaults to the GitHub-provided token. |
46-
| `publish-script` | The command to use to build and publish packages |
47-
| `version-script` | The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided |
48-
| `commit-message` | The commit message. Default to `Version Packages` |
49-
| `pr-title` | The pull request title. Default to `Version Packages` |
50-
| `pr-draft` | Controls draft PR behavior. Use 'create' to create new version PRs as draft, or 'always' to also convert existing version PRs back to draft when updating them. |
51-
| `pr-base-branch` | Sets the base branch of the PR. Defaults to `github.ref_name`. |
52-
| `create-github-releases` | Whether to create Github releases after publish |
53-
| `push-git-tags` | Whether to create git tags after publish. If `create-github-releases` is set to `true`, this option will also always be `true`. |
54-
| `commit-mode` | An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI, or "github-api" to push changes via the GitHub API. When using "github-api", all commits and tags are signed using GitHub's GPG key and attributed to the user or app who owns the GITHUB_TOKEN. |
53+
| Inputs | Description |
54+
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55+
| `github-token` | The GitHub token to use for authentication. Defaults to the GitHub-provided token. To use a custom token, pass it explicitly to this input. |
56+
| `publish-script` | The command to use to build and publish packages |
57+
| `version-script` | The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided |
58+
| `commit-message` | The commit message. Default to `Version Packages` |
59+
| `pr-title` | The pull request title. Default to `Version Packages` |
60+
| `pr-draft` | Controls draft PR behavior. Use 'create' to create new version PRs as draft, or 'always' to also convert existing version PRs back to draft when updating them. |
61+
| `pr-base-branch` | Sets the base branch of the PR. Defaults to `github.ref_name`. |
62+
| `create-github-releases` | Whether to create Github releases after publish |
63+
| `push-git-tags` | Whether to create git tags after publish. If `create-github-releases` is set to `true`, this option will also always be `true`. |
64+
| `push-with-git-cli` | Whether to use the Git CLI instead of the GitHub API to push release commits and tags. Defaults to `false`. When using the GitHub API, commits and tags are signed using GitHub's GPG key and attributed to the user or app that owns the `github-token`. |
5565
5666
| Outputs | Description |
5767
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |

‎action.yml‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ runs:
55
main: "dist/index.js"
66
inputs:
77
github-token:
8-
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
8+
description: >
9+
The GitHub token to use for authentication. Defaults to the GitHub-provided token.
10+
To use a custom token, pass it explicitly to this input.
911
required: false
1012
default: ${{ github.token }}
1113
publish-script:
@@ -38,14 +40,13 @@ inputs:
3840
this option will also always be `true`.
3941
required: false
4042
default: true
41-
commit-mode:
43+
push-with-git-cli:
4244
description: >
43-
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,
44-
or "github-api" to push changes via the GitHub API. When using "github-api",
45-
all commits and tags are signed using GitHub's GPG key and attributed to the user
46-
or app who owns the GITHUB_TOKEN.
45+
Whether to use the Git CLI instead of the GitHub API to push release commits and tags.
46+
Defaults to `false`. When using the GitHub API, commits and tags are signed using
47+
GitHub's GPG key and attributed to the user or app that owns the `github-token`.
4748
required: false
48-
default: "git-cli"
49+
default: false
4950
outputs:
5051
published:
5152
description: A "true" or "false" string value to indicate whether a publishing is happened or not

‎pr-comment/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373

7474
| Inputs | Description |
7575
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
76-
| `github-token` | The GitHub token to use for authentication. Defaults to the GitHub-provided token. |
76+
| `github-token` | The GitHub token to use for authentication. Defaults to the GitHub-provided token. To use a custom token, pass it explicitly to this input. |
7777
| `body` | **Required.** The comment body to post on the PR. |
7878
| `update-id` | By default, the action will create and update a comment with this id. Pass a different id to create and update a new comment, or pass an empty string to disable updating comments. |
7979

‎pr-comment/action.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ runs:
55
main: ../dist/pr-comment.js
66
inputs:
77
github-token:
8-
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
8+
description: >
9+
The GitHub token to use for authentication. Defaults to the GitHub-provided token.
10+
To use a custom token, pass it explicitly to this input.
911
required: false
1012
default: ${{ github.token }}
1113
body:

‎publish/README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ This action publishes packages to npm.
1818

1919
<!-- api-start -->
2020

21-
| Inputs | Description |
22-
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
23-
| `github-token` | The GitHub token to use for authentication. Defaults to the GitHub-provided token. |
24-
| `script` | The command to use to publish packages |
25-
| `pack-dir-artifact-id` | Artifact id for packed publish output generated by the pack subaction |
26-
| `create-github-releases` | Whether to create Github releases after publish |
27-
| `push-git-tags` | Whether to create git tags after publish. If `create-github-releases` is set to `true`, this option will also always be `true`. |
21+
| Inputs | Description |
22+
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
23+
| `github-token` | The GitHub token to use for authentication. Defaults to the GitHub-provided token. To use a custom token, pass it explicitly to this input. |
24+
| `script` | The command to use to publish packages |
25+
| `pack-dir-artifact-id` | Artifact id for packed publish output generated by the pack subaction |
26+
| `create-github-releases` | Whether to create Github releases after publish |
27+
| `push-git-tags` | Whether to create git tags after publish. If `create-github-releases` is set to `true`, this option will also always be `true`. |
2828

2929
| Outputs | Description |
3030
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |

‎publish/action.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ runs:
55
main: ../dist/publish.js
66
inputs:
77
github-token:
8-
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
8+
description: >
9+
The GitHub token to use for authentication. Defaults to the GitHub-provided token.
10+
To use a custom token, pass it explicitly to this input.
911
required: false
1012
default: ${{ github.token }}
1113
script:

0 commit comments

Comments
 (0)