Skip to content

Commit fbd50e9

Browse files
Merge pull request #19 from chrisgleissner/feature/dynamic-version
Fix release process regression: synchronize dynamic version handling
2 parents 841927a + 9702cf1 commit fbd50e9

File tree

8 files changed

+113
-35
lines changed

8 files changed

+113
-35
lines changed

.github/actions/package-plugin/action.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ inputs:
4444
description: Working directory for packaging
4545
required: false
4646
default: ${{ github.workspace }}
47+
version:
48+
description: Plugin version to use (overrides buildspec.json)
49+
required: false
50+
default: ''
4751
runs:
4852
using: composite
4953
steps:
@@ -57,6 +61,7 @@ runs:
5761
CODESIGN_TEAM: ${{ inputs.codesignTeam }}
5862
CODESIGN_IDENT_USER: ${{ inputs.codesignUser }}
5963
CODESIGN_IDENT_PASS: ${{ inputs.codesignPass }}
64+
PLUGIN_VERSION_OVERRIDE: ${{ inputs.version }}
6065
run: |
6166
: Run macOS Packaging
6267
@@ -83,6 +88,8 @@ runs:
8388
if: runner.os == 'Linux'
8489
shell: zsh --no-rcs --errexit --pipefail {0}
8590
working-directory: ${{ inputs.workingDirectory }}
91+
env:
92+
PLUGIN_VERSION_OVERRIDE: ${{ inputs.version }}
8693
run: |
8794
: Run Ubuntu Packaging
8895
package_args=(
@@ -98,6 +105,8 @@ runs:
98105
- name: Run Windows Packaging
99106
if: runner.os == 'Windows'
100107
shell: pwsh
108+
env:
109+
PLUGIN_VERSION_OVERRIDE: ${{ inputs.version }}
101110
run: |
102111
# Run Windows Packaging
103112
if ( $Env:RUNNER_DEBUG -ne $null ) {

.github/scripts/Package-Windows.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ function Package {
4646
$BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json
4747
$ProductName = $BuildSpec.name
4848
$ProductVersion = $BuildSpec.version
49+
50+
# Use version override if provided (for centralized version management)
51+
if ($env:PLUGIN_VERSION_OVERRIDE) {
52+
$ProductVersion = $env:PLUGIN_VERSION_OVERRIDE
53+
}
4954

5055
$OutputName = "${ProductName}-${ProductVersion}-windows-${Target}"
5156

.github/scripts/package-macos

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ package() {
9696
local product_version
9797
read -r product_name product_version <<< \
9898
"$(jq -r '. | {name, version} | join(" ")' ${buildspec_file})"
99+
100+
# Use version override if provided (for centralized version management)
101+
if [[ -n "${PLUGIN_VERSION_OVERRIDE}" ]]; then
102+
product_version="${PLUGIN_VERSION_OVERRIDE}"
103+
fi
99104
100105
local output_name="${product_name}-${product_version}-${host_os}-universal"
101106

.github/scripts/package-ubuntu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ ${_usage_host:-}"
146146
local product_version
147147
read -r product_name product_version <<< \
148148
"$(jq -r '. | {name, version} | join(" ")' ${buildspec_file})"
149+
150+
# Use version override if provided (for centralized version management)
151+
if [[ -n "${PLUGIN_VERSION_OVERRIDE}" ]]; then
152+
product_version="${PLUGIN_VERSION_OVERRIDE}"
153+
fi
149154
150155
local -a cmake_args=()
151156
if (( _loglevel > 1 )) cmake_args+=(--verbose)

.github/workflows/build-project.yaml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
pluginName:
66
description: Project name detected by parsing build spec file
77
value: ${{ jobs.check-event.outputs.pluginName }}
8+
pluginVersion:
9+
description: Project version detected by parsing build spec file
10+
value: ${{ jobs.check-event.outputs.pluginVersion }}
811
jobs:
912
check-event:
1013
name: Check GitHub Event Data 🔎
@@ -19,6 +22,7 @@ jobs:
1922
config: ${{ steps.setup.outputs.config }}
2023
commitHash: ${{ steps.setup.outputs.commitHash }}
2124
pluginName: ${{ steps.setup.outputs.pluginName }}
25+
pluginVersion: ${{ steps.setup.outputs.pluginVersion }}
2226
steps:
2327
- uses: actions/checkout@v4
2428
with:
@@ -62,14 +66,31 @@ jobs:
6266
done
6367
echo "commitHash=${GITHUB_SHA:0:9}" >> $GITHUB_OUTPUT
6468
65-
plugin_name="$(grep 'name' buildspec.json | sed -E -e 's/^.+"name":[^"]+"(.+)",?$/\1/g')"
66-
plugin_display_name="$(grep 'displayName' buildspec.json | sed -E -e 's/^.+"displayName":[^"]+"(.+)",?$/\1/g' || echo "")"
69+
plugin_name="$(jq -r '.name' buildspec.json)"
70+
plugin_display_name="$(jq -r '.displayName // empty' buildspec.json)"
71+
72+
# For PR builds, calculate the same development version that CMake uses
73+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
74+
# Match CMake logic: MAJOR.MINOR.(9000 + GITHUB_RUN_NUMBER)
75+
base_version="$(jq -r '.version' buildspec.json)"
76+
IFS='.' read -r major minor patch <<< "${base_version}"
77+
if [[ -n "${GITHUB_RUN_NUMBER}" ]]; then
78+
run_mod=$((GITHUB_RUN_NUMBER % 1000)) # Limit to 0-999 range
79+
dev_patch=$((900 + run_mod)) # Results in 900-1899 range
80+
plugin_version="${major}.${minor}.${dev_patch}"
81+
else
82+
plugin_version="${major}.${minor}.999"
83+
fi
84+
else
85+
plugin_version="$(jq -r '.version' buildspec.json)"
86+
fi
6787
6888
if [[ "${plugin_display_name}" ]]; then
6989
echo "pluginName=${plugin_display_name}" >> $GITHUB_OUTPUT
7090
else
7191
echo "pluginName=${plugin_name}" >> $GITHUB_OUTPUT
7292
fi
93+
echo "pluginVersion=${plugin_version}" >> $GITHUB_OUTPUT
7394
7495
macos-build:
7596
name: Build for macOS 🍏
@@ -105,12 +126,11 @@ jobs:
105126
print '::endgroup::'
106127
107128
local product_name
108-
local product_version
109-
read -r product_name product_version <<< \
110-
"$(jq -r '. | {name, version} | join(" ")' buildspec.json)"
129+
read -r product_name <<< \
130+
"$(jq -r '.name' buildspec.json)"
111131
112132
print "pluginName=${product_name}" >> $GITHUB_OUTPUT
113-
print "pluginVersion=${product_version}" >> $GITHUB_OUTPUT
133+
print "pluginVersion=${{ needs.check-event.outputs.pluginVersion }}" >> $GITHUB_OUTPUT
114134
115135
- uses: actions/cache/restore@v4
116136
id: ccache-cache
@@ -155,6 +175,7 @@ jobs:
155175
notarize: ${{ fromJSON(needs.check-event.outputs.notarize) && fromJSON(steps.codesign.outputs.haveNotarizationUser) }}
156176
codesignUser: ${{ secrets.MACOS_NOTARIZATION_USERNAME }}
157177
codesignPass: ${{ secrets.MACOS_NOTARIZATION_PASSWORD }}
178+
version: ${{ needs.check-event.outputs.pluginVersion }}
158179

159180
- name: Upload Artifacts 📡
160181
uses: actions/upload-artifact@v4
@@ -197,11 +218,11 @@ jobs:
197218
: Set Up Environment 🔧
198219
if [[ "${RUNNER_DEBUG}" ]]; then set -x; fi
199220
200-
read -r product_name product_version <<< \
201-
"$(jq -r '. | {name, version} | join(" ")' buildspec.json)"
221+
read -r product_name <<< \
222+
"$(jq -r '.name' buildspec.json)"
202223
203224
echo "pluginName=${product_name}" >> $GITHUB_OUTPUT
204-
echo "pluginVersion=${product_version}" >> $GITHUB_OUTPUT
225+
echo "pluginVersion=${{ needs.check-event.outputs.pluginVersion }}" >> $GITHUB_OUTPUT
205226
206227
- uses: actions/cache/restore@v4
207228
id: ccache-cache
@@ -223,6 +244,7 @@ jobs:
223244
target: x86_64
224245
config: ${{ needs.check-event.outputs.config }}
225246
package: ${{ fromJSON(needs.check-event.outputs.package) }}
247+
version: ${{ needs.check-event.outputs.pluginVersion }}
226248

227249
- name: Upload Source Tarball 🗜️
228250
uses: actions/upload-artifact@v4
@@ -272,10 +294,9 @@ jobs:
272294
273295
$BuildSpec = Get-Content -Path buildspec.json -Raw | ConvertFrom-Json
274296
$ProductName = $BuildSpec.name
275-
$ProductVersion = $BuildSpec.version
276297
277298
"pluginName=${ProductName}" >> $env:GITHUB_OUTPUT
278-
"pluginVersion=${ProductVersion}" >> $env:GITHUB_OUTPUT
299+
"pluginVersion=${{ needs.check-event.outputs.pluginVersion }}" >> $env:GITHUB_OUTPUT
279300
280301
- name: Build Plugin 🧱
281302
uses: ./.github/actions/build-plugin
@@ -289,6 +310,7 @@ jobs:
289310
target: x64
290311
config: ${{ needs.check-event.outputs.config }}
291312
package: ${{ fromJSON(needs.check-event.outputs.package) }}
313+
version: ${{ needs.check-event.outputs.pluginVersion }}
292314

293315
- name: Upload Artifacts 📡
294316
uses: actions/upload-artifact@v4

.github/workflows/push.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
7171
root_dir="$(pwd)"
7272
commit_hash="${GITHUB_SHA:0:9}"
73+
# Use the version from the build workflow (ensures consistency with artifacts)
74+
version="${{ needs.build-project.outputs.pluginVersion }}"
7375
7476
variants=(
7577
'windows-x64;zip|exe'
@@ -81,7 +83,8 @@ jobs:
8183
for variant_data in "${variants[@]}"; do
8284
IFS=';' read -r variant suffix <<< "${variant_data}"
8385
84-
candidates=(*-${variant}-${commit_hash}/@(*|*-dbgsym).@(${suffix}))
86+
# Look for artifacts with the actual version number from the tag
87+
candidates=(*-${version}-${variant}-${commit_hash}/@(*|*-dbgsym).@(${suffix}))
8588
8689
for candidate in "${candidates[@]}"; do
8790
mv "${candidate}" "${root_dir}"

CMakeLists.txt

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,43 @@ cmake_minimum_required(VERSION 3.28...3.30)
22

33
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE)
44

5-
# Determine authoritative version from git tag first
6-
execute_process(
7-
COMMAND git describe --tags --always --dirty
8-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
9-
OUTPUT_VARIABLE GIT_VERSION_TAG
10-
OUTPUT_STRIP_TRAILING_WHITESPACE
11-
ERROR_QUIET
12-
)
13-
14-
# Extract clean version number from git tag for project version
15-
if(GIT_VERSION_TAG AND GIT_VERSION_TAG MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)")
16-
# Extract version number from tag (e.g., "v1.2.3" -> "1.2.3", "1.2.3-dirty" -> "1.2.3")
17-
string(REGEX REPLACE "^v?([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" AUTHORITATIVE_VERSION "${GIT_VERSION_TAG}")
18-
message(STATUS "Using git tag version: ${AUTHORITATIVE_VERSION}")
5+
# Determine authoritative version from git tag first (skip for PR builds)
6+
if(DEFINED ENV{GITHUB_EVENT_NAME} AND "$ENV{GITHUB_EVENT_NAME}" STREQUAL "pull_request")
7+
# For PR builds, use development version with high patch numbers
8+
# Use format MAJOR.MINOR.999X where X is build number (CMake VERSION compliant)
9+
string(REPLACE "." ";" version_parts "${_version}")
10+
list(GET version_parts 0 major)
11+
list(GET version_parts 1 minor)
12+
13+
if(DEFINED ENV{GITHUB_RUN_NUMBER})
14+
# Use development patch number with limited range to avoid potential issues
15+
math(EXPR run_mod "$ENV{GITHUB_RUN_NUMBER} % 1000") # Limit to 0-999 range
16+
math(EXPR dev_patch "900 + ${run_mod}") # Results in 900-1899 range
17+
set(AUTHORITATIVE_VERSION "${major}.${minor}.${dev_patch}")
18+
else()
19+
# Local development builds use 999
20+
set(AUTHORITATIVE_VERSION "${major}.${minor}.999")
21+
endif()
22+
message(STATUS "PR build detected, using development version: ${AUTHORITATIVE_VERSION}")
1923
else()
20-
# Fallback to buildspec.json version if no proper git tag is available
21-
set(AUTHORITATIVE_VERSION "${_version}")
22-
message(STATUS "No git tag found, using buildspec.json version: ${AUTHORITATIVE_VERSION}")
24+
execute_process(
25+
COMMAND git describe --tags --always --dirty
26+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
27+
OUTPUT_VARIABLE GIT_VERSION_TAG
28+
OUTPUT_STRIP_TRAILING_WHITESPACE
29+
ERROR_QUIET
30+
)
31+
32+
# Extract clean version number from git tag for project version
33+
if(GIT_VERSION_TAG AND GIT_VERSION_TAG MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)")
34+
# Extract version number from tag (e.g., "v1.2.3" -> "1.2.3", "1.2.3-dirty" -> "1.2.3")
35+
string(REGEX REPLACE "^v?([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" AUTHORITATIVE_VERSION "${GIT_VERSION_TAG}")
36+
message(STATUS "Using git tag version: ${AUTHORITATIVE_VERSION}")
37+
else()
38+
# Fallback to buildspec.json version if no proper git tag is available
39+
set(AUTHORITATIVE_VERSION "${_version}")
40+
message(STATUS "No git tag found, using buildspec.json version: ${AUTHORITATIVE_VERSION}")
41+
endif()
2342
endif()
2443

2544
project(${_name} VERSION ${AUTHORITATIVE_VERSION})
@@ -37,15 +56,25 @@ include(helpers)
3756

3857
add_library(${CMAKE_PROJECT_NAME} MODULE)
3958

40-
# Update buildspec.json with authoritative version if it came from git tag
41-
if(GIT_VERSION_TAG AND GIT_VERSION_TAG MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)")
42-
# Update buildspec.json with the git tag version to keep it in sync
43-
# Use sed to update only line 41 (the main project version, not dependency versions)
59+
# Update buildspec.json with authoritative version for consistent packaging
60+
# Always update for PR builds (development versions) and tagged releases
61+
if(AUTHORITATIVE_VERSION)
62+
# Update buildspec.json with the calculated version to keep it in sync
63+
# Use a cross-platform approach with temporary file to avoid sed -i incompatibilities
4464
execute_process(
45-
COMMAND sed -i "41s/\"version\": \"[^\"]*\"/\"version\": \"${AUTHORITATIVE_VERSION}\"/" "${CMAKE_SOURCE_DIR}/buildspec.json"
65+
COMMAND sed "41s/\"version\": \"[^\"]*\"/\"version\": \"${AUTHORITATIVE_VERSION}\"/" "${CMAKE_SOURCE_DIR}/buildspec.json"
66+
OUTPUT_FILE "${CMAKE_SOURCE_DIR}/buildspec.json.tmp"
4667
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
4768
RESULT_VARIABLE sed_result
4869
)
70+
71+
if(sed_result EQUAL 0)
72+
execute_process(
73+
COMMAND ${CMAKE_COMMAND} -E rename "${CMAKE_SOURCE_DIR}/buildspec.json.tmp" "${CMAKE_SOURCE_DIR}/buildspec.json"
74+
RESULT_VARIABLE mv_result
75+
)
76+
set(sed_result ${mv_result})
77+
endif()
4978

5079
if(sed_result EQUAL 0)
5180
message(STATUS "Updated buildspec.json version to: ${AUTHORITATIVE_VERSION}")

buildspec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"name": "c64u-plugin-for-obs",
4040
"displayName": "Commodore 64 Ultimate Source Plugin for OBS",
41-
"version": "0.4.3",
41+
"version": "0.5.985",
4242
"author": "Christian Gleissner",
4343
"website": "https://c64.gleissner.uk",
4444
"email": "[email protected]"

0 commit comments

Comments
 (0)