豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 2025d98

Browse files
committed
fix(github-actions): rework token revoke mechanism to not rely on post run
Currently Github actions acquire tokens from the secrets for an app installation. The actions can operate on repositories using this token. Later, as a Github action (separate step) we attempt to revoke the token. This does not work at all, and never did, because the previously used installation Github token is not known in the post step, so the post step always failed. We rework this to always revoke the token as part of the Node process where we acquired the installation token.
1 parent c713d4a commit 2025d98

File tree

34 files changed

+207
-77951
lines changed

34 files changed

+207
-77951
lines changed

github-actions/commit-message-based-labels/BUILD.bazel

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
load("//tools:defaults.bzl", "esbuild_checked_in")
22

3-
esbuild_checked_in(
4-
name = "post",
5-
entry_point = "//github-actions/commit-message-based-labels/lib:post.ts",
6-
target = "node16",
7-
deps = [
8-
"//github-actions/commit-message-based-labels/lib",
9-
],
10-
)
11-
123
esbuild_checked_in(
134
name = "main",
145
entry_point = "//github-actions/commit-message-based-labels/lib:main.ts",

github-actions/commit-message-based-labels/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ inputs:
88
runs:
99
using: 'node16'
1010
main: 'main.js'
11-
post: 'post.js'

github-actions/commit-message-based-labels/lib/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package(default_visibility = ["//github-actions/commit-message-based-labels:__su
44

55
exports_files([
66
"main.ts",
7-
"post.ts",
87
])
98

109
ts_library(

github-actions/commit-message-based-labels/lib/main.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,30 @@ import {context} from '@actions/github';
33
import {Octokit} from '@octokit/rest';
44
import {parseCommitMessage} from '../../../ng-dev/commit-message/parse.js';
55
import {breakingChangeLabel, deprecationLabel} from '../../../ng-dev/pr/config/index.js';
6-
import {ANGULAR_ROBOT, getAuthTokenFor} from '../../utils.js';
6+
import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../utils.js';
77

88
/** List of supported label and commit message attribute combinations. */
99
const supportedLabels = [
1010
[breakingChangeLabel, 'breakingChanges'],
1111
[deprecationLabel, 'deprecations'],
1212
] as const;
1313

14-
async function run(): Promise<void> {
15-
const token = await getAuthTokenFor(ANGULAR_ROBOT);
16-
const client = new Octokit({auth: token});
14+
async function main() {
15+
let installationClient: Octokit | null = null;
16+
17+
try {
18+
const token = await getAuthTokenFor(ANGULAR_ROBOT);
19+
installationClient = new Octokit({auth: token});
20+
21+
await runCommitMessageBasedLabelsAction(installationClient);
22+
} finally {
23+
if (installationClient !== null) {
24+
await revokeActiveInstallationToken(installationClient);
25+
}
26+
}
27+
}
28+
29+
async function runCommitMessageBasedLabelsAction(client: Octokit): Promise<void> {
1730
const {number, owner, repo} = context.issue;
1831
/** Labels currently applied to the PR. */
1932
const labels = await (
@@ -57,7 +70,10 @@ async function run(): Promise<void> {
5770
// Only run if the action is executed in a repository within the Angular org. This is in place
5871
// to prevent the action from actually running in a fork of a repository with this action set up.
5972
if (context.repo.owner === 'angular') {
60-
run();
73+
main().catch((e: Error) => {
74+
core.error(e);
75+
core.setFailed(e.message);
76+
});
6177
} else {
6278
core.warning(
6379
'Automatic labeling was skipped as this action is only meant to run ' +

github-actions/commit-message-based-labels/lib/post.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)