Skip to content

Commit d9acdfd

Browse files
committed
ci: refactor: proceedIfBot
1 parent bd6672d commit d9acdfd

File tree

6 files changed

+39
-61
lines changed

6 files changed

+39
-61
lines changed

.github/jsTemplates/utils/jobs.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@ import { defaultJobMachine, bot } from './constants';
33

44
// eslint-disable-next-line @typescript-eslint/naming-convention
55
export const JOB = {
6-
proceedIfBot: {
7-
outputs: {
8-
status: '${{ steps.check-author.conclusion }}',
9-
},
6+
dumpGithubContext: {
107
...defaultJobMachine,
11-
steps: [
12-
STEP.dumpContext('github'),
13-
{
14-
name: `Check if author is ${bot}`,
15-
id: 'check-author',
16-
if: `github.event.pull_request.user.login != '${bot}'`,
17-
run: `echo Skip! Pull request created by \${{ github.event.pull_request.user.login }} not ${bot}
18-
exit 0`,
19-
},
20-
],
8+
steps: [STEP.dumpContext('github')],
9+
},
10+
proceedIfBot: {
11+
if: `github.event.pull_request.user.login == '${bot}'`,
12+
steps: [STEP.echo(`Pull request created by \${{ github.event.pull_request.user.login }} is ${bot}`)],
2113
},
2214
};

.github/jsTemplates/utils/steps.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ export const changePRBaseFromMasterToDevelop: UsesStep = {
164164
},
165165
};
166166

