Skip to content

Commit 7314435

Browse files
authored
chore(github): auto-approve automated github workflows (#381)
* chore(github): update auto approve mechanism for some workflows * chore(github): update auto approve mechanism for upgrade main deps
1 parent c4fa881 commit 7314435

File tree

7 files changed

+114
-5
lines changed

7 files changed

+114
-5
lines changed

.github/workflows/auto-approve.yml

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/code-generation.yml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/monthly-repo-metrics.yml

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/upgrade-main.yml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { JsonPatch, awscdk } from 'projen';
1515
import { DependabotScheduleInterval, VersioningStrategy } from 'projen/lib/github';
1616
import { JobPermission } from 'projen/lib/github/workflows-model';
1717
import { NpmAccess } from 'projen/lib/javascript';
18+
import { buildUpgradeMainPRCustomJob } from './projenrc/github-jobs';
1819
import {
1920
buildMeritBadgerWorkflow,
2021
buildMonthlyIssuesMetricsWorkflow,
@@ -117,6 +118,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
117118
sampleCode: false,
118119
stale: true,
119120
});
121+
120122
// Add some useful github workflows
121123
buildMeritBadgerWorkflow(project);
122124
buildMonthlyIssuesMetricsWorkflow(project);
@@ -127,6 +129,12 @@ runBanditWorkflow(project);
127129
runCommitLintWorkflow(project);
128130
buildCodeGenerationWorkflow(project);
129131

