Skip to content

Commit 099bf14

Browse files
committed
Updated the release yaml and now have a script to validate the input against the current project version
1 parent a15b6a5 commit 099bf14

File tree

5 files changed

+141
-12
lines changed

5 files changed

+141
-12
lines changed

.github/data/release_body.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Libdbc release
2+
3+
### Developer Notes
4+
5+
**TODO: Update this!**
6+
7+
## Breaking Changes
8+
9+
* <Insert-Change>
10+
11+
## Features
12+
13+
* <Insert-Change>
14+
15+
## Bugs
16+
17+
* <Insert-Change>
18+
19+

.github/workflows/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Libdbc Pipeline
22

3-
on: [push]
3+
on: [push, workflow_call]
44

55
env:
66
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)

.github/workflows/release.yml

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,80 @@ on:
55
inputs:
66
major:
77
required: true
8-
type: string
8+
description: "The major version"
9+
type: number
910
minor:
1011
required: true
11-
type: string
12+
description: "The minor version"
13+
type: number
1214
patch:
1315
required: true
14-
type: string
16+
description: "The patch version"
17+
type: number
18+
19+
release_type:
20+
type: choice
21+
description: "The type of release you are making. Controls branch naming / creation"
22+
options:
23+
- patch
24+
- minor
25+
- major
1526

1627
jobs:
28+
check_version:
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: "Validate version in cmake before continuing"
35+
run: ./scripts/check_version.py --version "v${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}"
36+
37+
pipeline:
38+
runs-on: ubuntu-latest
39+
needs: [check_version]
40+
uses: ./.github/workflows/pipeline.yml
41+
1742
create_release:
1843
runs-on: ubuntu-latest
44+
needs: [pipeline]
45+
46+
env:
47+
header_file_path: build/single_header/libdbc/libdbc.hpp
48+
1949
steps:
20-
- name: "Checkout the code"
21-
uses: actions/checkout@v3
50+
- uses: actions/checkout@v4
51+
52+
- name: "Setup Cargo"
53+
run: |
54+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
55+
source "$HOME/.cargo/env"
56+
57+
- name: "Generate the header only library"
58+
run: ./scripts/create_single_header.sh
59+
60+
- uses: actions/upload-artifact@v4
61+
with:
62+
if-no-files-found: error
63+
name: header-only
64+
path: ${{ env.header_file_path }}
65+
66+
- name: "Create a branch if we are making a major / minor release"
67+
uses: peterjgrainger/[email protected]
68+
if: ${{ inputs.major }} || ${{ inputs.minor }}
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
with:
72+
branch: 'release/v${{ inputs.major }}.${{ inputs.minor }}'
73+
sha: '${{ github.sha }}'
2274

23-
- name: "Run tests as a pre check"
24-
uses: .github/workflows/tests.yml
75+
- uses: ncipollo/release-action@v1
76+
with:
77+
artifacts: "${{ env.header_file_path }}"
78+
draft: true
79+
bodyFile: ".github/workflows/release_body.md"
80+
tag: v${{ inputs.major }}.${{ inputs.minor }}.${{ inputs.patch }}
81+
commit: release/v${{ inputs.major }}.${{ inputs.minor }}
2582

2683

2784

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

3-
project(dbc
4-
VERSION 0.2.0
5-
DESCRIPTION "C++ DBC Parser"
6-
)
3+
# Keep this on one line for release checking
4+
project(dbc VERSION 0.2.0 DESCRIPTION "C++ DBC Parser")
75

86
# -- PROJECT OPTIONS -- #
97
option(DBC_ENABLE_TESTS "Enable Unittests" ON)

scripts/check_version.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
# Used to check the input verion against the input
3+
import re
4+
import argparse
5+
6+
7+
def get_cmake_version(cmake_file):
8+
with open(cmake_file, 'r') as f:
9+
contents = f.read()
10+
match = re.search(r'project\(.*VERSION (\d+)\.(\d+)\.(\d+)', contents)
11+
if match:
12+
major, minor, patch = map(int, match.groups())
13+
return major, minor, patch
14+
return None
15+
16+
17+
def validate_semver(version):
18+
pattern = r'^v(\d+)\.(\d+)\.(\d+)$'
19+
match = re.match(pattern, version)
20+
if match:
21+
return tuple(map(int, match.groups()))
22+
else:
23+
return None
24+
25+
26+
def compare_versions(input_version, cmake_version):
27+
if input_version > cmake_version:
28+
print("Input version is greater than CMake version.")
29+
exit(1)
30+
elif input_version < cmake_version:
31+
print("Input version is smaller than CMake version.")
32+
exit(1)
33+
else:
34+
print("Input version is equal to CMake version.")
35+
36+
37+
if __name__ == "__main__":
38+
parser = argparse.ArgumentParser(description="Check input version against CMake project version")
39+
parser.add_argument("--version", type=str, help="Input version with a 'v' prefix", required=True)
40+
args = parser.parse_args()
41+
42+
cmake_version = get_cmake_version("CMakeLists.txt")
43+
if cmake_version is None:
44+
print("Failed to retrieve version from CMakeLists.txt.")
45+
exit(1)
46+
else:
47+
input_version = validate_semver(args.version)
48+
if input_version is None:
49+
print("Invalid input version format. Please provide a version in the format 'vX.Y.Z'")
50+
exit(1)
51+
else:
52+
compare_versions(input_version, cmake_version)
53+
54+
55+

0 commit comments

Comments
 (0)