Skip to content

Commit 54867ec

Browse files
Widthdomclaude
andauthored
Pin release.yml checkout ref to refs/tags/<tag_name> on workflow_dispatch (#156)
When workflow_dispatch was invoked with a branch name (e.g. "main"), actions/checkout would silently resolve it as a branch ref and later steps that assume HEAD is a release tag (git describe --tags --exact-match HEAD, gh release create --verify-tag, etc.) would fail with confusing errors. Resolve inputs.tag_name via format('refs/tags/{0}', inputs.tag_name) in both the release and nuget-publish jobs so a branch name now fails the checkout step itself instead of reaching the tag-assumed downstream logic. https://claude.ai/code/session_01EynRk1KiNDypBTkzJgwfVT Co-authored-by: Claude <noreply@anthropic.com>
2 parents ca3c8a1 + 9627027 commit 54867ec

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ jobs:
2222
uses: actions/checkout@v4
2323
with:
2424
fetch-depth: 0
25-
ref: ${{ inputs.tag_name || github.ref }}
25+
# On workflow_dispatch, force refs/tags/<tag_name> so a branch name
26+
# (e.g. "main") fails checkout instead of falling through to the
27+
# tag-assumed downstream steps.
28+
# workflow_dispatch では refs/tags/<tag_name> に固定し、"main" 等の
29+
# ブランチ名が指定された場合にタグ前提の後続ステップへ進む前に
30+
# checkout 段階で失敗させます。
31+
ref: ${{ inputs.tag_name && format('refs/tags/{0}', inputs.tag_name) || github.ref }}
2632

2733
- name: Set up .NET
2834
uses: actions/setup-dotnet@v4
@@ -149,7 +155,9 @@ jobs:
149155
uses: actions/checkout@v4
150156
with:
151157
fetch-depth: 0
152-
ref: ${{ inputs.tag_name || github.ref }}
158+
# See release job for rationale.
159+
# release ジョブの注記を参照してください。
160+
ref: ${{ inputs.tag_name && format('refs/tags/{0}', inputs.tag_name) || github.ref }}
153161

154162
- name: Set up .NET
155163
uses: actions/setup-dotnet@v4

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
99

1010
### [Unreleased]
1111

12+
#### Fixed
13+
14+
- **Release workflow `workflow_dispatch` now pins the checkout to `refs/tags/<tag_name>`** — Both the `release` and `nuget-publish` jobs in `.github/workflows/release.yml` now resolve the dispatch `tag_name` input via `format('refs/tags/{0}', inputs.tag_name)`. Supplying a branch name (for example `main`) now fails at the `actions/checkout` step instead of falling through into the tag-assumed downstream logic (`git describe --tags --exact-match HEAD`, `gh release create --verify-tag`, etc.) and producing confusing late-stage failures. Tag-push triggers still fall through to `github.ref` unchanged. Affected: `.github/workflows/release.yml`, `FolderDiffIL4DotNet.Tests/Architecture/CiAutomationConfigurationTests.cs`. Tests: `CiAutomationConfigurationTests.cs` (1 updated).
15+
1216
### [1.17.0] - 2026-04-17
1317

1418
#### Changed
@@ -1440,6 +1444,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
14401444

14411445
### [Unreleased]
14421446

1447+
#### 修正
1448+
1449+
- **リリースワークフローの `workflow_dispatch` は checkout を `refs/tags/<tag_name>` に固定** — `.github/workflows/release.yml` の `release` / `nuget-publish` ジョブは、dispatch 入力 `tag_name` を `format('refs/tags/{0}', inputs.tag_name)` で解決するようになりました。ブランチ名(例: `main`)が指定された場合は `actions/checkout` 段階で失敗するため、従来のようにタグ前提の後続処理(`git describe --tags --exact-match HEAD`、`gh release create --verify-tag` など)まで進んで混乱する失敗メッセージを出すことがなくなりました。タグ push 起点の実行はこれまで通り `github.ref` を利用します。対象: `.github/workflows/release.yml`、`FolderDiffIL4DotNet.Tests/Architecture/CiAutomationConfigurationTests.cs`。テスト: `CiAutomationConfigurationTests.cs`(更新 1 件)。
1450+
14431451
### [1.17.0] - 2026-04-17
14441452

14451453
#### 変更

FolderDiffIL4DotNet.Tests/Architecture/CiAutomationConfigurationTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ public void ReleaseWorkflow_CreatesGitHubReleaseFromVersionTags()
9191
workflow);
9292
Assert.Contains("CURRENT_TAG=$(git describe --tags --exact-match HEAD --match 'v*')", workflow, StringComparison.Ordinal);
9393
Assert.Contains("PREV_TAG=$(git describe --first-parent --tags --abbrev=0 HEAD^ --match 'v*' 2>/dev/null || true)", workflow, StringComparison.Ordinal);
94+
// workflow_dispatch must resolve the tag input to refs/tags/<tag_name>
95+
// so that branch names (e.g. "main") fail at checkout instead of
96+
// falling through into tag-assumed downstream steps.
97+
// workflow_dispatch では tag 入力を refs/tags/<tag_name> に解決し、
98+
// "main" のようなブランチ名が指定された場合にタグ前提の後続ステップへ
99+
// 進む前に checkout 段階で失敗させます。
100+
Assert.Contains(
101+
"ref: ${{ inputs.tag_name && format('refs/tags/{0}', inputs.tag_name) || github.ref }}",
102+
workflow,
103+
StringComparison.Ordinal);
104+
Assert.DoesNotContain(
105+
"ref: ${{ inputs.tag_name || github.ref }}",
106+
workflow,
107+
StringComparison.Ordinal);
94108
Assert.DoesNotContain("Check if Core exists on GitHub Packages", workflow, StringComparison.Ordinal);
95109
Assert.DoesNotContain("Check if Plugin.Abstractions exists on GitHub Packages", workflow, StringComparison.Ordinal);
96110
Assert.DoesNotContain("owner_path=\"users\"", workflow, StringComparison.Ordinal);

0 commit comments

Comments
 (0)