-
Notifications
You must be signed in to change notification settings - Fork 10
102 lines (95 loc) · 4.64 KB
/
post-pull-request-checks-automation.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Post Pull Request Checks Automation
on:
workflow_call:
secrets:
# We can't access org secrets here so they need to be passed in.
MERGE_TOKEN:
required: false
description: >
An authentication token, like a personal access token (PAT), that provides write access to the repository and
can be used to merge the pull request. This is necessary because when a pull request is merged while being
authenticated with the default GITHUB_TOKEN of a workflow run, then the merge won't trigger other workflows
(like a build workflow on the target branch). This is an intentional limitation, see:
https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow.
Thus, we need to use an alternative authentication token. See
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
for info on how to create PATs; you'll need one with the "repo" scope. Check out
https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs
for instructions on what other tokens you can use.
JIRA_BASE_URL:
required: true
description: >
Configure as explained under
https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md.
JIRA_USER_EMAIL:
required: true
description: >
Configure as explained under
https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md.
JIRA_API_TOKEN:
required: true
description: >
Configure as explained under
https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows/Productivity/CreateJiraIssuesForCommunityActivities.md.
inputs:
merge-method:
description: >
The merge strategy to be used for the auto-merge-pull-request action. See the API documentation for
"merge_method" for applicable values:
https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request
type: string
default: merge
timeout-minutes:
type: number
# Sometimes the job is slow to start, so we have to factor in that.
default: 3
description: Configuration for the timeout-minutes parameter of the workflow.
run-only-latest-workflow:
type: string
description: Run only if the current workflow is the most recent workflow.
default: true
jobs:
post-pull-request-checks-automation:
name: Post Pull Request Checks Automation
runs-on: ubuntu-24.04
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Check Further Steps Should Run
if: inputs.run-only-latest-workflow == 'true'
uses: Lombiq/GitHub-Actions/.github/actions/check-current-workflow-is-latest@dev
id: check-steps-should-run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
current-workflow-id: ${{ github.run_id }}
- name: Set Merge Token
if: steps.check-steps-should-run.outputs.is-latest != 'false'
shell: pwsh
env:
MERGE_TOKEN: ${{ secrets.MERGE_TOKEN }}
run: |
$mergeToken = $Env:MERGE_TOKEN ? $Env:MERGE_TOKEN : "${{ secrets.GITHUB_TOKEN }}"
# This could use Set-GitHubEnv but then we'd need to turn this into an action.
"MERGE_TOKEN=$mergeToken" >> $Env:GITHUB_ENV
- name: Automatically Merge Pull Request
if: steps.check-steps-should-run.outputs.is-latest != 'false'
uses: Lombiq/GitHub-Actions/.github/actions/auto-merge-pull-request@dev
env:
GITHUB_TOKEN: ${{ env.MERGE_TOKEN }}
with:
merge-method: ${{ inputs.merge-method }}
- name: Automatically Transition Jira issue
if: steps.check-steps-should-run.outputs.is-latest != 'false'
uses: Lombiq/GitHub-Actions/.github/actions/auto-transition-jira-issue@dev
env:
GITHUB_TOKEN: ${{ env.MERGE_TOKEN }}
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
- name: Remove Label
if: steps.check-steps-should-run.outputs.is-latest != 'false'
uses: Lombiq/GitHub-Actions/.github/actions/add-remove-label@dev
with:
token: ${{ env.MERGE_TOKEN }}
labels: merge-and-resolve-jira-issue-if-checks-succeed
type: remove