Skip to content

Commit f2700ee

Browse files
committed
Add tag-based release workflow
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 1877e97 commit f2700ee

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: Release tag to publish, for example v0.1.0
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
release:
19+
name: Build and publish release
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
27+
28+
- name: Resolve release version
29+
id: version
30+
run: |
31+
set -eu
32+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
33+
tag="${{ inputs.tag }}"
34+
else
35+
tag="${GITHUB_REF_NAME}"
36+
fi
37+
38+
if ! printf '%s\n' "$tag" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
39+
echo "Release tag must look like vX.Y.Z, got: $tag" >&2
40+
exit 1
41+
fi
42+
43+
version="${tag#v}"
44+
project_version="$(sed -n 's/^(version \([^)]*\)).*/\1/p' dune-project)"
45+
if [ "$project_version" != "$version" ]; then
46+
echo "Tag $tag does not match dune-project version $project_version" >&2
47+
exit 1
48+
fi
49+
50+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
51+
echo "version=$version" >> "$GITHUB_OUTPUT"
52+
53+
- name: Install system dependencies
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install -y libbpf-dev libelf-dev zlib1g-dev pkg-config
57+
58+
- name: Set up OCaml
59+
uses: ocaml/setup-ocaml@v3
60+
with:
61+
ocaml-compiler: 5.2
62+
63+
- name: Install OCaml dependencies
64+
run: opam install . --deps-only --with-test -y
65+
66+
- name: Build and test
67+
run: |
68+
opam exec -- dune build
69+
opam exec -- dune runtest
70+
71+
- name: Build package archive
72+
run: opam exec -- dune build @install
73+
74+
- name: Prepare release artifacts
75+
run: |
76+
set -eu
77+
version="${{ steps.version.outputs.version }}"
78+
staging="kernelscript-$version"
79+
mkdir -p "dist/$staging"
80+
git archive --format=tar --prefix="$staging/" HEAD | tar -x -C dist
81+
cp _build/default/src/main.exe "dist/kernelscript-linux-x86_64"
82+
tar -C dist -czf "dist/$staging-source.tar.gz" "$staging"
83+
(cd dist && sha256sum "$staging-source.tar.gz" kernelscript-linux-x86_64 > "SHA256SUMS")
84+
85+
- name: Publish GitHub Release
86+
env:
87+
GH_TOKEN: ${{ github.token }}
88+
run: |
89+
tag="${{ steps.version.outputs.tag }}"
90+
version="${{ steps.version.outputs.version }}"
91+
gh release create "$tag" \
92+
--title "KernelScript $version" \
93+
--generate-notes \
94+
"dist/kernelscript-$version-source.tar.gz" \
95+
"dist/kernelscript-linux-x86_64" \
96+
"dist/SHA256SUMS"

0 commit comments

Comments
 (0)