forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (99 loc) · 4.59 KB
/
Copy pathnightly_detect_failure.yml
File metadata and controls
108 lines (99 loc) · 4.59 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
name: Post to zulip if the nightly-testing branch is failing.
on:
workflow_run:
workflows: ["continuous integration"]
types:
- completed
jobs:
handle_failure:
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.head_branch == 'nightly-testing' }}
runs-on: ubuntu-latest
steps:
- name: Send message on Zulip
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_API_KEY }}
email: 'github-mathlib4-bot@leanprover.zulipchat.com'
organization-url: 'https://leanprover.zulipchat.com'
to: 'mathlib reviewers'
type: 'stream'
topic: 'CI failure on the nightly-testing branch'
content: |
❌ The latest CI for branch#nightly-testing has [failed](https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}).
handle_success:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'nightly-testing' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: nightly-testing # checkout nightly-testing branch
fetch-depth: 0 # checkout all branches so that we can push from `nightly-testing` to `nightly-testing-YYYY-MM-DD`
token: ${{ secrets.NIGHTLY_TESTING }}
- name: Update the nightly-testing-YYYY-MM-DD branch
run: |
toolchain=$(<lean-toolchain)
if [[ $toolchain =~ leanprover/lean4:nightly-([a-zA-Z0-9_-]+) ]]; then
version=${BASH_REMATCH[1]}
echo "NIGHTLY=$version" >> $GITHUB_ENV
# Check if the remote tag exists
if git ls-remote --tags --exit-code origin "nightly-testing-$version" >/dev/null; then
echo "Tag nightly-testing-$version already exists on the remote."
else
# If the tag does not exist, create and push the tag to remote
echo "Creating tag nightly-testing-$version from the current state of the nightly-testing branch."
git tag nightly-testing-$version
git push origin nightly-testing-$version
fi
else
echo "Error: The file lean-toolchain does not contain the expected pattern."
exit 1
fi
# Next, we'll update the `nightly-with-mathlib` branch at Lean.
- name: Cleanup workspace
run: |
sudo rm -rf *
# Checkout the Lean repository on 'nightly-with-mathlib'
- name: Checkout Lean repository
uses: actions/checkout@v3
with:
repository: leanprover/lean4
token: ${{ secrets.LEAN_PR_TESTING }}
ref: nightly-with-mathlib
# Merge the relevant nightly.
- name: Fetch tags from 'lean4-nightly', and merge relevant nightly into 'nightly-with-mathlib'
run: |
git remote add nightly https://github.com/leanprover/lean4-nightly.git
git fetch nightly --tags
# Note: old jobs may run out of order, but it is safe to merge an older `nightly-YYYY-MM-DD`.
git merge nightly-${NIGHTLY} --strategy-option ours --allow-unrelated-histories || true
git push origin
# Now post a success message to zulip, if the last message there is not a success message.
# https://chat.openai.com/share/87656d2c-c804-4583-91aa-426d4f1537b3
- name: Install Zulip API client
run: pip install zulip
- name: Check last message and post if necessary
run: |
import zulip
client = zulip.Client(email='github-mathlib4-bot@leanprover.zulipchat.com', api_key='${{ secrets.ZULIP_API_KEY }}', site='https://leanprover.zulipchat.com')
# Get the last message in the 'CI failure on the nightly-testing branch' topic
request = {
'anchor': 'newest',
'num_before': 1,
'num_after': 0,
'narrow': [{'operator': 'stream', 'operand': 'mathlib reviewers'}, {'operator': 'topic', 'operand': 'CI failure on the nightly-testing branch'}],
'apply_markdown': True
}
response = client.get_messages(request)
messages = response['messages']
if not messages or messages[0]['content'] != "✅ The latest CI for branch#nightly-testing has succeeded!":
# Post the success message
request = {
'type': 'stream',
'to': 'mathlib reviewers',
'topic': 'CI failure on the nightly-testing branch',
'content': '✅ The latest CI for branch#nightly-testing has succeeded!'
}
result = client.send_message(request)
print(result)
shell: python