Skip to content

Commit 23ef09c

Browse files
frick
1 parent fe67527 commit 23ef09c

1 file changed

Lines changed: 54 additions & 14 deletions

File tree

.github/workflows/release.yml

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ on:
88

99
permissions:
1010
contents: write
11-
11+
actions: write
12+
checks: write
1213
jobs:
1314
prepare:
1415
name: Prepare release (check files, version, notes)
15-
runs-on: windows-latest
16+
runs-on: ubuntu-latest
1617
outputs:
1718
should_release: ${{ steps.check_files.outputs.should_release }}
1819
version: ${{ steps.next_version.outputs.version }}
@@ -27,25 +28,30 @@ jobs:
2728
id: check_files
2829
shell: pwsh
2930
run: |
31+
Write-Output "DEBUG: Starting check_files"
32+
Write-Output "DEBUG: PR Event Data - Base: ${{ github.event.pull_request.base.sha }} - Head: ${{ github.event.pull_request.head.sha }}"
33+
3034
$changedFiles = git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}
31-
Write-Output "Changed files:"
35+
Write-Output "DEBUG: Changed files found:"
3236
Write-Output $changedFiles
3337
3438
$sourceChanged = $false
3539
foreach ($file in $changedFiles) {
3640
if ($file -match '\.(cpp|h|hpp|c|cc|cxx)$') {
3741
$sourceChanged = $true
38-
Write-Output "Source file changed: $file"
42+
Write-Output "DEBUG: Source file changed: $file"
3943
break
4044
}
4145
}
4246
47+
Write-Output "DEBUG: sourceChanged is $sourceChanged"
48+
4349
if ($sourceChanged) {
4450
Write-Output "should_release=true" >> $env:GITHUB_OUTPUT
45-
Write-Output "Source files changed - will proceed with release"
51+
Write-Output "DEBUG: Setting should_release=true"
4652
} else {
4753
Write-Output "should_release=false" >> $env:GITHUB_OUTPUT
48-
Write-Output "No source files changed - skipping release"
54+
Write-Output "DEBUG: Setting should_release=false"
4955
}
5056
5157
- name: Get latest release tag
@@ -55,33 +61,45 @@ jobs:
5561
env:
5662
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5763
run: |
64+
Write-Output "DEBUG: Starting get_latest_tag"
5865
$repo = "${{ github.repository }}"
66+
Write-Output "DEBUG: Repo is $repo"
67+
5968
$headers = @{"Authorization" = "token $env:GITHUB_TOKEN"; "Accept" = "application/vnd.github.v3+json"}
6069
6170
# Try GitHub Releases API first (includes prereleases)
6271
try {
72+
Write-Output "DEBUG: Fetching releases from API..."
6373
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases?per_page=100" -Headers $headers -UseBasicParsing
74+
Write-Output "DEBUG: Fetched $($releases.Count) releases"
6475
} catch {
76+
Write-Output "DEBUG: Failed to fetch releases from API: $_"
6577
$releases = @()
6678
}
6779
6880
$candidates = @()
6981
foreach ($r in $releases) {
82+
Write-Output "DEBUG: Checking release tag: $($r.tag_name)"
7083
if ($r.tag_name -match 'v?(\d+)\.(\d+)\.(\d+)') {
7184
$candidates += [PSCustomObject]@{ Tag = $r.tag_name; Major = [int]$Matches[1]; Minor = [int]$Matches[2]; Patch = [int]$Matches[3] }
7285
}
7386
}
7487
7588
if ($candidates.Count -gt 0) {
76-
$sorted = $candidates | Sort-Object -Property @{Expression={$_.Major};Descending=$true}, @{Expression={$_.Minor};Descending=$true}, @{Expression={$_.Patch};Descending=$true}
77-
$latestTag = $sorted[0].Tag
78-
Write-Output "latest_tag=$latestTag" >> $env:GITHUB_OUTPUT
79-
exit 0
89+
Write-Output "DEBUG: Found valid candidates in releases."
90+
$sorted = $candidates | Sort-Object -Property @{Expression={$_.Major};Descending=$true}, @{Expression={$_.Minor};Descending=$true}, @{Expression={$_.Patch};Descending=$true}
91+
$latestTag = $sorted[0].Tag
92+
Write-Output "DEBUG: Selected latest tag from API: $latestTag"
93+
Write-Output "latest_tag=$latestTag" >> $env:GITHUB_OUTPUT
94+
exit 0
8095
}
8196
8297
# Fallback: ensure tags are fetched and inspect local tags
98+
Write-Output "DEBUG: Fallback to local git tags"
8399
git fetch --tags --prune || true
84100
$local = git tag -l "v[0-9]*.[0-9]*.[0-9]*"
101+
Write-Output "DEBUG: Local tags found: $local"
102+
85103
if ($local) {
86104
$sortedTags = $local | ForEach-Object {
87105
if ($_ -match 'v?(\d+)\.(\d+)\.(\d+)') {
@@ -90,11 +108,14 @@ jobs:
90108
} | Sort-Object -Property @{Expression={$_.Major};Descending=$true}, @{Expression={$_.Minor};Descending=$true}, @{Expression={$_.Patch};Descending=$true}
91109
if ($sortedTags.Count -gt 0) {
92110
$latestTag = $sortedTags[0].Tag
111+
Write-Output "DEBUG: Selected latest tag from local tags: $latestTag"
93112
Write-Output "latest_tag=$latestTag" >> $env:GITHUB_OUTPUT
94113
} else {
114+
Write-Output "DEBUG: No valid semantic version tags found locally. Defaulting to v0.0.0"
95115
Write-Output "latest_tag=v0.0.0" >> $env:GITHUB_OUTPUT
96116
}
97117
} else {
118+
Write-Output "DEBUG: No local tags found. Defaulting to v0.0.0"
98119
Write-Output "latest_tag=v0.0.0" >> $env:GITHUB_OUTPUT
99120
}
100121
@@ -104,12 +125,15 @@ jobs:
104125
shell: pwsh
105126
run: |
106127
$latestTag = "${{ steps.get_latest_tag.outputs.latest_tag }}"
128+
Write-Output "DEBUG: Starting next_version. Input latestTag: $latestTag"
129+
107130
if ($latestTag -match 'v?(\d+)\.(\d+)\.(\d+)') {
108131
$major = [int]$Matches[1]
109132
$minor = [int]$Matches[2]
110133
$patch = [int]$Matches[3]
111134
$patch = $patch + 1
112135
$newVersion = "v$major.$minor.$patch"
136+
Write-Output "DEBUG: Calculated new version: $newVersion"
113137
Write-Output "version=$newVersion" >> $env:GITHUB_OUTPUT
114138
Write-Output "version_number=$major.$minor.$patch" >> $env:GITHUB_OUTPUT
115139
} else {
@@ -122,7 +146,10 @@ jobs:
122146
id: parse_commit
123147
shell: pwsh
124148
run: |
149+
Write-Output "DEBUG: Starting parse_commit"
125150
$commitMsg = git log -1 --pretty=%B
151+
Write-Output "DEBUG: Commit message: $commitMsg"
152+
126153
$commitSubject = $commitMsg.Split("`n")[0]
127154
$commitBodyLines = $commitMsg.Split("`n") | Select-Object -Skip 1
128155
$commitBody = ($commitBodyLines -join "`n").Trim()
@@ -156,10 +183,12 @@ jobs:
156183
$releaseNotes += "`n$commitBody`n"
157184
}
158185
186+
Write-Output "DEBUG: releaseNotes: $releaseNotes"
159187
$commitSha = git rev-parse --short HEAD
160188
$releaseNotes += "`n---`n*Commit: $commitSha*"
161189

162190
$delimiter = "EOF_$(Get-Random)"
191+
Write-Output "DEBUG: Writing notes to output using delimiter $delimiter"
163192
Write-Output "notes<<$delimiter" >> $env:GITHUB_OUTPUT
164193
Write-Output $releaseNotes >> $env:GITHUB_OUTPUT
165194
Write-Output $delimiter >> $env:GITHUB_OUTPUT
@@ -213,7 +242,7 @@ jobs:
213242

214243
create-release:
215244
name: Create GitHub Release with all artifacts
216-
needs: build
245+
needs: [prepare, build]
217246
if: needs.prepare.outputs.should_release == 'true'
218247
runs-on: ubuntu-latest
219248
steps:
@@ -236,20 +265,31 @@ jobs:
236265
shell: bash
237266
run: |
238267
set -e
268+
echo "DEBUG: Ensure Release Tag Exists"
269+
echo "DEBUG: received version: '${{ needs.prepare.outputs.version }}'"
270+
echo "DEBUG: received sha: $(git rev-parse HEAD)"
271+
272+
git config user.name "github-actions[bot]"
273+
git config user.email "github-actions[bot]@users.noreply.github.com"
274+
239275
TAG="${{ needs.prepare.outputs.version }}"
240276
echo "Preparing tag: $TAG"
241277
if [ -z "$TAG" ]; then
242278
echo "No tag provided; cannot create release"
243279
exit 1
244280
fi
245281
if git rev-parse "$TAG" >/dev/null 2>&1; then
246-
echo "Tag $TAG already exists locally"
282+
echo "DEBUG: Tag $TAG already exists locally"
247283
else
248-
git tag -a "$TAG" -m "Release $TAG"
249-
echo "Created local tag $TAG"
284+
# Explicitly tag the HEAD sha to match the checked out state
285+
HEAD_SHA=$(git rev-parse HEAD)
286+
echo "DEBUG: Creating tag $TAG on $HEAD_SHA"
287+
git tag -a "$TAG" -m "Release $TAG" "$HEAD_SHA"
288+
echo "DEBUG: Created local tag $TAG"
250289
fi
251290
252291
# Push tag (skip errors if it already exists on remote)
292+
echo "DEBUG: Pushing tag $TAG"
253293
git push origin "$TAG" || echo "Tag push failed or already exists on remote"
254294
255295
- name: Create Release and Upload Assets

0 commit comments

Comments
 (0)