-
Notifications
You must be signed in to change notification settings - Fork 673
131 lines (116 loc) · 5.27 KB
/
Copy pathstatus-checks.yml
File metadata and controls
131 lines (116 loc) · 5.27 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: status-checks
on:
issue_comment:
types: [created]
pull_request:
types: [labeled, opened, reopened, synchronize]
merge_group:
branches:
- main
types: [checks_requested]
permissions:
issues: write
pull-requests: write
jobs:
github-ui:
runs-on: ubuntu-latest
if: "${{ (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'integration-tests: skipped manually')) || github.event_name == 'merge_group' || (github.event_name == 'issue_comment' && github.event.issue.pull_request != null) }}"
steps:
- name: Generate token for primer
id: generate_primer_token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
app-id: 902635
owner: 'primer'
repositories: 'react'
private-key: ${{ secrets.PRIMER_INTEGRATION_APP_PRIVATE_KEY }}
permission-statuses: 'write'
# Support for reporting on required github-ui status checks on pull requests
- name: Override status checks for pull request
if: "${{ github.event_name == 'pull_request' }}"
run: |
# Get the timeline event ID for the label being added
EVENT_ID=$(gh api "/repos/primer/react/issues/$PR_NUMBER/timeline" \
--jq '.[] | select(.event == "labeled" and .label.name == "integration-tests: skipped manually") | .id' \
| tail -n 1)
# Construct the HTML URL from the event ID
if [ -n "$EVENT_ID" ]; then
TARGET_URL="${{ github.event.pull_request.html_url }}#event-$EVENT_ID"
else
TARGET_URL="${{ github.event.pull_request.html_url }}"
fi
gh api -X POST "/repos/primer/react/statuses/$SHA" \
-f state='success' \
-f context='github-ui / ci' \
-f description='Skipped' \
-f target_url="$TARGET_URL"
gh api -X POST "/repos/primer/react/statuses/$SHA" \
-f state='success' \
-f context='github-ui / projects' \
-f description='Skipped' \
-f target_url="$TARGET_URL"
gh api -X POST "/repos/primer/react/statuses/$SHA" \
-f state='success' \
-f context='github-ui / vrt' \
-f description='Skipped' \
-f target_url="$TARGET_URL"
env:
GH_TOKEN: ${{ steps.generate_primer_token.outputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
SHA: ${{ github.event.pull_request.head.sha }}
# Support for reporting on required github-ui status checks in merge queues
- name: Override status checks for merge queue
if: "${{ github.event_name == 'merge_group' }}"
run: |
gh api -X POST "/repos/primer/react/statuses/${{ github.event.merge_group.head_sha }}" \
-f state='success' \
-f context='github-ui / ci' \
-f description='Skipped'
gh api -X POST "/repos/primer/react/statuses/${{ github.event.merge_group.head_sha }}" \
-f state='success' \
-f context='github-ui / projects' \
-f description='Skipped'
gh api -X POST "/repos/primer/react/statuses/${{ github.event.merge_group.head_sha }}" \
-f state='success' \
-f context='github-ui / vrt' \
-f description='Skipped'
env:
GH_TOKEN: ${{ steps.generate_primer_token.outputs.token }}
# Support for reporting on required github-ui status checks via issue comment, useful for Pull Requests from forks
- name: Issue comment command
if: ${{ github.event_name == 'issue_comment' }}
id: command
uses: github/command@3442f3fa1efe01bdb024b157083c337902d17372 # v2.0.3
with:
command: '.skip-integration-checks'
allowed_contexts: pull_request
# Note: this permission step is _critical_ to make sure only maintainers can run the command
permissions: 'write,admin'
allow_forks: true
- name: Override status checks for issue comment
if: ${{ github.event_name == 'issue_comment' && steps.command.outputs.continue == 'true' }}
run: |
SHA=$(gh pr view -R 'primer/react' $NUMBER --json headRefOid --jq '.headRefOid')
if [ -z "$SHA" ]; then
echo "No pull request found for issue #$NUMBER, or gh pr view failed."
exit 1
fi
gh api -X POST "/repos/primer/react/statuses/$SHA" \
-f state='success' \
-f context='github-ui / ci' \
-f description='Manual override' \
-f target_url="$COMMENT_URL"
gh api -X POST "/repos/primer/react/statuses/$SHA" \
-f state='success' \
-f context='github-ui / projects' \
-f description='Manual override' \
-f target_url="$COMMENT_URL"
gh api -X POST "/repos/primer/react/statuses/$SHA" \
-f state='success' \
-f context='github-ui / vrt' \
-f description='Manual override' \
-f target_url="$COMMENT_URL"
env:
COMMENT_URL: ${{ github.event.comment.html_url }}
GH_TOKEN: ${{ steps.generate_primer_token.outputs.token }}
NUMBER: ${{ github.event.issue.number }}