Skip to content

Commit 313b693

Browse files
committed
switch to commitMode
1 parent 0105bde commit 313b693

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

.changeset/green-dogs-change.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"@changesets/action": minor
33
---
44

5-
Introduce a new input commitUsingApi that allows pushing tags and commits
6-
using the GitHub API instead of the git CLI.
5+
Introduce a new input `commitMode` that allows using the GitHub API for pushing tags and commits instead of the Git CLI.
76

8-
When used, this means means that all tags and commits will be attributed
9-
to the user whose GITHUB_TOKEN is used,
10-
and also signed using GitHub's internal GPG key.
7+
When used with `"github-api"` value all tags and commits will be attributed to the user whose GITHUB_TOKEN is used, and also signed using GitHub's internal GPG key.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changesets Release Action
22

3-
This action for [Changesets](https://github.com/atlassian/changesets) creates a pull request with all of the package versions updated and changelogs updated and when there are new changesets on [your configured `baseBranch`](https://github.com/changesets/changesets/blob/main/docs/config-file-options.md#basebranch-git-branch-name), the PR will be updated. When you're ready, you can merge the pull request and you can either publish the packages to npm manually or setup the action to do it for you.
3+
This action for [Changesets](https://github.com/changesets/changesets) creates a pull request with all of the package versions updated and changelogs updated and when there are new changesets on [your configured `baseBranch`](https://github.com/changesets/changesets/blob/main/docs/config-file-options.md#basebranch-git-branch-name), the PR will be updated. When you're ready, you can merge the pull request and you can either publish the packages to npm manually or setup the action to do it for you.
44

55
## Usage
66

@@ -12,7 +12,7 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
1212
- title - The pull request title. Default to `Version Packages`
1313
- setupGitUser - Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
1414
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
15-
- commitUsingApi - A boolean value to indicate whether to use the GitHub API to push changes or not, so changes are GPG-signed. Default to `false`
15+
- commitMode - Specifies 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 GPG-signed and attributed to the user or app who owns the `GITHUB_TOKEN`. Default to `git-cli`.
1616
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
1717

1818
### Outputs

action.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ inputs:
2828
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
2929
required: false
3030
default: true
31-
commitUsingApi:
31+
commitMode:
3232
description: >
33-
A boolean value to indicate whether to push changes via Github API or not,
34-
this will mean all commits and tags are signed using GitHub's GPG key,
35-
and attributed to the user or app who owns the GITHUB_TOKEN
33+
An enum to specify the commit mode. Use "git-cli" to push changes using the Git CLI,
34+
or "github-api" to push changes via the GitHub API. When using "github-api",
35+
all commits and tags are signed using GitHub's GPG key and attributed to the user
36+
or app who owns the GITHUB_TOKEN.
3637
required: false
37-
default: false
38+
default: "git-cli"
3839
branch:
3940
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
4041
required: false

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
2222
}
2323

2424
const octokit = setupOctokit(githubToken);
25-
const commitUsingApi = core.getBooleanInput("commitUsingApi");
26-
const git = new Git(commitUsingApi ? octokit : undefined);
25+
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
26+
if (commitMode !== "git-cli" && commitMode !== "github-api") {
27+
core.setFailed(`Invalid commit mode: ${commitMode}`);
28+
return;
29+
}
30+
const git = new Git(commitMode === "github-api" ? octokit : undefined);
2731

2832
let setupGitUser = core.getBooleanInput("setupGitUser");
2933

@@ -114,7 +118,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
114118
const octokit = setupOctokit(githubToken);
115119
const { pullRequestNumber } = await runVersion({
116120
script: getOptionalInput("version"),
117-
git: new Git(commitUsingApi ? octokit : undefined),
121+
git,
118122
octokit,
119123
prTitle: getOptionalInput("title"),
120124
commitMessage: getOptionalInput("commit"),

0 commit comments

Comments
 (0)