-
Notifications
You must be signed in to change notification settings - Fork 77
142 lines (123 loc) · 4.84 KB
/
update-release-status.yml
File metadata and controls
142 lines (123 loc) · 4.84 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
132
133
134
135
136
137
138
139
140
141
142
name: "Update Release Status"
on:
workflow_dispatch:
inputs:
head-sha:
description: |
The head SHA to use.
type: string
required: true
env:
HEAD_SHA: ${{ inputs.head-sha }}
jobs:
validate-check-runs:
runs-on: ubuntu-22.04
outputs:
status: ${{ steps.set-output.outputs.status }}
conclusion: ${{ steps.set-output.outputs.conclusion }}
permissions:
actions: write
checks: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ inputs.head-sha }}
- name: Get release status check run
id: get-check-run
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
check_run_info=$(gh api \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--jq '.check_runs[] | select(.name == "release-status") | {id: .id, status: .status, conclusion: .conclusion}' \
/repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs)
if [[ -z "$check_run_info" ]]; then
echo "No release status check run found"
exit 1
fi
check_run_id=$(echo "$check_run_info" | jq -r '.id')
check_run_status=$(echo "$check_run_info" | jq -r '.status')
check_run_conclusion=$(echo "$check_run_info" | jq -r '.conclusion')
echo "CHECK_RUN_ID=$check_run_id" >> "$GITHUB_ENV"
echo "CHECK_RUN_STATUS=$check_run_status" >> "$GITHUB_ENV"
echo "CHECK_RUN_CONCLUSION=$check_run_conclusion" >> "$GITHUB_ENV"
- name: Reset release status
if: env.CHECK_RUN_STATUS == 'completed'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
check_run_id=$(gh api \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--field name="release-status" \
--field head_sha="$HEAD_SHA" \
--jq ".id" \
/repos/$GITHUB_REPOSITORY/check-runs)
echo "Created release status check run with id $check_run_id"
# Reset the status to in progress.
echo "CHECK_RUN_STATUS=in_progress" >> "$GITHUB_ENV"
echo "CHECK_RUN_ID=$check_run_id" >> "$GITHUB_ENV"
- name: Check all runs completed
if: env.CHECK_RUN_STATUS != 'completed'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
check_runs=$(gh api \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--jq '.check_runs | map(select(.name != "release-status"))' \
/repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs)
status_stats=$(echo "$check_runs" | jq -r '. | {failed: (map(select(.conclusion == "failure")) | length), pending: (map(select(.status != "completed")) | length) }')
echo "status_stats=$status_stats"
failed=$(echo "$status_stats" | jq -r '.failed')
pending=$(echo "$status_stats" | jq -r '.pending')
echo "CHECK_RUNS_FAILED=$failed" >> "$GITHUB_ENV"
echo "CHECK_RUNS_PENDING=$pending" >> "$GITHUB_ENV"
- name: Conclude release status
if: env.CHECK_RUNS_PENDING == '0' && env.CHECK_RUN_STATUS != 'completed'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
if [[ "$CHECK_RUNS_FAILED" == "0" ]]; then
echo "All check runs succeeded"
conclusion="success"
else
echo "Some check runs failed"
conclusion="failure"
fi
jq -n \
--arg status "completed" \
--arg conclusion "$conclusion" \
'{status: $status, conclusion: $conclusion}' \
| \
gh api \
--method PATCH \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--input - \
/repos/$GITHUB_REPOSITORY/check-runs/$CHECK_RUN_ID
echo "RELEASE_STATUS_CONCLUSION=$conclusion" >> "$GITHUB_ENV"
- name: Set output
id: set-output
run: |
echo "conclusion=$RELEASE_STATUS_CONCLUSION" >> "$GITHUB_OUTPUT"
if [[ "$CHECK_RUNS_PENDING" == "0" ]]; then
echo "status=completed" >> "$GITHUB_OUTPUT"
else
echo "status=in_progress" >> "$GITHUB_OUTPUT"
fi
update-release:
needs: validate-check-runs
if: needs.validate-check-runs.outputs.status == 'completed' && needs.validate-check-runs.outputs.conclusion == 'success'
uses: ./.github/workflows/update-release.yml
permissions:
actions: write
contents: write
pull-requests: write
with:
head-sha: ${{ inputs.head-sha }}
secrets:
AUTOMATION_PRIVATE_KEY: ${{ secrets.AUTOMATION_PRIVATE_KEY }}