Skip to content

Commit c8c3a19

Browse files
vaindclaude
andauthored
fix: Danger and updater download script URLs cannot use GITHUB_WORKFLOW_REF (#111)
* Revert "fix: Use GITHUB_WORKFLOW_REF instead of _workflow_version input (#109)" This reverts commit bdf2970. * feat: Add PowerShell script for Craft release version updates Adds automated version management for Craft releases: - Creates scripts/update-version.ps1 to update _workflow_version defaults - Updates .craft.yml to use the script in preReleaseCommand - Script automatically updates danger.yml and updater.yml workflow defaults 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: Update default workflow version to 2.14.1 in danger and updater workflows * fix: Add proper YAML quoting to version update script Ensures the PowerShell script properly quotes version values in YAML to maintain valid syntax when updating _workflow_version defaults. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: Add changelog entry for Craft automation and workflow fix Documents the addition of PowerShell version update script and the revert from GITHUB_WORKFLOW_REF back to _workflow_version parameter. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: Update changelog entry to clarify GITHUB_WORKFLOW_REF issue The core problem is that script download URLs cannot use GITHUB_WORKFLOW_REF when workflows are called from other repositories. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: Simplify changelog entry to focus on the core fix Remove implementation details about Craft automation and focus on the main issue: GITHUB_WORKFLOW_REF cannot be used for script download URLs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c3ab8b9 commit c8c3a19

File tree

7 files changed

+71
-10
lines changed

7 files changed

+71
-10
lines changed

.craft.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
minVersion: 0.23.1
22
changelogPolicy: auto
3-
preReleaseCommand: pwsh -cwa ''
3+
preReleaseCommand: pwsh scripts/update-version.ps1
44
artifactProvider:
55
name: none
66
targets:

.github/workflows/danger-workflow-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
jobs:
99
danger:
1010
uses: ./.github/workflows/danger.yml
11+
with:
12+
_workflow_version: ${{ github.sha }}
1113

1214
test-outputs:
1315
runs-on: ubuntu-latest

.github/workflows/danger.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Runs DangerJS with a pre-configured set of rules on a Pull Request.
22
on:
33
workflow_call:
4+
inputs:
5+
_workflow_version:
6+
description: 'Internal: specify github-workflows (this repo) revision to use when checking out scripts.'
7+
type: string
8+
required: false
9+
default: '2.14.1' # Note: this is updated during release process
410
outputs:
511
outcome:
612
description: Whether the Danger run finished successfully. Possible values are success, failure, cancelled, or skipped.
@@ -18,10 +24,8 @@ jobs:
1824

1925
- name: Download dangerfile.js and utilities
2026
run: |
21-
# Extract the ref from GITHUB_WORKFLOW_REF (e.g., getsentry/github-workflows/.github/workflows/danger.yml@refs/pull/109/merge -> refs/pull/109/merge)
22-
WORKFLOW_REF=$(echo "${{ github.workflow_ref }}" | sed 's/.*@//')
23-
wget https://raw.githubusercontent.com/getsentry/github-workflows/${WORKFLOW_REF}/danger/dangerfile.js -P ${{ runner.temp }}
24-
wget https://raw.githubusercontent.com/getsentry/github-workflows/${WORKFLOW_REF}/danger/dangerfile-utils.js -P ${{ runner.temp }}
27+
wget https://raw.githubusercontent.com/getsentry/github-workflows/${{ inputs._workflow_version }}/danger/dangerfile.js -P ${{ runner.temp }}
28+
wget https://raw.githubusercontent.com/getsentry/github-workflows/${{ inputs._workflow_version }}/danger/dangerfile-utils.js -P ${{ runner.temp }}
2529
2630
# Using a pre-built docker image in GitHub container registry instaed of NPM to reduce possible attack vectors.
2731
- name: Run DangerJS

.github/workflows/updater.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ on:
3838
type: string
3939
required: false
4040
default: create
41+
_workflow_version:
42+
description: 'Internal: specify github-workflows (this repo) revision to use when checking out scripts.'
43+
type: string
44+
required: false
45+
default: '2.14.1' # Note: this is updated during release process
4146
secrets:
4247
api-token:
4348
required: true
@@ -136,13 +141,11 @@ jobs:
136141
# Note: cannot use `actions/checkout` at the moment because you can't clone outside of the repo root.
137142
# Follow https://github.com/actions/checkout/issues/197
138143
run: |
139-
# Extract the ref from GITHUB_WORKFLOW_REF (e.g., getsentry/github-workflows/.github/workflows/updater.yml@refs/pull/109/merge -> refs/pull/109/merge)
140-
$workflowRef = '${{ github.workflow_ref }}' -replace '.*@', ''
141-
New-Item -ItemType Directory -Force -Path '${{ runner.temp }}/ghwf'
142-
Set-Location '${{ runner.temp }}/ghwf'
144+
mkdir -p ${{ runner.temp }}/ghwf
145+
cd ${{ runner.temp }}/ghwf
143146
git init
144147
git remote add origin https://github.com/getsentry/github-workflows.git
145-
git fetch --depth 1 origin $workflowRef
148+
git fetch --depth 1 origin ${{ inputs._workflow_version }}
146149
git checkout FETCH_HEAD
147150
148151
- name: Update to the latest version

.github/workflows/workflow-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
name: WORKFLOW-TEST-DEPENDENCY-DO-NOT-MERGE
1313
pattern: '^2\.0\.'
1414
pr-strategy: update
15+
_workflow_version: ${{ github.sha }}
1516
secrets:
1617
api-token: ${{ github.token }}
1718

@@ -22,6 +23,7 @@ jobs:
2223
name: Workflow args test script
2324
runs-on: macos-latest
2425
pattern: '.*'
26+
_workflow_version: ${{ github.sha }}
2527
secrets:
2628
api-token: ${{ github.token }}
2729

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Danger and updater download script URLs cannot use GITHUB_WORKFLOW_REF ([#111](https://github.com/getsentry/github-workflows/pull/111))
8+
39
## 2.14.1
410

511
### Fixes

scripts/update-version.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env pwsh
2+
3+
param(
4+
[Parameter(Mandatory=$true, Position=0)]
5+
[string]$OldVersion,
6+
7+
[Parameter(Mandatory=$true, Position=1)]
8+
[string]$NewVersion
9+
)
10+
11+
Set-StrictMode -Version Latest
12+
$ErrorActionPreference = "Stop"
13+
$PSNativeCommandUseErrorActionPreference = $true
14+
15+
Write-Host "Updating version from $OldVersion to $NewVersion"
16+
17+
# Update specific workflow files with _workflow_version inputs
18+
Write-Host "Updating workflow files..."
19+
$workflowFiles = @(
20+
".github/workflows/updater.yml",
21+
".github/workflows/danger.yml"
22+
)
23+
24+
foreach ($filePath in $workflowFiles) {
25+
$content = Get-Content -Path $filePath -Raw
26+
27+
# Check if this file has _workflow_version input with a default value
28+
if ($content -match '(?ms)_workflow_version:.*?default:\s*([^\s#]+)') {
29+
Write-Host "Updating $filePath..."
30+
$oldDefault = $Matches[1]
31+
32+
# Replace the default value for _workflow_version
33+
$newContent = $content -replace '((?ms)_workflow_version:.*?default:\s*)([^\s#]+)', "`${1}'$NewVersion'"
34+
35+
# Write the updated content back to the file
36+
$newContent | Out-File -FilePath $filePath -Encoding utf8 -NoNewline
37+
38+
Write-Host " Updated default from '$oldDefault' to '$NewVersion'"
39+
} else {
40+
Write-Error "No _workflow_version default found in $filePath"
41+
}
42+
}
43+
44+
Write-Host "Version update completed successfully!"

0 commit comments

Comments
 (0)