167+
export function echo(message: string, env?: { [key: string]: string }): RunStep {
168+
const runStep: RunStep = {
169+
run: `echo ${message}`,
170+
};
171+
172+
if (env) {
173+
runStep.env = env;
174+
}
175+
176+
return runStep;
177+
}
178+
167179
export function cancelWorkflow(workflow: number): UsesStep {
168180
return {
169181
uses: DEPENDENCIES['cancel-workflow-action'],

.github/jsTemplates/workflows/automerge.yml.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,15 @@ export = {
1616
},
1717
},
1818
jobs: {
19-
'pre-automerge-bot': JOB.proceedIfBot,
19+
'dump-github-context': JOB.dumpGithubContext,
20+
'cancel-not-dependabot': JOB.proceedIfBot,
2021
// Ignore labels does not contain 'dependencies' || contains 'released'
2122
'cancel-released-label': {
22-
needs: ['pre-automerge-bot'],
23+
needs: ['cancel-not-dependabot'],
2324
...defaultJobMachine,
24-
if: `needs.pre-automerge-bot.outputs.status != 'success'
25-
&& contains( github.event.pull_request.labels.*.name, '${dependabotLabel}')
25+
if: `contains( github.event.pull_request.labels.*.name, '${dependabotLabel}')
2626
&& !contains( github.event.pull_request.labels.*.name, '${avoidMergeLabel}')`,
27-
steps: [
28-
{
29-
run: `echo "There is no '${avoidMergeLabel}' label!"`,
30-
},
31-
],
27+
steps: [STEP.echo(`There is no '${avoidMergeLabel}' label!`)],
3228
},
3329
// Since we are looking for 2 labels ['dependencies' & <ecosystem>],
3430
// we get 2 runs of this workflow due to the 2 labelled trigger.
@@ -37,11 +33,7 @@ export = {
3733
needs: ['cancel-released-label'],
3834
...defaultJobMachine,
3935
if: `github.event.action != 'labeled' || github.event.label.name != '${dependabotLabel}'`,
40-
steps: [
41-
{
42-
run: `echo "There is no '${dependabotLabel}' label!"`,
43-
},
44-
],
36+
steps: [STEP.echo(`There is no '${dependabotLabel}' label!`)],
4537
},
4638
'github-action': {
4739
needs: ['cancel-dependencies-label'],

.github/jsTemplates/workflows/security-update.yml.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ export = {
1414
},
1515
},
1616
jobs: {
17-
'pre-pr-update-base': JOB.proceedIfBot,
17+
'cancel-not-dependabot': JOB.proceedIfBot,
1818
'pr-update-base': {
19-
needs: ['pre-pr-update-base'],
20-
if: `needs.pre-pr-update-base.outputs.status != 'success'`,
19+
needs: ['cancel-not-dependabot'],
2120
...defaultJobMachine,
2221
steps: [STEP.changePRBaseFromMasterToDevelop],
2322
},

.github/workflows/automerge.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,33 @@ name: automerge-dependabot
1616
branches:
1717
- develop
1818
jobs:
19-
pre-automerge-bot:
20-
outputs:
21-
status: '${{ steps.check-author.conclusion }}'
19+
dump-github-context:
2220
runs-on: ubuntu-latest
2321
steps:
2422
- name: Dump github context
2523
env:
2624
GITHUB_CONTEXT: '${{ toJson(github) }}'
2725
run: echo "$GITHUB_CONTEXT"
28-
- name: 'Check if author is dependabot[bot]'
29-
id: check-author
30-
if: 'github.event.pull_request.user.login != ''dependabot[bot]'''
31-
run: |-
32-
echo Skip! Pull request created by ${{ github.event.pull_request.user.login }} not dependabot[bot]
33-
exit 0
26+
cancel-not-dependabot:
27+
if: 'github.event.pull_request.user.login == ''dependabot[bot]'''
28+
steps:
29+
- run: 'echo Pull request created by ${{ github.event.pull_request.user.login }} is dependabot[bot]'
3430
cancel-released-label:
3531
needs:
36-
- pre-automerge-bot
32+
- cancel-not-dependabot
3733
runs-on: ubuntu-latest
3834
if: |-
39-
needs.pre-automerge-bot.outputs.status != 'success'
40-
&& contains( github.event.pull_request.labels.*.name, 'dependencies')
35+
contains( github.event.pull_request.labels.*.name, 'dependencies')
4136
&& !contains( github.event.pull_request.labels.*.name, 'released')
4237
steps:
43-
- run: echo "There is no 'released' label!"
38+
- run: echo There is no 'released' label!
4439
cancel-dependencies-label:
4540
needs:
4641
- cancel-released-label
4742
runs-on: ubuntu-latest
4843
if: github.event.action != 'labeled' || github.event.label.name != 'dependencies'
4944
steps:
50-
- run: echo "There is no 'dependencies' label!"
45+
- run: echo There is no 'dependencies' label!
5146
github-action:
5247
needs:
5348
- cancel-dependencies-label

.github/workflows/security-update.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,13 @@ name: security-update
1414
branches:
1515
- master
1616
jobs:
17-
pre-pr-update-base:
18-
outputs:
19-
status: '${{ steps.check-author.conclusion }}'
20-
runs-on: ubuntu-latest
17+
cancel-not-dependabot:
18+
if: 'github.event.pull_request.user.login == ''dependabot[bot]'''
2119
steps:
22-
- name: Dump github context
23-
env:
24-
GITHUB_CONTEXT: '${{ toJson(github) }}'
25-
run: echo "$GITHUB_CONTEXT"
26-
- name: 'Check if author is dependabot[bot]'
27-
id: check-author
28-
if: 'github.event.pull_request.user.login != ''dependabot[bot]'''
29-
run: |-
30-
echo Skip! Pull request created by ${{ github.event.pull_request.user.login }} not dependabot[bot]
31-
exit 0
20+
- run: 'echo Pull request created by ${{ github.event.pull_request.user.login }} is dependabot[bot]'
3221
pr-update-base:
3322
needs:
34-
- pre-pr-update-base
35-
if: needs.pre-pr-update-base.outputs.status != 'success'
23+
- cancel-not-dependabot
3624
runs-on: ubuntu-latest
3725
steps:
3826
- uses: a-b-r-o-w-n/check-base-branch-action@v1

0 commit comments

Comments
 (0)