Skip to content

Commit c7e2a22

Browse files
committed
[cicd_cmake_multi_platform.yml] archive & release only on git tag
and if build type is Release, add package_src to the release minor: submodules: 'recursive' cmake working-directory generate_release_notes: true rm: commented out cache
1 parent 3e6b2f0 commit c7e2a22

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

.github/workflows/cicd_cmake_multi_platform.yml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## CMake CI/CD on multiple platforms. AUTHOR: WANDEX
22
## project: build, test, deploy
33
name: CI/CD cmake-multi-platform
4+
permissions:
5+
contents: write ## for the action release
46

57
defaults:
68
run:
@@ -83,6 +85,8 @@ jobs:
8385
steps:
8486
## https://github.com/marketplace/actions/checkout
8587
- uses: actions/checkout@v4
88+
with:
89+
submodules: 'recursive'
8690

8791
## Turn repeated input strings (such as the build output directory) into step outputs.
8892
## These step outputs can be used throughout the workflow file as regular variables.
@@ -151,6 +155,7 @@ jobs:
151155
working-directory: ${{ steps.str3.outputs.dir_path_env }}
152156
run : |
153157
env > post.txt && cat post.txt
158+
# env > post.txt && diff bef.txt post.txt > env.diff && cat env.diff
154159
# env > post.txt && diff -u bef.txt post.txt > env.diff && cat env.diff
155160
# TODO: must find a convenient cross-platform way to install diffutils.
156161

@@ -163,10 +168,9 @@ jobs:
163168
run : cmake -G >cmake_pl_generators.txt 2>&1 || true && cat cmake_pl_generators.txt
164169

165170
- name: Configure CMake
171+
working-directory: ${{ steps.str2.outputs.dir_path_build }}
166172
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
170174
-D CMAKE_INSTALL_PREFIX=${{ steps.str3.outputs.dir_path_deploy }}
171175
-D CMAKE_CXX_COMPILER=${{ matrix.cxx }}
172176
-D CMAKE_C_COMPILER=${{ matrix.cc }}
@@ -176,14 +180,16 @@ jobs:
176180
177181
## Build program with the given configuration. Note that --config is needed for multi-config generator.
178182
- 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
180185

181186
- name: Test
182187
working-directory: ${{ steps.str2.outputs.dir_path_build }}
183188
run: ctest --build-config ${{ matrix.bt }} --output-on-failure
184189

185190
- 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
187193

188194
- name: Deploy ${{ steps.strip.outputs.__strip }}
189195
working-directory: ${{ steps.str2.outputs.dir_path_build }}
@@ -215,25 +221,37 @@ jobs:
215221
compression-level: 6
216222
overwrite: true ## optional, default is false
217223

218-
# - name: Cache
219-
# uses: actions/[email protected]
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 }}
237255
238256
## END steps
239257
## END multi-build-test-deploy

0 commit comments

Comments
 (0)