-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (100 loc) · 4.39 KB
/
release.yml
File metadata and controls
120 lines (100 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: write
jobs:
validate-version:
name: Validate version tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract.outputs.version }}
steps:
- uses: actions/checkout@v6
- name: Extract version from tag
id: extract
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Verify tag matches fallback version.hpp
run: |
header_file="lib/include/ds_mysql/version.hpp"
tag_version="${{ steps.extract.outputs.version }}"
tag_major="${tag_version%%.*}"
tag_rest="${tag_version#*.}"
tag_minor="${tag_rest%%.*}"
tag_patch="${tag_rest##*.}"
header_major=$(grep -oP 'static constexpr std::uint32_t major = \K\d+' "$header_file")
header_minor=$(grep -oP 'static constexpr std::uint32_t minor = \K\d+' "$header_file")
header_patch=$(grep -oP 'static constexpr std::uint32_t patch = \K\d+' "$header_file")
header_string=$(grep -oP 'static constexpr std::string_view string = "\K[^"]+' "$header_file")
echo "Tag version: $tag_version"
echo "Header version: ${header_major}.${header_minor}.${header_patch}"
echo "Header string: $header_string"
if [ "$header_major" != "$tag_major" ] || [ "$header_minor" != "$tag_minor" ] || [ "$header_patch" != "$tag_patch" ] || [ "$header_string" != "$tag_version" ]; then
echo "::error::Tag version ($tag_version) does not match fallback version.hpp values (${header_major}.${header_minor}.${header_patch}, string=${header_string})"
exit 1
fi
- name: Verify tag matches CMakeLists.txt version
run: |
cmake_version=$(grep -m1 'project(DSMySQL' CMakeLists.txt -A5 \
| grep 'VERSION' \
| grep -oP '\d+\.\d+\.\d+')
tag_version="${{ steps.extract.outputs.version }}"
echo "Tag version: $tag_version"
echo "CMake version: $cmake_version"
if [ "$tag_version" != "$cmake_version" ]; then
echo "::error::Tag version ($tag_version) does not match CMakeLists.txt version ($cmake_version)"
exit 1
fi
ci:
name: CI
needs: validate-version
uses: ./.github/workflows/ci.yml
release:
name: Create GitHub release
needs: [validate-version, ci]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install CMake (for configure_file)
run: |
sudo apt-get update -q
sudo apt-get install -y software-properties-common ca-certificates gpg wget
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc \
| gpg --dearmor \
| sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg > /dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' \
| sudo tee /etc/apt/sources.list.d/kitware.list
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -q
sudo apt-get install -y cmake libmysqlclient-dev pkg-config g++-15 gcc-15
env:
DEBIAN_FRONTEND: noninteractive
- name: Generate version.hpp
run: |
cmake -B _ver_build -DSKIP_DOCKER_MANAGEMENT=ON \
-DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF \
-DBUILD_INTEGRATION_TESTS=OFF
env:
CXX: g++-15
CC: gcc-15
- name: Package headers
id: package
run: |
VERSION="${{ needs.validate-version.outputs.version }}"
ARCHIVE="ds_mysql-v${VERSION}.tar.gz"
# Merge source headers with generated version override header.
mkdir -p _dist/ds_mysql
cp -r lib/include/ds_mysql/. _dist/ds_mysql/
cp _ver_build/lib/include/ds_mysql/version_generated.hpp _dist/ds_mysql/version_generated.hpp
rm -f _dist/ds_mysql/version.hpp.in
tar -czf "$ARCHIVE" -C _dist ds_mysql
echo "archive=$ARCHIVE" >> "$GITHUB_OUTPUT"
- name: Create release
uses: softprops/action-gh-release@v2
with:
name: DSMySQL v${{ needs.validate-version.outputs.version }}
tag_name: ${{ github.ref_name }}
generate_release_notes: true
files: ${{ steps.package.outputs.archive }}