Skip to content

Commit 304d1da

Browse files
authored
ci: automatically release with CI (#956)
This patch adds a CI to release NEMU automatically. It will try to release at 12:00 (UTC+8) everyday. According to the demand of the release ci, build difftest-so is moved to a sperate CI for reuse.
1 parent 9f7b09b commit 304d1da

File tree

4 files changed

+186
-27
lines changed

4 files changed

+186
-27
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build
2+
on:
3+
workflow_call:
4+
5+
jobs:
6+
compile-difftest-so:
7+
strategy:
8+
matrix:
9+
container-version: ['ubuntu-20.04', 'ubuntu-22.04', 'ubuntu-24.04']
10+
fail-fast: false
11+
runs-on: ubuntu-latest
12+
container:
13+
image: ghcr.io/openxiangshan/xs-env:${{ matrix.container-version }}
14+
continue-on-error: false
15+
name: Compile difftest-so
16+
timeout-minutes: 30
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup env
22+
run: |
23+
echo "NEMU_HOME=$GITHUB_WORKSPACE" >> $GITHUB_ENV
24+
25+
- name: compile dynamic libraries
26+
run: |
27+
bash ./scripts/generate_so_for_difftest.sh
28+
29+
- name: archive difftest-so artifacts
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: difftest-so-${{ matrix.container-version }}
33+
path: |
34+
artifact

.github/workflows/ci.yml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -371,29 +371,5 @@ jobs:
371371
run: |
372372
./build/riscv64-nemu-interpreter -b --diff ${SPIKE_SO} ${CI_WORKLOADS}/linux/rvv-bench/fw_payload.bin -I 400000000
373373
374-
compile-difftest-so:
375-
strategy:
376-
matrix:
377-
container-version: ['ubuntu-20.04', 'ubuntu-22.04', 'ubuntu-24.04']
378-
fail-fast: false
379-
runs-on: ubuntu-latest
380-
container:
381-
image: ghcr.io/openxiangshan/xs-env:${{ matrix.container-version }}
382-
continue-on-error: false
383-
name: Compile difftest-so
384-
timeout-minutes: 30
385-
steps:
386-
- name: Checkout repository
387-
uses: actions/checkout@v4
388-
- name: Setup env
389-
run: |
390-
echo "NEMU_HOME=$GITHUB_WORKSPACE" >> $GITHUB_ENV
391-
- name: compile dynamic libraries
392-
run: |
393-
bash ./scripts/generate_so_for_difftest.sh
394-
- name: archive difftest-so artifacts
395-
uses: actions/upload-artifact@v4
396-
with:
397-
name: difftest-so-${{ matrix.container-version }}
398-
path: |
399-
artifact
374+
build:
375+
uses: ./.github/workflows/build.yml

.github/workflows/release.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: Auto Release
2+
3+
on:
4+
schedule:
5+
- cron: '0 4 * * *' # 12:00 UTC+8
6+
workflow_dispatch:
7+
8+
jobs:
9+
check-and-release:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
should_release: ${{ steps.check_diff.outputs.should_release }}
13+
new_tag: ${{ steps.generate_tag.outputs.new_tag }}
14+
latest_tag: ${{ steps.get_latest_tag.outputs.latest_tag }}
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get latest release tag
22+
id: get_latest_tag
23+
run: |
24+
latest_tag=$(git tag --sort=-version:refname | head -n 1)
25+
if [ -z "$latest_tag" ]; then
26+
echo "No previous release found"
27+
echo "latest_tag=" >> $GITHUB_OUTPUT
28+
else
29+
echo "Latest tag: $latest_tag"
30+
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
31+
fi
32+
33+
- name: Check for changes since last release
34+
id: check_diff
35+
run: |
36+
latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}"
37+
if [ -z "$latest_tag" ]; then
38+
echo "No previous release, will create first release"
39+
echo "should_release=true" >> $GITHUB_OUTPUT
40+
else
41+
diff_count=$(git rev-list ${latest_tag}..HEAD --count)
42+
if [ "$diff_count" -eq "0" ]; then
43+
echo "No changes since last release ($latest_tag)"
44+
echo "should_release=false" >> $GITHUB_OUTPUT
45+
else
46+
echo "Found $diff_count commits since last release"
47+
echo "should_release=true" >> $GITHUB_OUTPUT
48+
fi
49+
fi
50+
51+
- name: Generate CalVer tag
52+
id: generate_tag
53+
if: steps.check_diff.outputs.should_release == 'true'
54+
run: |
55+
# Get current date (UTC+8)
56+
TZ='Asia/Shanghai' year=$(date +%Y)
57+
TZ='Asia/Shanghai' month=$(date +%m)
58+
59+
# Find all version in this year/month with 'v' prefix and 'r' suffix
60+
prefix="v${year}.${month}.r"
61+
existing_tags=$(git tag -l "${prefix}*" | sort -V)
62+
63+
if [ -z "$existing_tags" ]; then
64+
# No version in this year/month, start from 1
65+
micro=1
66+
else
67+
# Micro + 1
68+
last_tag=$(echo "$existing_tags" | tail -n 1)
69+
last_micro=$(echo "$last_tag" | sed "s/${prefix}//")
70+
micro=$((last_micro + 1))
71+
fi
72+
73+
new_tag="v${year}.${month}.r${micro}"
74+
echo "New tag: $new_tag"
75+
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
76+
77+
build:
78+
name: build artifacts
79+
needs: check-and-release
80+
if: needs.check-and-release.outputs.should_release == 'true'
81+
uses: ./.github/workflows/build.yml
82+
83+
create-release:
84+
needs: [check-and-release, build]
85+
if: needs.check-and-release.outputs.should_release == 'true'
86+
runs-on: ubuntu-latest
87+
permissions:
88+
contents: write
89+
steps:
90+
- name: Checkout repository
91+
uses: actions/checkout@v4
92+
with:
93+
fetch-depth: 0
94+
95+
- name: Download all artifacts
96+
uses: actions/download-artifact@v4
97+
with:
98+
pattern: difftest-so-*
99+
path: release-artifacts
100+
101+
- name: Prepare release assets
102+
run: |
103+
mkdir -p release-files
104+
cd release-artifacts
105+
ls -l
106+
new_tag="${{ needs.check-and-release.outputs.new_tag }}"
107+
for dir in difftest-so-*; do
108+
if [ -d "$dir" ]; then
109+
container_version=$(echo "$dir" | sed 's/difftest-so-//')
110+
cd "$dir"
111+
tar -czf "../../release-files/difftest-so-${new_tag}-${container_version}.tar.gz" .
112+
cd ..
113+
fi
114+
done
115+
116+
- name: Generate release notes
117+
run: |
118+
new_tag="${{ needs.check-and-release.outputs.new_tag }}"
119+
# Remove 'v' prefix for parsing
120+
version_num="${new_tag#v}"
121+
year=$(echo "$version_num" | cut -d'.' -f1)
122+
month=$(echo "$version_num" | cut -d'.' -f2)
123+
micro=$(echo "$version_num" | sed 's/.*r//')
124+
month_name=$(date -d "${year}-${month}-01" +"%B")
125+
release_date=$(TZ='Asia/Shanghai' date +"%B %-d, %Y")
126+
127+
cat > RELEASE_NOTES.md << EOF
128+
Release ${new_tag} is the ${micro}th release in ${month_name} ${year}, released on ${release_date}.
129+
130+
## Artifacts
131+
The release includes pre-compiled difftest shared objects for different Ubuntu versions:
132+
- \`difftest-so-${new_tag}-ubuntu-20.04.tar.gz\`: Compiled on Ubuntu 20.04, good for CentOS 7.
133+
- \`difftest-so-${new_tag}-ubuntu-22.04.tar.gz\`: Compiled on Ubuntu 22.04
134+
- \`difftest-so-${new_tag}-ubuntu-24.04.tar.gz\`: Compiled on Ubuntu 24.04
135+
EOF
136+
137+
- name: Create Release
138+
uses: softprops/action-gh-release@v2
139+
with:
140+
tag_name: ${{ needs.check-and-release.outputs.new_tag }}
141+
name: Release ${{ needs.check-and-release.outputs.new_tag }}
142+
body_path: RELEASE_NOTES.md
143+
draft: false
144+
prerelease: false
145+
generate_release_notes: true
146+
files: |
147+
release-files/*.tar.gz
148+
env:
149+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
!Dockerfile
1111
!README.md
1212
!Kconfig
13-
!.github/workflows/ci.yml
13+
!.github/workflows/*.yml
1414
!scripts/*.sh
1515
!scripts/checkpoint_example/*
1616
include/config

0 commit comments

Comments
 (0)