GitHub Action support
See original GitHub issueI’d like to make semantic-release work within GitHub actions out of the box
action "npx semantic-release" {
uses = "docker://timbru31/node-alpine-git"
runs = "npx"
args = "semantic-release"
secrets = ["GITHUB_TOKEN", "NPM_TOKEN"]
}
The NPM_TOKEN
needs to be configured, but GITHUB_TOKEN
should work with the one provided by GitHub action.
But when I run the action, I get the following error
EGHNOPERMISSION The GitHub token doesn’t allow to push on the repository octokit/routes
The problem is that the token is not an OAuth token, but an GitHub App installation access token, because that’s how it’s implemented I assume.
The verification works by checking the respone of github.repos.get()
which for the GitHub Action returns
...
"permissions": {
"admin": false,
"push": false,
"pull": false
},
Although the token has code write permission to the repository.
The token itself is easily distinguished: it starts with v1.
, e.g. v1.1234567890123456789012345678901234567890
.
We could also just check if process.env.GITHUB_ACTION
is set, see Environment variables. But people can pass their own tokens so that’s not guaranteed.
I’d suggest we check for both.
If both is true, we can just assume that it has write access.
I’ll do some testing myself
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (7 by maintainers)
Ok. Checking
isNil(env.GITHUB_ACTION)
seems better than checking forv1
in the token. I’m guessing GitHub can change the format of token anytime (at some point it will be comev2
I imagine).You need to set the
GITHUB_TOKEN
environment variable fromsecrets.GITHUB_TOKEN
. See https://github.com/octokit/core.js/blob/master/.github/workflows/release.yml for reference