Skip to content

Commit 5a91e1f

Browse files
committed
Merge branch '19-fix-publish-step' into release
2 parents 51d1193 + dfb0b84 commit 5a91e1f

2 files changed

Lines changed: 75 additions & 7 deletions

File tree

.github/workflows/package.yml

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ jobs:
4949
with:
5050
fetch-depth: 0
5151

52+
- name: Resolve version from tag
53+
shell: bash
54+
run: |
55+
ref="${GITHUB_REF_NAME}"
56+
echo "H5CPP_VERSION=${ref#v}" >> "$GITHUB_ENV"
57+
5258
- name: Install LLVM toolchain (Linux)
5359
if: runner.os == 'Linux'
5460
shell: bash
@@ -156,7 +162,8 @@ jobs:
156162
-DCMAKE_BUILD_TYPE=Release \
157163
-DLLVM_DIR="$LLVM_DIR" \
158164
-DClang_DIR="$Clang_DIR" \
159-
-DH5CPP_STATIC_LINK_LLVM=ON
165+
-DH5CPP_STATIC_LINK_LLVM=ON \
166+
-DH5CPP_VERSION_OVERRIDE="${H5CPP_VERSION:-}"
160167
161168
- name: Configure (Windows)
162169
if: runner.os == 'Windows'
@@ -167,7 +174,8 @@ jobs:
167174
-DCMAKE_BUILD_TYPE=Release `
168175
-DLLVM_DIR="$env:LLVM_DIR" `
169176
-DClang_DIR="$env:Clang_DIR" `
170-
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
177+
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded `
178+
-DH5CPP_VERSION_OVERRIDE="$env:H5CPP_VERSION"
171179
172180
- name: Build
173181
shell: bash
@@ -187,7 +195,12 @@ jobs:
187195
uses: actions/upload-artifact@v4
188196
with:
189197
name: h5cpp-compiler-${{ matrix.os }}-${{ matrix.format }}
190-
path: build/h5cpp-compiler-*
198+
if-no-files-found: error
199+
path: |
200+
build/h5cpp-compiler-*.deb
201+
build/h5cpp-compiler-*.rpm
202+
build/h5cpp-compiler-*.exe
203+
build/h5cpp-compiler-*.pkg
191204
192205
publish:
193206
name: Publish Release
@@ -208,10 +221,51 @@ jobs:
208221
- name: Create Release and upload assets
209222
shell: bash
210223
run: |
211-
set -euxo pipefail
224+
set -euo pipefail
212225
tag="${GITHUB_REF_NAME}"
213-
gh release create "$tag" --generate-notes || true
214-
find artifacts -type f -name "h5cpp-compiler-*" -print0 | \
215-
xargs -0 gh release upload "$tag" --clobber
226+
227+
# Ensure release exists. Idempotent: create only if missing,
228+
# so a re-run of the workflow against the same tag does not 422.
229+
if ! gh release view "$tag" >/dev/null 2>&1; then
230+
gh release create "$tag" \
231+
--title "h5cpp-compiler-${tag}" \
232+
--generate-notes
233+
fi
234+
235+
# Collect installer artifacts only. Defensive against stray
236+
# CMake-generated files (e.g. h5cpp-compiler-dev.sln on Windows).
237+
shopt -s globstar nullglob
238+
files=( artifacts/**/*.deb artifacts/**/*.rpm artifacts/**/*.exe artifacts/**/*.pkg )
239+
if (( ${#files[@]} == 0 )); then
240+
echo "no installer artifacts found under artifacts/" >&2
241+
exit 1
242+
fi
243+
244+
# Upload each file with bounded retries. uploads.github.com is
245+
# eventually consistent right after release creation and
246+
# occasionally 404s on first POST.
247+
failed=()
248+
for f in "${files[@]}"; do
249+
[[ -f "$f" ]] || continue
250+
echo "::group::upload $(basename "$f")"
251+
ok=0
252+
for attempt in 1 2 3 4 5; do
253+
if gh release upload "$tag" "$f" --clobber; then
254+
ok=1
255+
break
256+
fi
257+
backoff=$(( attempt * attempt * 2 ))
258+
echo "attempt ${attempt} failed; retrying in ${backoff}s"
259+
sleep "${backoff}"
260+
done
261+
echo "::endgroup::"
262+
(( ok == 1 )) || failed+=( "$f" )
263+
done
264+
265+
if (( ${#failed[@]} > 0 )); then
266+
echo "Upload failed for:" >&2
267+
printf ' - %s\n' "${failed[@]}" >&2
268+
exit 1
269+
fi
216270
env:
217271
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ set(CPACK_PACKAGE_VENDOR "VargaConsulting")
196196
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
197197
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
198198
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
199+
200+
# CI passes -DH5CPP_VERSION_OVERRIDE=X.Y.Z (derived from the tag) so installer
201+
# filenames track the release tag instead of the frozen project() version.
202+
if(DEFINED H5CPP_VERSION_OVERRIDE AND NOT H5CPP_VERSION_OVERRIDE STREQUAL "")
203+
if(H5CPP_VERSION_OVERRIDE MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
204+
set(CPACK_PACKAGE_VERSION "${H5CPP_VERSION_OVERRIDE}")
205+
set(CPACK_PACKAGE_VERSION_MAJOR "${CMAKE_MATCH_1}")
206+
set(CPACK_PACKAGE_VERSION_MINOR "${CMAKE_MATCH_2}")
207+
set(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_MATCH_3}")
208+
else()
209+
message(FATAL_ERROR
210+
"H5CPP_VERSION_OVERRIDE='${H5CPP_VERSION_OVERRIDE}' is not X.Y.Z")
211+
endif()
212+
endif()
199213
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Source code transformation tool for HDF5 H5CPP library")
200214
set(CPACK_PACKAGE_CONTACT "steven@vargaconsulting.ca")
201215
set(CPACK_PACKAGE_LICENSE "MIT")

0 commit comments

Comments
 (0)