Skip to content

Commit 1e29f7c

Browse files
ci: adjust output, retry tests on failure, include hashes in release notes (#1520)
* scripts/reproduce-builds: rename with prefix and adjust output * ci: rerun tests and include hashes in release * ci: fix variables and really skip 8.10.7 * ci: fix prepare step * ci: setup swap for 8.10.7 * ci: fix upload and formatting * ci: properly format hashes * ci: simplify --------- Co-authored-by: shum <shum@liber.li>
1 parent d11be15 commit 1e29f7c

3 files changed

Lines changed: 177 additions & 43 deletions

File tree

.github/actions/swap/action.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Set Swap Space'
2+
description: 'Add moar swap'
3+
branding:
4+
icon: 'crop'
5+
color: 'orange'
6+
inputs:
7+
swap-size-gb:
8+
description: 'Swap space to create, in Gigabytes.'
9+
required: false
10+
default: '10'
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Swap space report before modification
15+
shell: bash
16+
run: |
17+
echo "Memory and swap:"
18+
free -h
19+
echo
20+
swapon --show
21+
echo
22+
- name: Set Swap
23+
shell: bash
24+
run: |
25+
export SWAP_FILE=$(swapon --show=NAME | tail -n 1)
26+
echo "Swap file: $SWAP_FILE"
27+
if [ -z "$SWAP_FILE" ]; then
28+
SWAP_FILE=/opt/swapfile
29+
else
30+
sudo swapoff $SWAP_FILE
31+
sudo rm $SWAP_FILE
32+
fi
33+
sudo fallocate -l ${{ inputs.swap-size-gb }}G $SWAP_FILE
34+
sudo chmod 600 $SWAP_FILE
35+
sudo mkswap $SWAP_FILE
36+
sudo swapon $SWAP_FILE
37+
- name: Swap space report after modification
38+
shell: bash
39+
run: |
40+
echo "Memory and swap:"
41+
free -h
42+
echo
43+
swapon --show
44+
echo

.github/workflows/build.yml

Lines changed: 121 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,56 @@ on:
1010
pull_request:
1111

1212
jobs:
13+
14+
# =============================
15+
# Create release
16+
# =============================
17+
18+
# Create release, but only if it's triggered by tag push.
19+
# On pull requests/commits push, this job will always complete.
20+
21+
maybe-release:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Clone project
25+
if: startsWith(github.ref, 'refs/tags/v')
26+
uses: actions/checkout@v3
27+
28+
- name: Build changelog
29+
id: build_changelog
30+
if: startsWith(github.ref, 'refs/tags/v')
31+
uses: simplex-chat/release-changelog-builder-action@v5
32+
with:
33+
configuration: .github/changelog_conf.json
34+
failOnError: true
35+
ignorePreReleases: true
36+
commitMode: true
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Create release
41+
if: startsWith(github.ref, 'refs/tags/v')
42+
uses: simplex-chat/action-gh-release@v2
43+
with:
44+
body: |
45+
See full changelog [here](https://github.com/simplex-chat/simplexmq/blob/master/CHANGELOG.md).
46+
47+
Commits:
48+
${{ steps.build_changelog.outputs.changelog }}
49+
prerelease: true
50+
files: |
51+
LICENSE
52+
fail_on_unmatched_files: true
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
# =============================
57+
# Main build job
58+
# =============================
59+
1360
build:
14-
name: "Ubuntu: ${{ matrix.os }}, GHC: ${{ matrix.ghc }}"
61+
name: "ubuntu-${{ matrix.os }}, GHC: ${{ matrix.ghc }}"
62+
needs: maybe-release
1563
env:
1664
apps: "smp-server xftp-server ntf-server xftp"
1765
runs-on: ubuntu-${{ matrix.os }}
@@ -35,21 +83,32 @@ jobs:
3583
- os: 22.04
3684
ghc: "8.10.7"
3785
platform_name: 22_04-8.10.7
86+
should_run: ${{ !(github.ref == 'refs/heads/stable' || startsWith(github.ref, 'refs/tags/v')) }}
3887
- os: 22.04
3988
ghc: "9.6.3"
4089
platform_name: 22_04-x86-64
90+
should_run: true
4191
- os: 24.04
4292
ghc: "9.6.3"
4393
platform_name: 24_04-x86-64
94+
should_run: true
4495
steps:
4596
- name: Clone project
97+
if: matrix.should_run == true
4698
uses: actions/checkout@v3
4799

48100
- name: Set up Docker Buildx
101+
if: matrix.should_run == true
49102
uses: simplex-chat/docker-setup-buildx-action@v3
50103

104+
- name: Setup swap
105+
if: matrix.ghc == '8.10.7' && matrix.should_run == true
106+
uses: ./.github/actions/swap
107+
with:
108+
swap-size-gb: 20
109+
51110
- name: Install PostgreSQL 15 client tools
52-
if: matrix.os == '22.04'
111+
if: matrix.os == '22.04' && matrix.should_run == true
53112
shell: bash
54113
run: |
55114
# Import the repository signing key
@@ -62,6 +121,7 @@ jobs:
62121
sudo apt -y install postgresql-client-15
63122
64123
- name: Build and cache Docker image
124+
if: matrix.should_run == true
65125
uses: simplex-chat/docker-build-push-action@v6
66126
with:
67127
context: .
@@ -77,6 +137,7 @@ jobs:
77137
GHC=${{ matrix.ghc }}
78138
79139
- name: Cache dependencies
140+
if: matrix.should_run == true
80141
uses: actions/cache@v4
81142
with:
82143
path: |
@@ -85,6 +146,7 @@ jobs:
85146
key: ${{ matrix.os }}-${{ hashFiles('cabal.project', 'simplexmq.cabal') }}
86147

87148
- name: Start container
149+
if: matrix.should_run == true
88150
shell: bash
89151
run: |
90152
docker run -t -d \
@@ -95,6 +157,7 @@ jobs:
95157
build/${{ matrix.platform_name }}:latest
96158
97159
- name: Build smp-server (postgresql) and tests
160+
if: matrix.should_run == true
98161
shell: docker exec -t builder sh -eu {0}
99162
run: |
100163
cabal update
@@ -108,17 +171,27 @@ jobs:
108171
strip /out/smp-server
109172
110173
- name: Copy simplexmq-test from container
174+
if: matrix.should_run == true
111175
shell: bash
112176
run: |
113177
docker cp builder:/out/simplexmq-test .
114178
115179
- name: Copy smp-server (postgresql) from container and prepare it
116-
if: startsWith(github.ref, 'refs/tags/v')
180+
if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true
181+
id: prepare-postgres
117182
shell: bash
118183
run: |
119-
docker cp builder:/out/smp-server ./smp-server-postgres-ubuntu-${{ matrix.platform_name }}
184+
name="smp-server-postgres-ubuntu-${{ matrix.platform_name }}"
185+
docker cp builder:/out/smp-server $name
186+
187+
path="${{ github.workspace }}/$name"
188+
echo "bin=$path" >> $GITHUB_OUTPUT
189+
190+
hash="SHA2-256($name)= $(openssl sha256 $path | cut -d' ' -f 2)"
191+
printf 'hash=%s' "$hash" >> $GITHUB_OUTPUT
120192
121193
- name: Build everything else (standard)
194+
if: matrix.should_run == true
122195
shell: docker exec -t builder sh -eu {0}
123196
run: |
124197
cabal build --jobs=$(nproc)
@@ -131,48 +204,64 @@ jobs:
131204
done
132205
133206
- name: Copy binaries from container and prepare them
134-
if: startsWith(github.ref, 'refs/tags/v')
207+
id: prepare-regular
208+
if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true
135209
shell: bash
136210
run: |
137211
docker cp builder:/out .
138-
for i in ${{ env.apps }}; do mv ./out/$i ./$i-ubuntu-${{ matrix.platform_name }}; done
139212
140-
- name: Build changelog
141-
if: startsWith(github.ref, 'refs/tags/v')
142-
id: build_changelog
143-
uses: simplex-chat/release-changelog-builder-action@v5
144-
with:
145-
configuration: .github/changelog_conf.json
146-
failOnError: true
147-
ignorePreReleases: true
148-
commitMode: true
149-
env:
150-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
213+
printf 'bins<<EOF\n' > bins.output
214+
printf 'hashes<<EOF\n' > hashes.output
215+
for i in ${{ env.apps }}; do
216+
mv ./out/$i ./$i-ubuntu-${{ matrix.platform_name }}
151217
152-
- name: Create release
153-
if: startsWith(github.ref, 'refs/tags/v') && matrix.ghc != '8.10.7'
218+
name="$i-ubuntu-${{ matrix.platform_name }}"
219+
220+
path="${{ github.workspace }}/$name"
221+
hash="SHA2-256($name)= $(openssl sha256 $path | cut -d' ' -f 2)"
222+
223+
printf '%s\n' "$path" >> bins.output
224+
printf '%s\n\n' "$hash" >> hashes.output
225+
done
226+
printf 'EOF\n' >> bins.output
227+
printf 'EOF\n' >> hashes.output
228+
229+
cat bins.output >> "$GITHUB_OUTPUT"
230+
cat hashes.output >> "$GITHUB_OUTPUT"
231+
232+
- name: Upload binaries
233+
if: startsWith(github.ref, 'refs/tags/v') && matrix.should_run == true
154234
uses: simplex-chat/action-gh-release@v2
155235
with:
156-
body: |
157-
See full changelog [here](https://github.com/simplex-chat/simplexmq/blob/master/CHANGELOG.md).
158-
159-
Commits:
160-
${{ steps.build_changelog.outputs.changelog }}
236+
append_body: true
161237
prerelease: true
162-
files: |
163-
LICENSE
164-
smp-server-ubuntu-${{ matrix.platform_name }}
165-
smp-server-postgres-ubuntu-${{ matrix.platform_name }}
166-
ntf-server-ubuntu-${{ matrix.platform_name }}
167-
xftp-server-ubuntu-${{ matrix.platform_name }}
168-
xftp-ubuntu-${{ matrix.platform_name }}
169238
fail_on_unmatched_files: true
239+
body: |
240+
${{ steps.prepare-regular.outputs.hashes }}
241+
${{ steps.prepare-postgres.outputs.hash }}
242+
files: |
243+
${{ steps.prepare-regular.outputs.bins }}
244+
${{ steps.prepare-postgres.outputs.bin }}
170245
env:
171246
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
172247

173248
- name: Test
249+
if: matrix.should_run == true
174250
shell: bash
175251
env:
176252
PGHOST: localhost
177253
run: |
178-
./simplexmq-test
254+
i=1
255+
while [ "$i" -le 10 ]; do
256+
if ./simplexmq-test; then
257+
break
258+
else
259+
echo "Attempt $i failed, retrying..."
260+
i=$((i + 1))
261+
sleep 1
262+
fi
263+
done
264+
if [ "$i" -gt 10 ]; then
265+
echo "All 10 attempts failed."
266+
exit 1
267+
fi
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ TAG="$1"
66
tempdir="$(mktemp -d)"
77
init_dir="$PWD"
88

9-
repo="https://github.com/simplex-chat/simplexmq"
9+
repo_name="simplexmq"
10+
repo="https://github.com/simplex-chat/${repo_name}"
1011
export DOCKER_BUILDKIT=1
1112

1213
cleanup() {
@@ -18,10 +19,10 @@ cleanup() {
1819
}
1920
trap 'cleanup' EXIT INT
2021

21-
mkdir -p "$init_dir/$TAG/from-source" "$init_dir/$TAG/prebuilt"
22+
mkdir -p "$init_dir/$TAG-$repo_name/from-source" "$init_dir/$TAG-$repo_name/prebuilt"
2223

2324
git -C "$tempdir" clone "$repo.git" &&\
24-
cd "$tempdir/simplexmq" &&\
25+
cd "$tempdir/${repo_name}" &&\
2526
git checkout "$TAG"
2627

2728
for os in 22.04 24.04; do
@@ -39,7 +40,7 @@ for os in 22.04 24.04; do
3940
# Run container in background
4041
docker run -t -d \
4142
--name builder \
42-
-v "$tempdir/simplexmq:/project" \
43+
-v "$tempdir/${repo_name}:/project" \
4344
local
4445

4546
# PostgreSQL build (only smp-server)
@@ -51,11 +52,11 @@ for os in 22.04 24.04; do
5152
# Copy smp-server postgresql binary and prepare it
5253
docker cp \
5354
builder:/out/smp-server \
54-
"$init_dir/$TAG/from-source/smp-server-postgres-ubuntu-${os_url}-x86-64"
55+
"$init_dir/$TAG-$repo_name/from-source/smp-server-postgres-ubuntu-${os_url}-x86-64"
5556

5657
# Download prebuilt postgresql binary
5758
curl -L \
58-
--output-dir "$init_dir/$TAG/prebuilt/" \
59+
--output-dir "$init_dir/$TAG-$repo_name/prebuilt/" \
5960
-O \
6061
"$repo/releases/download/${TAG}/smp-server-postgres-ubuntu-${os_url}-x86-64"
6162

@@ -76,11 +77,11 @@ for os in 22.04 24.04; do
7677
# Prepare regular binaries and download the prebuilt ones
7778
for app in $apps; do
7879
curl -L \
79-
--output-dir "$init_dir/$TAG/prebuilt/" \
80+
--output-dir "$init_dir/$TAG-$repo_name/prebuilt/" \
8081
-O \
8182
"$repo/releases/download/${TAG}/${app}-ubuntu-${os_url}-x86-64"
8283

83-
mv "./out-${os}/$app" "$init_dir/$TAG/from-source/${app}-ubuntu-${os_url}-x86-64"
84+
mv "./out-${os}/$app" "$init_dir/$TAG-$repo_name/from-source/${app}-ubuntu-${os_url}-x86-64"
8485
done
8586

8687
# Important! Remove dist-newstyle for the next interation
@@ -105,7 +106,7 @@ cd "$init_dir"
105106
# Final stage: compare hashes
106107

107108
# Path to binaries
108-
path_bin="$init_dir/$TAG"
109+
path_bin="$init_dir/$TAG-$repo_name"
109110

110111
# Assume everything is okay for now
111112
bad=0
@@ -122,7 +123,7 @@ for file in "$path_bin"/from-source/*; do
122123

123124
# Compare
124125
if [ "$compiled" != "$prebuilt" ]; then
125-
# If hashes doesn't match, sed bad...
126+
# If hashes doesn't match, set bad...
126127
bad=1
127128

128129
# ... and print affected binary
@@ -132,7 +133,7 @@ done
132133

133134
# If everything is still okay, compute checksums file
134135
if [ "$bad" = 0 ]; then
135-
sha256sum "$path_bin"/from-source/* | sed -e "s|$PWD/||g" -e 's|from-source/||g' > "$path_bin/_sha256sums"
136+
sha256sum "$path_bin"/from-source/* | sed -e "s|$PWD/||g" -e 's|from-source/||g' -e "s|-$repo_name||g" > "$path_bin/_sha256sums"
136137

137138
printf 'Checksums computed - %s\n' "$path_bin/_sha256sums"
138139
fi

0 commit comments

Comments
 (0)