Skip to content

Commit 75a30a5

Browse files
authored
feat: deprecate GITHUB_TOKEN env var and use token input instead with default value (#112)
* deprecate GITHUB_TOKEN env var and use token input instead with default value * update readme * npm run lint:fix
1 parent 401756f commit 75a30a5

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

README.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ Add a step like this to your workflow:
5959
# Default: ''
6060
tag: 'v1.0.0 --force'
6161

62-
env:
63-
# This is necessary in order to push a commit to the repo
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
62+
# Token to use for pushing the commit. The default value won't trigger any workflows, you need to use a Personal Access Token for that.
63+
# Default: secrets.GITHUB_TOKEN
64+
token: ${{ secrets.GITHUB_TOKEN }}
6565
```
6666
67-
### Environment variables:
68-
69-
The only `env` variable required is the token for the action to run: GitHub generates one automatically, but you need to pass it through `env` to make it available to actions. You can find more about `GITHUB_TOKEN` [here](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
70-
That said, you can just copy the example line and not worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
71-
7267
### Adding files:
7368
7469
The action adds files using a regular `git add` command, so you can put every kind of argument in the `add` option. For example, if you want to force-add a file: `./path/to/file.txt --force`.
@@ -129,8 +124,6 @@ jobs:
129124
author_email: [email protected]
130125
message: 'Your commit message'
131126
add: '*.js'
132-
env:
133-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134127
```
135128

136129
If you need to run the action on a repository that is not located in [`$GITHUB_WORKSPACE`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables#default-environment-variables), you can use the `cwd` option: the action uses a `cd` normal command, so the path should follow bash standards.
@@ -159,8 +152,6 @@ jobs:
159152
message: 'Add the very useful text file'
160153
add: '*.txt --force'
161154
cwd: './pathToRepo/'
162-
env:
163-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164155
```
165156

166157
## Contributors ✨

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ inputs:
3838
tag:
3939
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
4040
required: false
41+
token:
42+
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
43+
required: false
44+
default: ${{ github.token }}
4145

4246
outputs:
4347
committed:

src/main.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,22 @@ async function checkInputs() {
161161

162162
const eventPath = process.env.GITHUB_EVENT_PATH,
163163
event = eventPath && require(eventPath),
164-
token = process.env.GITHUB_TOKEN,
165164
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
166165
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
167166
defaultBranch = isPR
168167
? (event?.pull_request?.head?.ref as string)
169168
: process.env.GITHUB_REF?.substring(11)
170169

171170
// #region GITHUB_TOKEN
172-
if (!token)
171+
let token = process.env.GITHUB_TOKEN
172+
if (token) {
173173
warning(
174-
'The GITHUB_TOKEN env variable is missing: the action may not work as expected.'
174+
"The GITHUB_TOKEN env variable is deprecated and will not be supported in the next major release. Use the 'token' input, " +
175+
"which defaults to 'secrets.GITHUB_TOKEN'."
175176
)
177+
} else {
178+
token = getInput('token')
179+
}
176180
// #endregion
177181

178182
// #region add, remove

0 commit comments

Comments
 (0)