Skip to content

Commit d84a5c3

Browse files
author
Pierre-Luc Gagné
committed
chore: strengthen release workflow and sync fallback versioning
1 parent 55adbb3 commit d84a5c3

7 files changed

Lines changed: 84 additions & 25 deletions

File tree

.github/workflows/release.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ jobs:
2222
id: extract
2323
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
2424

25+
- name: Verify tag matches fallback version.hpp
26+
run: |
27+
header_file="lib/include/ds_mysql/version.hpp"
28+
tag_version="${{ steps.extract.outputs.version }}"
29+
30+
tag_major="${tag_version%%.*}"
31+
tag_rest="${tag_version#*.}"
32+
tag_minor="${tag_rest%%.*}"
33+
tag_patch="${tag_rest##*.}"
34+
35+
header_major=$(grep -oP 'static constexpr std::uint32_t major = \K\d+' "$header_file")
36+
header_minor=$(grep -oP 'static constexpr std::uint32_t minor = \K\d+' "$header_file")
37+
header_patch=$(grep -oP 'static constexpr std::uint32_t patch = \K\d+' "$header_file")
38+
header_string=$(grep -oP 'static constexpr std::string_view string = "\K[^"]+' "$header_file")
39+
40+
echo "Tag version: $tag_version"
41+
echo "Header version: ${header_major}.${header_minor}.${header_patch}"
42+
echo "Header string: $header_string"
43+
44+
if [ "$header_major" != "$tag_major" ] || [ "$header_minor" != "$tag_minor" ] || [ "$header_patch" != "$tag_patch" ] || [ "$header_string" != "$tag_version" ]; then
45+
echo "::error::Tag version ($tag_version) does not match fallback version.hpp values (${header_major}.${header_minor}.${header_patch}, string=${header_string})"
46+
exit 1
47+
fi
48+
2549
- name: Verify tag matches CMakeLists.txt version
2650
run: |
2751
cmake_version=$(grep -m1 'project(DSMySQL' CMakeLists.txt -A5 \
@@ -106,6 +130,7 @@ jobs:
106130
CC: gcc-15
107131

108132
- name: Package headers
133+
id: package
109134
run: |
110135
VERSION="${{ needs.validate-version.outputs.version }}"
111136
ARCHIVE="ds_mysql-v${VERSION}.tar.gz"
@@ -117,12 +142,12 @@ jobs:
117142
rm -f _dist/ds_mysql/version.hpp.in
118143
119144
tar -czf "$ARCHIVE" -C _dist ds_mysql
120-
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
145+
echo "archive=$ARCHIVE" >> "$GITHUB_OUTPUT"
121146
122147
- name: Create release
123148
uses: softprops/action-gh-release@v2
124149
with:
125150
name: DSMySQL v${{ needs.validate-version.outputs.version }}
126151
tag_name: ${{ github.ref_name }}
127152
generate_release_notes: true
128-
files: ${{ env.ARCHIVE }}
153+
files: ${{ steps.package.outputs.archive }}

docs/RELEASE.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ which:
1010

1111
1. Validates that the tag matches the `VERSION` declared in `CMakeLists.txt`.
1212
2. Runs the full unit-test suite (GCC).
13-
3. Generates `version.hpp` from the template.
13+
3. Generates `version_generated.hpp` from the template.
1414
4. Packages the public headers into `ds_mysql-v<version>.tar.gz`.
1515
5. Creates a GitHub Release and attaches the archive.
1616

1717
The easiest way to perform all pre-tag steps in one shot is the helper script:
1818

1919
```bash
20-
./scripts/release/release.sh <new-version> # e.g. ./scripts/release/release.sh 1.1.0
20+
./scripts/release/release.sh <new-version> # e.g. ./scripts/release/release.sh 1.1.0
2121
```
2222

2323
---
@@ -43,8 +43,14 @@ project(DSMySQL
4343
)
4444
```
4545

46-
The version is the single source of truth. `version.hpp` is generated from it
47-
at configure time, so no other file needs editing.
46+
The version is the single source of truth.
47+
48+
If you use `scripts/release/release.sh`, it also updates fallback constants in
49+
`lib/include/ds_mysql/version.hpp` so raw-header/non-CMake consumers see the
50+
new version too.
51+
52+
For a fully manual release, update `lib/include/ds_mysql/version.hpp` major,
53+
minor, patch, and string values to match `<new-version>`.
4854

4955
### 3. Update `CHANGELOG.md`
5056

@@ -64,7 +70,7 @@ Also update the `[Unreleased]` comparison link at the bottom of the file.
6470
### 4. Commit
6571

6672
```bash
67-
git add CMakeLists.txt CHANGELOG.md
73+
git add CMakeLists.txt lib/include/ds_mysql/version.hpp CHANGELOG.md
6874
git commit -m "chore: release v<new-version>"
6975
```
7076

@@ -86,9 +92,9 @@ After the workflow succeeds:
8692
- The GitHub Release page lists the new tag with auto-generated release notes.
8793
- The `ds_mysql-v<version>.tar.gz` archive is attached and contains every public
8894
header under a top-level `ds_mysql/` directory, including the generated
89-
`version.hpp`.
95+
`version_generated.hpp`.
9096
- Confirm `ds_mysql::version::string` matches the new version by inspecting
91-
`version.hpp` inside the archive.
97+
`version_generated.hpp` inside the archive.
9298

9399
---
94100

lib/include/ds_mysql/version.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace ds_mysql {
1616
/// This checked-in fallback is used only when no build-system generated
1717
/// `version_generated.hpp` is present (e.g. raw-header, non-CMake usage).
1818
struct version {
19-
static constexpr std::uint32_t major = 0;
19+
static constexpr std::uint32_t major = 1;
2020
static constexpr std::uint32_t minor = 0;
2121
static constexpr std::uint32_t patch = 0;
2222

2323
/// Packed integer: major * 10000 + minor * 100 + patch.
2424
static constexpr std::uint32_t value = major * 10'000u + minor * 100u + patch;
2525

2626
/// Canonical fallback string for non-generated builds.
27-
static constexpr std::string_view string = "0.0.0+unknown";
27+
static constexpr std::string_view string = "1.0.0";
2828
};
2929

3030
} // namespace ds_mysql
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env bash
2-
# scripts/ci/act-ci-full.sh — run all Linux CI jobs locally with act, sequentially.
2+
# scripts/act/act-ci-full.sh — run all Linux CI jobs locally with act, sequentially.
33
#
44
# Jobs run in order:
55
# 1) tests-gcc
66
# 2) tests-clang
77
# 3) package-consumer-smoke
88
#
99
# Usage:
10-
# bash ./scripts/ci/act-ci-full.sh
11-
# bash ./scripts/ci/act-ci-full.sh --pull=false
10+
# bash ./scripts/act/act-ci-full.sh
11+
# bash ./scripts/act/act-ci-full.sh --pull=false
1212

1313
set -euo pipefail
1414

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
2-
# scripts/ci/act-ci.sh — run CI tests-gcc locally with act using a free MySQL host port.
2+
# scripts/act/act-ci.sh — run CI tests-gcc locally with act using a free MySQL host port.
33
#
44
# Usage:
5-
# bash ./scripts/ci/act-ci.sh
6-
# bash ./scripts/ci/act-ci.sh --pull=false
5+
# bash ./scripts/act/act-ci.sh
6+
# bash ./scripts/act/act-ci.sh --pull=false
77

88
set -euo pipefail
99

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env bash
2-
# scripts/release/act-release.sh — run release workflow locally with act
2+
# scripts/act/act-release.sh — run release workflow locally with act
33
#
44
# Usage:
5-
# ./scripts/release/act-release.sh
5+
# ./scripts/act/act-release.sh
66
#
77
# What it does:
88
# 1. Extracts the current version from CMakeLists.txt.

scripts/release/release.sh

100644100755
Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
2-
# scripts/release/release.sh — bump version, update CHANGELOG, commit, and tag.
2+
# scripts/release/release.sh — bump version, sync fallback header,
3+
# update CHANGELOG, commit, and tag.
34
#
45
# Usage:
56
# ./scripts/release/release.sh <new-version>
@@ -9,10 +10,11 @@
910
# 1. Validates the supplied version string.
1011
# 2. Ensures the working tree is clean and on `main`.
1112
# 3. Updates the VERSION field in CMakeLists.txt.
12-
# 4. Opens CHANGELOG.md in $EDITOR so you can fill in the release notes.
13-
# 5. Commits the two changed files.
14-
# 6. Creates an annotated tag.
15-
# 7. Optionally pushes branch + tag to origin.
13+
# 4. Updates checked-in fallback version constants in version.hpp.
14+
# 5. Opens CHANGELOG.md in $EDITOR so you can fill in the release notes.
15+
# 6. Commits the changed files.
16+
# 7. Creates an annotated tag.
17+
# 8. Optionally pushes branch + tag to origin.
1618

1719
set -euo pipefail
1820

@@ -36,6 +38,7 @@ NEW_VERSION="$1"
3638
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
3739
CMAKE_FILE="$REPO_ROOT/CMakeLists.txt"
3840
CHANGELOG="$REPO_ROOT/CHANGELOG.md"
41+
VERSION_HEADER="$REPO_ROOT/lib/include/ds_mysql/version.hpp"
3942

4043
# ──────────────────────────────────────────────────────────────────────────────
4144
# Git sanity checks
@@ -88,6 +91,31 @@ UPDATED_VERSION="$(grep -oP '(?<=VERSION )\d+\.\d+\.\d+' "$CMAKE_FILE" | head -1
8891
[[ "$UPDATED_VERSION" == "$NEW_VERSION" ]] \
8992
|| die "CMakeLists.txt update failed — expected $NEW_VERSION, got $UPDATED_VERSION"
9093

94+
# ──────────────────────────────────────────────────────────────────────────────
95+
# Sync fallback version in checked-in header
96+
# ──────────────────────────────────────────────────────────────────────────────
97+
98+
IFS='.' read -r NEW_MAJOR NEW_MINOR NEW_PATCH <<< "$NEW_VERSION"
99+
100+
info "Updating fallback version header …"
101+
sed -Ei "s/(static constexpr std::uint32_t major = )[0-9]+;/\\1${NEW_MAJOR};/" \
102+
"$VERSION_HEADER"
103+
sed -Ei "s/(static constexpr std::uint32_t minor = )[0-9]+;/\\1${NEW_MINOR};/" \
104+
"$VERSION_HEADER"
105+
sed -Ei "s/(static constexpr std::uint32_t patch = )[0-9]+;/\\1${NEW_PATCH};/" \
106+
"$VERSION_HEADER"
107+
sed -Ei "s|(static constexpr std::string_view string = )\"[^\"]+\";|\\1\"${NEW_VERSION}\";|" \
108+
"$VERSION_HEADER"
109+
110+
grep -q "static constexpr std::uint32_t major = ${NEW_MAJOR};" "$VERSION_HEADER" \
111+
|| die "Failed to update major in version.hpp"
112+
grep -q "static constexpr std::uint32_t minor = ${NEW_MINOR};" "$VERSION_HEADER" \
113+
|| die "Failed to update minor in version.hpp"
114+
grep -q "static constexpr std::uint32_t patch = ${NEW_PATCH};" "$VERSION_HEADER" \
115+
|| die "Failed to update patch in version.hpp"
116+
grep -q "static constexpr std::string_view string = \"${NEW_VERSION}\";" "$VERSION_HEADER" \
117+
|| die "Failed to update string in version.hpp"
118+
91119
# ──────────────────────────────────────────────────────────────────────────────
92120
# Update CHANGELOG.md
93121
# ──────────────────────────────────────────────────────────────────────────────
@@ -125,7 +153,7 @@ info "Opening CHANGELOG.md in ${EDITOR} …"
125153
# ──────────────────────────────────────────────────────────────────────────────
126154

127155
info "Staging changed files …"
128-
git add "$CMAKE_FILE" "$CHANGELOG"
156+
git add "$CMAKE_FILE" "$VERSION_HEADER" "$CHANGELOG"
129157

130158
git diff --cached --stat
131159

0 commit comments

Comments
 (0)