1
1
# # CMake CI/CD on multiple platforms. AUTHOR: WANDEX
2
2
# # project: build, test, deploy
3
3
name : CI/CD cmake-multi-platform
4
+ permissions :
5
+ contents : write # # for the action release
4
6
5
7
defaults :
6
8
run :
83
85
steps :
84
86
# # https://github.com/marketplace/actions/checkout
85
87
- uses : actions/checkout@v4
88
+ with :
89
+ submodules : ' recursive'
86
90
87
91
# # Turn repeated input strings (such as the build output directory) into step outputs.
88
92
# # These step outputs can be used throughout the workflow file as regular variables.
@@ -151,6 +155,7 @@ jobs:
151
155
working-directory : ${{ steps.str3.outputs.dir_path_env }}
152
156
run : |
153
157
env > post.txt && cat post.txt
158
+ # env > post.txt && diff bef.txt post.txt > env.diff && cat env.diff
154
159
# env > post.txt && diff -u bef.txt post.txt > env.diff && cat env.diff
155
160
# TODO: must find a convenient cross-platform way to install diffutils.
156
161
@@ -163,10 +168,9 @@ jobs:
163
168
run : cmake -G >cmake_pl_generators.txt 2>&1 || true && cat cmake_pl_generators.txt
164
169
165
170
- name : Configure CMake
171
+ working-directory : ${{ steps.str2.outputs.dir_path_build }}
166
172
run : >
167
- cmake -G ${{ matrix.gen }} --log-level=DEBUG
168
- -S "${{ steps.str1.outputs.dir_path_prj }}"
169
- -B "${{ steps.str2.outputs.dir_path_build }}"
173
+ cmake -S .. -B . -G ${{ matrix.gen }} --log-level=DEBUG
170
174
-D CMAKE_INSTALL_PREFIX=${{ steps.str3.outputs.dir_path_deploy }}
171
175
-D CMAKE_CXX_COMPILER=${{ matrix.cxx }}
172
176
-D CMAKE_C_COMPILER=${{ matrix.cc }}
@@ -176,14 +180,16 @@ jobs:
176
180
177
181
# # Build program with the given configuration. Note that --config is needed for multi-config generator.
178
182
- name : Build
179
- run : cmake --build "${{ steps.str2.outputs.dir_path_build }}" --config ${{ matrix.bt }} --verbose
183
+ working-directory : ${{ steps.str2.outputs.dir_path_build }}
184
+ run : cmake --build . --config ${{ matrix.bt }} --verbose
180
185
181
186
- name : Test
182
187
working-directory : ${{ steps.str2.outputs.dir_path_build }}
183
188
run : ctest --build-config ${{ matrix.bt }} --output-on-failure
184
189
185
190
- name : Package source code
186
- run : cmake --build "${{ steps.str2.outputs.dir_path_build }}" --target src_package --config ${{ matrix.bt }}
191
+ working-directory : ${{ steps.str2.outputs.dir_path_build }}
192
+ run : cmake --build . --config ${{ matrix.bt }} --target package_src
187
193
188
194
- name : Deploy ${{ steps.strip.outputs.__strip }}
189
195
working-directory : ${{ steps.str2.outputs.dir_path_build }}
@@ -215,25 +221,37 @@ jobs:
215
221
compression-level : 6
216
222
overwrite : true # # optional, default is false
217
223
218
- # - name: Cache
219
-
220
- # with:
221
- # ## A list of files, directories, and wildcard patterns to cache and restore
222
- # path:
223
- # ## An explicit key for restoring and saving the cache
224
- # key:
225
- # ## An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.
226
- # restore-keys: ## optional
227
- # ## The chunk size used to split up large files during upload, in bytes
228
- # upload-chunk-size: ## optional
229
- # ## An optional boolean when enabled, allows windows runners to save or restore caches that can be restored or saved respectively on other platforms
230
- # enableCrossOsArchive: ## optional, default is false
231
- # ## Fail the workflow if cache entry is not found
232
- # fail-on-cache-miss: ## optional, default is false
233
- # ## Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache
234
- # lookup-only: ## optional, default is false
235
- # ## Run the post step to save the cache even if another step before fails
236
- # save-always: ## optional, default is false
224
+ - name : archive
225
+ id : archive
226
+ shell : bash
227
+ if : ${{ github.ref_type == 'tag' && matrix.bt == 'Release' }}
228
+ working-directory : ${{ steps.str2.outputs.dir_path_build }}
229
+ run : |
230
+ PRJNAME=${{ env.PRJ_NAME }}
231
+ VERSION=$GITHUB_REF_NAME
232
+ ARCH=$(uname -m)
233
+ PRJVERA=$PRJNAME-$VERSION-$ARCH
234
+ PKGNAME=$PRJVERA-${{ matrix.bp }}
235
+ TARBALL=$PKGNAME.tar.gz
236
+ SHASUM=$PKGNAME.tar.gz.sha256
237
+ cp -r deploy $PRJVERA
238
+ tar -czf $TARBALL $PRJVERA
239
+ cmake -E sha256sum $TARBALL > $SHASUM
240
+ echo "TARBALL=$TARBALL" >> $GITHUB_OUTPUT
241
+ echo "SHASUM=$SHASUM" >> $GITHUB_OUTPUT
242
+
243
+ # # https://github.com/marketplace/actions/gh-release
244
+ - name : release
245
+ uses : softprops/action-gh-release@v2
246
+ if : ${{ github.ref_type == 'tag' && matrix.bt == 'Release' }}
247
+ with :
248
+ generate_release_notes : true
249
+ draft : true
250
+ token : ${{ secrets.GITHUB_TOKEN }}
251
+ files : |
252
+ ${{ steps.str2.outputs.dir_path_build }}/${{ env.PRJ_NAME }}-*-src.tar.gz
253
+ ${{ steps.str2.outputs.dir_path_build }}/${{ steps.archive.outputs.TARBALL }}
254
+ ${{ steps.str2.outputs.dir_path_build }}/${{ steps.archive.outputs.SHASUM }}
237
255
238
256
# # END steps
239
257
# # END multi-build-test-deploy
0 commit comments