132+
const workflowUpgradeMain = project.github?.tryFindWorkflow('upgrade-main');
133+
if (workflowUpgradeMain) {
134+
// upgrade the PR job to use the custom one adding a label
135+
workflowUpgradeMain.updateJob('pr', buildUpgradeMainPRCustomJob());
136+
}
137+
130138
// Add specific overrides https://projen.io/docs/integrations/github/#actions-versions
131139
project.github?.actions.set('actions/checkout@v3', 'actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744');
132140
project.github?.actions.set('actions/download-artifact@v3', 'actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a');
@@ -139,7 +147,7 @@ project.github?.actions.set('amannn/[email protected]', 'amann
139147
project.github?.actions.set('aws-github-ops/github-merit-badger@main', 'aws-github-ops/github-merit-badger@70d1c47f7051d6e324d4ddc48d676ba61ef69a3e');
140148
project.github?.actions.set('codecov/codecov-action@v3', 'codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d');
141149
project.github?.actions.set('github/issue-metrics@v2', 'github/issue-metrics@6bc5254e72971dbb7462db077779f1643f772afd');
142-
project.github?.actions.set('hmarr/auto-approve-action@v3.2.1', 'hmarr/auto-approve-action@44888193675f29a83e04faf4002fa8c0b537b1e4');
150+
project.github?.actions.set('hmarr/auto-approve-action@v4.0.0', 'hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363');
143151
project.github?.actions.set('minicli/[email protected]', 'minicli/action-contributors@20ec03af008cb51110a3137fbf77f59a4fd7ff5a');
144152
project.github?.actions.set('oss-review-toolkit/ort-ci-github-action@v1', 'oss-review-toolkit/ort-ci-github-action@7f23c1f8d169dad430e41df223d3b8409c7a156e');
145153
project.github?.actions.set('peter-evans/create-issue-from-file@v4', 'peter-evans/create-issue-from-file@433e51abf769039ee20ba1293a088ca19d573b7f');

projenrc/github-jobs.ts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5+
* with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
10+
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
import { Job, JobPermission } from 'projen/lib/github/workflows-model';
14+
15+
/**
16+
* GitHub job used to replace the default one created by Projen
17+
* as part of the upgrade-main action workflow. This job takes
18+
* the same steps, and adds the auto-approve label
19+
*/
20+
export function buildUpgradeMainPRCustomJob() {
21+
const pr: Job = {
22+
name: 'Create Pull Request',
23+
needs: ['upgrade'],
24+
runsOn: ['ubuntu-latest'],
25+
permissions: {
26+
contents: JobPermission.READ,
27+
},
28+
if: '${{ needs.upgrade.outputs.patch_created }}',
29+
steps: [
30+
{
31+
name: 'Checkout',
32+
uses: 'actions/checkout@v3',
33+
with: {
34+
ref: 'main',
35+
},
36+
},
37+
{
38+
name: 'Download patch',
39+
uses: 'actions/download-artifact@v3',
40+
with: {
41+
name: '.repo.patch',
42+
path: '${{ runner.temp }}',
43+
},
44+
},
45+
{
46+
name: 'Apply patch',
47+
run: '[ -s ${{ runner.temp }}/.repo.patch ] && git apply ${{ runner.temp }}/.repo.patch || echo "Empty patch. Skipping."',
48+
},
49+
{
50+
name: 'Set git identity',
51+
run: [
52+
'git config user.name "github-actions"',
53+
'git config user.email "[email protected]"',
54+
].join('\n'),
55+
},
56+
{
57+
name: 'Create Pull Request',
58+
id: 'create-pr',
59+
uses: 'peter-evans/create-pull-request@v4',
60+
with: {
61+
'token': '${{ secrets.PROJEN_GITHUB_TOKEN }}',
62+
'commit-message': [
63+
'chore(deps): upgrade dependencies\n',
64+
65+
'Upgrades project dependencies. See details in [workflow run].\n',
66+
67+
'[Workflow Run]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n',
68+
69+
'------\n',
70+
71+
'*Automatically created by projen via the "upgrade-main" workflow*',
72+
].join('\n'),
73+
'branch': 'github-actions/upgrade-main',
74+
'title': 'chore(deps): upgrade dependencies',
75+
'body': [
76+
'Upgrades project dependencies. See details in [workflow run].\n',
77+
'[Workflow Run]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n',
78+
'------\n',
79+
80+
'*Automatically created by projen via the "upgrade-main" workflow*',
81+
].join('\n'),
82+
'author': 'github-actions <[email protected]>',
83+
'committer': 'github-actions <[email protected]>',
84+
'signoff': true,
85+
'labels': 'auto-approve',
86+
},
87+
},
88+
],
89+
};
90+
91+
return pr;
92+
}

projenrc/github-workflows.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export function buildMonthlyIssuesMetricsWorkflow(project: AwsCdkConstructLibrar
100100
'token': '${{ secrets.PROJEN_GITHUB_TOKEN }}',
101101
'content-filepath': './issue_metrics.md',
102102
'assignees': 'krokoko',
103+
'labels': 'auto-approve',
103104
},
104105
},
105106
{
@@ -120,6 +121,7 @@ export function buildMonthlyIssuesMetricsWorkflow(project: AwsCdkConstructLibrar
120121
'token': '${{ secrets.PROJEN_GITHUB_TOKEN }}',
121122
'content-filepath': './issue_metrics.md',
122123
'assignees': 'krokoko',
124+
'labels': 'auto-approve',
123125
},
124126
},
125127
],
@@ -147,15 +149,16 @@ export function buildMonthlyIssuesMetricsWorkflow(project: AwsCdkConstructLibrar
147149
export function buildAutoApproveWorkflow(project: AwsCdkConstructLibrary) {
148150
const autoapprove: Job = {
149151
runsOn: ['ubuntu-latest'],
150-
if: "(github.event.pull_request.user.login == 'emerging-tech-cdk-constructs-bot' || github.event.pull_request.user.login == 'generative-ai-cdk-constructs-bot') && contains(github.event.pull_request.labels.*.name, 'auto-approve')",
152+
if: "contains(github.event.pull_request.labels.*.name, 'auto-approve')",
151153
permissions: {
152154
pullRequests: JobPermission.WRITE,
153155
},
154156
steps: [
155157
{
156-
uses: 'hmarr/auto-approve-action@v3.2.1',
158+
uses: 'hmarr/auto-approve-action@v4.0.0',
157159
with: {
158160
'github-token': '${{ secrets.PROJEN_GITHUB_TOKEN }}',
161+
'review-message': 'Auto approved automated PR',
159162
},
160163
},
161164
],
@@ -576,6 +579,7 @@ export function buildCodeGenerationWorkflow(project: AwsCdkConstructLibrary) {
576579
'author': 'github-actions <[email protected]>',
577580
'committer': 'github-actions <[email protected]>',
578581
'signoff': true,
582+
'labels': 'auto-approve',
579583
},
580584
},
581585
],

0 commit comments

Comments
 (0)