blob: ab87780073a4a94ec5a5b2dd53421fb4d9c65390 (
plain) (
blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
name: release
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
version:
description: "Impact"
required: true
default: 'patch'
type: choice
options:
- minor
- patch
permissions:
contents: write
jobs:
linux:
if: ${{ github.ref_name != 'master' && startsWith(github.ref_name, 'v') && endsWith(github.ref_name, '.x') }}
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: |
set -euxo pipefail
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
ccache \
clang \
clang-tidy \
clang-tools \
libcjson-dev \
libopenblas-dev \
pkg-config \
valgrind
cc --version | sed -n '1,2p'
clang --version | sed -n '1,2p'
clang-tidy --version | sed -n '1,2p'
pkg-config --modversion libcjson 2>/dev/null || true
- name: Cache ccache
uses: actions/cache@v4
with:
path: ~/.cache/ccache
key: ccache-${{ runner.os }}-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
ccache-${{ runner.os }}-${{ github.ref_name }}-
ccache-${{ runner.os }}-
- name: Configure ccache
run: |
set -euxo pipefail
ccache --set-config=cache_dir="$HOME/.cache/ccache"
ccache --set-config=max_size=1G
ccache --zero-stats
- name: Run tests
env:
CC: ccache gcc
run: make test
- name: Compute build version
run: |
set -euxo pipefail
git fetch --all --tags
REF_NAME="${GITHUB_REF_NAME:-}"
MAJOR="$(echo "$REF_NAME" | sed -nE 's/^v([0-9]+)\.x$/\1/p')"
if [[ -z "$MAJOR" ]]; then
echo "Invalid branch name format (expected vX.x)" >&2
exit 1
fi
next_version () {
local current impact minor patch
impact="${1:-patch}"
current="$(
git tag \
| grep "^v${MAJOR}\.[0-9]*\.[0-9]*$" \
| sort -t "." -k1,1nr -k2,2nr -k3,3nr \
| cut -c2- \
| head -1
)" || true
if [[ -z "$current" ]]; then
if [[ "$MAJOR" -eq 0 ]]; then
echo "0.0.1"
else
echo "$MAJOR.0.0"
fi
return
fi
IFS='.' read -r _ minor patch <<< "$current"
case "$impact" in
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
*)
echo "Invalid impact: $impact" >&2
exit 1
;;
esac
echo "$MAJOR.$minor.$patch"
}
BUILD_VERSION="$(next_version "${{ inputs.version }}")"
TAG_NAME="v${BUILD_VERSION}"
echo "BUILD_VERSION=$BUILD_VERSION" >> "$GITHUB_ENV"
echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_ENV"
echo "BUILD_VERSION=$BUILD_VERSION"
echo "TAG_NAME=$TAG_NAME"
- name: Build release artifacts
env:
CC: ccache gcc
run: |
set -euxo pipefail
rm -rf tmp
mkdir -p tmp
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="x86_64" ;;
aarch64) ARCH="aarch64" ;;
*) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
NAME="embed-linux-${ARCH}"
make cpu \
ARCH_FLAGS="-march=x86-64" \
VERSION="$BUILD_VERSION" \
BUILD_COMMIT="$GITHUB_SHA" \
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" \
BUILD_OS="linux" \
BUILD_ARCH="$ARCH"
mkdir -p "tmp/$NAME"
cp embed embed-server LICENSE README.md "tmp/$NAME/"
tar -C tmp -czf "tmp/${NAME}.tar.gz" "$NAME"
cd tmp
sha256sum *.tar.gz > SHA256SUMS
- name: Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euxo pipefail
if [[ -z "${TAG_NAME:-}" ]]; then
echo "No tag name computed; refusing to release" >&2
exit 1
fi
commit="$(git rev-parse HEAD)"
if git tag --points-at "$commit" | grep -q "^${TAG_NAME}$"; then
echo "Commit already has tag $TAG_NAME, skipping release"
exit 0
fi
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Tag $TAG_NAME already exists, refusing to overwrite" >&2
exit 1
fi
git config user.name github-actions
git config user.email github-actions@github.com
git tag "$TAG_NAME"
git push origin "$TAG_NAME"
gh release create "$TAG_NAME" \
tmp/embed-linux-*.tar.gz \
tmp/SHA256SUMS \
--title "$TAG_NAME" \
--generate-notes
- name: Show ccache stats
if: always()
run: ccache --show-stats || true
|