forked from koala73/worldmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (56 loc) · 2.42 KB
/
deploy-gate.yml
File metadata and controls
66 lines (56 loc) · 2.42 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
name: Deploy Gate
# Runs whenever Test or Typecheck completes on a PR/push.
# Checks whether BOTH workflows have passed for the same commit SHA.
# Posts a commit status on the PR's head SHA so branch protection can see it.
on:
workflow_run:
workflows: ["Test", "Typecheck"]
types: [completed]
permissions:
statuses: write
jobs:
gate:
runs-on: ubuntu-latest
steps:
- name: Check unit + typecheck both passed for this SHA
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.workflow_run.head_sha }}
run: |
# Poll check-runs for this SHA and find the latest result for each required job
runs=$(gh api "repos/$REPO/commits/$SHA/check-runs" \
--jq '.check_runs | map(select(.name == "unit" or .name == "typecheck"))')
unit=$(echo "$runs" | python3 -c "
import sys, json
runs = json.load(sys.stdin)
matches = [r for r in runs if r['name'] == 'unit']
if not matches: print('pending')
else: print(sorted(matches, key=lambda r: r.get('completed_at') or '')[-1]['conclusion'] or 'pending')
")
typecheck=$(echo "$runs" | python3 -c "
import sys, json
runs = json.load(sys.stdin)
matches = [r for r in runs if r['name'] == 'typecheck']
if not matches: print('pending')
else: print(sorted(matches, key=lambda r: r.get('completed_at') or '')[-1]['conclusion'] or 'pending')
")
echo "unit=$unit typecheck=$typecheck"
if [ "$unit" = "pending" ] || [ "$typecheck" = "pending" ]; then
gh api "repos/$REPO/statuses/$SHA" --method POST \
--field state="pending" \
--field context="gate" \
--field description="Waiting for unit + typecheck to complete"
exit 0
fi
if [ "$unit" != "success" ] || [ "$typecheck" != "success" ]; then
gh api "repos/$REPO/statuses/$SHA" --method POST \
--field state="failure" \
--field context="gate" \
--field description="Required checks did not pass (unit=$unit typecheck=$typecheck)"
exit 0
fi
gh api "repos/$REPO/statuses/$SHA" --method POST \
--field state="success" \
--field context="gate" \
--field description="unit + typecheck both passed"