9ec88c41ee
Fixes https://github.com/actions/create-github-app-token/issues/55 Currently, `actions/create-github-app-token` always/unconditionally revokes the installation access token in a `post` step, at the completion of the current job. This prevents tokens from being used in other jobs. This PR makes this behavior configurable: - When the `skip-token-revoke` input is not specified (i.e. by default), the token is revoked in a `post` step (i.e. the current behavior). - When the `skip-token-revoke` input is set to a truthy value (e.g. `"true"`[^1]), the token is not revoked in a `post` step. This PR adds a test for the `skip-token-revoke: "true"` case. This is configurable in other app token actions, e.g. [tibdex/github-app-token](https://github.com/tibdex/github-app-token/blob/3eb77c7243b85c65e84acfa93fdbac02fb6bd532/README.md?plain=1#L46-L47) and [wow-actions/use-app-token](https://github.com/wow-actions/use-app-token/blob/cd772994fc762f99cf291f308797341327a49b0c/README.md?plain=1#L132). [^1]: Note that `"false"` is also truthy: `Boolean("false")` is `true`. If we think that’ll potentially confuse folks, I can require `skip-token-revoke` to be set explicitly to `"true"`.
30 lines
580 B
JavaScript
30 lines
580 B
JavaScript
// @ts-check
|
|
|
|
/**
|
|
* @param {import("@actions/core")} core
|
|
* @param {import("@octokit/request").request} request
|
|
*/
|
|
export async function post(core, request) {
|
|
const skipTokenRevoke = Boolean(core.getInput("skip_token_revoke"));
|
|
|
|
if (skipTokenRevoke) {
|
|
core.info("Token revocation was skipped");
|
|
return;
|
|
}
|
|
|
|
const token = core.getState("token");
|
|
|
|
if (!token) {
|
|
core.info("Token is not set");
|
|
return;
|
|
}
|
|
|
|
await request("DELETE /installation/token", {
|
|
headers: {
|
|
authorization: `token ${token}`,
|
|
},
|
|
});
|
|
|
|
core.info("Token revoked");
|
|
}
|