1010 pull_request :
1111
1212jobs :
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
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 : .
77137 GHC=${{ matrix.ghc }}
78138
79139 - name : Cache dependencies
140+ if : matrix.should_run == true
80141 uses : actions/cache@v4
81142 with :
82143 path : |
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 \
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
0 commit comments