Skip to content

Commit 6453913

Browse files
committed
Add Verus update test workflow
1 parent 839f0b4 commit 6453913

File tree

2 files changed

+194
-0
lines changed

2 files changed

+194
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Promote Update-Test to Main & Version
2+
3+
on:
4+
repository_dispatch:
5+
types: [verus-update-test-success]
6+
7+
jobs:
8+
promote:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout update-test
12+
uses: actions/checkout@v3
13+
with:
14+
ref: ${{ github.event.client_payload.branch }}
15+
fetch-depth: 0
16+
17+
- name: Configure Git for CI
18+
run: |
19+
git config user.name "Verus CI Bot"
20+
git config user.email "[email protected]"
21+
22+
- name: Read version branch from rust-toolchain.toml
23+
id: read-version
24+
run: |
25+
VERUS_VERSION=$(grep '^channel' rust-toolchain.toml | awk -F'"' '{print $2}')
26+
echo "VERUS_VERSION=$VERUS_VERSION" >> $GITHUB_ENV
27+
echo "Using version branch: $VERUS_VERSION"
28+
29+
- name: Push to version branch
30+
run: git push origin HEAD:${{ env.VERUS_VERSION }} --force
31+
32+
- name: Fetch main and origin
33+
run: |
34+
git fetch origin main --tags
35+
git fetch --all
36+
37+
- name: Cherry-pick workflow commit from main
38+
run: |
39+
WORKFLOW_COMMIT=$(git log origin/main --grep="Add Verus update test workflow" --pretty=format:"%H" -n 1)
40+
if [ -z "$WORKFLOW_COMMIT" ]; then
41+
echo "No workflow commit found on main. Aborting."
42+
exit 1
43+
else
44+
git cherry-pick $WORKFLOW_COMMIT
45+
fi
46+
47+
- name: Push to main
48+
run: git push origin HEAD:main --force
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Sync Upstream Verus & Dispatch
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 23 * * *"
7+
8+
jobs:
9+
check-version:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
continue: ${{ steps.version-check.outputs.continue }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Fetch upstream
20+
run: |
21+
git remote add upstream https://github.com/verus-lang/verus.git || true
22+
git fetch upstream main
23+
24+
- name: Read versions
25+
id: version-check
26+
run: |
27+
# upstream version
28+
UPSTREAM_VERSION=$(git show upstream/main:rust-toolchain.toml | grep '^channel' | awk -F'"' '{print $2}')
29+
echo "Upstream version: $UPSTREAM_VERSION"
30+
echo "UPSTREAM_VERSION=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
31+
32+
# local fork version
33+
VERUS_VERSION=$(grep '^channel' rust-toolchain.toml | awk -F'"' '{print $2}')
34+
echo "Local VERUS_VERSION: $VERUS_VERSION"
35+
echo "VERUS_VERSION=$VERUS_VERSION" >> $GITHUB_OUTPUT
36+
37+
if [ "$UPSTREAM_VERSION" != "$VERUS_VERSION" ]; then
38+
echo "Version changed! Fail workflow and create issue."
39+
echo "continue=false" >> $GITHUB_OUTPUT
40+
exit 1
41+
else
42+
echo "Version unchanged."
43+
echo "continue=true" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Create issue if version changed
47+
if: failure()
48+
uses: actions/github-script@v7
49+
with:
50+
github-token: ${{ secrets.GITHUB_TOKEN }}
51+
script: |
52+
const upstream_version = '${{ steps.version-check.outputs.UPSTREAM_VERSION }}';
53+
const local_version = '${{ steps.version-check.outputs.VERUS_VERSION }}';
54+
const upstream_commit = await exec.getExecOutput('git', ['rev-parse', 'upstream/main']);
55+
56+
const title = 'Detected upstream Verus rust-toolchain version change';
57+
const body = `Detected upstream Verus rust-toolchain version change.
58+
59+
The [upstream repo](https://github.com/verus-lang/verus) has updated its rust-toolchain channel version.
60+
61+
Automation is halted.
62+
63+
Old version: ${local_version || 'unknown'}
64+
New version: ${upstream_version || 'unknown'}
65+
Upstream commit: ${upstream_commit.stdout.trim()}
66+
67+
Please manually update local code before re-running this workflow.`;
68+
69+
// Check if there's already an open issue with this title
70+
const issues = await github.rest.issues.listForRepo({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
state: 'open',
74+
labels: 'automation'
75+
});
76+
77+
const existingIssue = issues.data.find(issue => issue.title === title);
78+
79+
if (existingIssue) {
80+
// Update existing issue
81+
await github.rest.issues.createComment({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
issue_number: existingIssue.number,
85+
body: `Updated detection:\n\n${body}`
86+
});
87+
console.log(`Updated existing issue #${existingIssue.number}`);
88+
} else {
89+
// Create new issue
90+
const issue = await github.rest.issues.create({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
title: title,
94+
body: body,
95+
labels: ['automation'],
96+
});
97+
console.log(`Created new issue #${issue.data.number}`);
98+
}
99+
100+
update-test:
101+
needs: check-version
102+
if: needs.check-version.outputs.continue == 'true'
103+
runs-on: ubuntu-latest
104+
steps:
105+
- name: Checkout
106+
uses: actions/checkout@v3
107+
with:
108+
fetch-depth: 0
109+
110+
- name: Configure Git for CI
111+
run: |
112+
git config user.name "Verus CI Bot"
113+
git config user.email "[email protected]"
114+
115+
- name: Fetch upstream & origin
116+
run: |
117+
git remote add upstream https://github.com/verus-lang/verus.git || true
118+
git fetch upstream main
119+
git fetch origin update-test
120+
121+
- name: Switch to update-test
122+
run: git checkout update-test
123+
124+
- name: Reset update-test to upstream/main
125+
run: git reset --hard upstream/main
126+
127+
- name: Cherry-pick "Fix for asterinas" commit
128+
run: |
129+
COMMIT_SHA=$(git log main --grep="Fix for asterinas" --pretty=format:"%H" -n 1)
130+
if [ -z "$COMMIT_SHA" ]; then
131+
echo "No commit with message 'Fix for asterinas' found on main. Aborting."
132+
exit 1
133+
else
134+
git cherry-pick $COMMIT_SHA
135+
fi
136+
137+
- name: Push update-test to origin
138+
run: git push origin update-test --force
139+
140+
- name: Repository dispatch to vostd
141+
uses: peter-evans/repository-dispatch@v2
142+
with:
143+
token: ${{ secrets.VERUS_TEST_TOKEN }}
144+
repository: asterinas/vostd
145+
event-type: verus-update-test
146+
client-payload: '{"branch":"main"}'

0 commit comments

Comments
 (0)