Skip to content

Commit 2843f15

Browse files
devversionalxhub
authored andcommitted
fix(dev-infra): merge tool should ensure that token has workflow oauth scope (angular#41989)
Currently if a PR modifies any file that configures a Github action (e.g. a workflow file), the caretaker might face an error when merging such PR: ``` ! [remote rejected] merge_pr_target_11.2.x -> 11.2.x (refusing to allow a Personal Access Token to create or update workflow ``` This happens because Github requires the token being used for the push operation to have the `workflow` scope set. This is a special scope added by Github to ensure that no changes can be made on upstream branches that might expose the `GITHUB_TOKEN` environment variable, which is available for push builds and could cause the token being leaked. With this commit we enforce that the caretaker adds the workflow scope to their github token. Since PRs can only be merged if reviewed thoroughly, it's acceptable to allow workflow file changes being merged through the merge tool by the caretaker (especially since we also allow CircleCI config files being merged with the default `repo`/`public_repo` scope). PR Close angular#41989
1 parent 3a48c07 commit 2843f15

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

dev-infra/ng-dev.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,6 +4215,14 @@ var PullRequestMergeTask = /** @class */ (function () {
42154215
missing.push('public_repo');
42164216
}
42174217
}
4218+
// Pull requests can modify Github action workflow files. In such cases Github requires us to
4219+
// push with a token that has the `workflow` oauth scope set. To avoid errors when the
4220+
// caretaker intends to merge such PRs, we ensure the scope is always set on the token before
4221+
// the merge process starts.
4222+
// https://docs.github.com/en/developers/apps/scopes-for-oauth-apps#available-scopes
4223+
if (!scopes.includes('workflow')) {
4224+
missing.push('workflow');
4225+
}
42184226
})];
42194227
case 1:
42204228
hasOauthScopes = _c.sent();

dev-infra/pr/merge/task.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ export class PullRequestMergeTask {
7474
missing.push('public_repo');
7575
}
7676
}
77+
78+
// Pull requests can modify Github action workflow files. In such cases Github requires us to
79+
// push with a token that has the `workflow` oauth scope set. To avoid errors when the
80+
// caretaker intends to merge such PRs, we ensure the scope is always set on the token before
81+
// the merge process starts.
82+
// https://docs.github.com/en/developers/apps/scopes-for-oauth-apps#available-scopes
83+
if (!scopes.includes('workflow')) {
84+
missing.push('workflow');
85+
}
7786
});
7887

7988
if (hasOauthScopes !== true) {

0 commit comments

Comments
 (0)