Skip to content

Commit 4720e4a

Browse files
committed
Allow passing tags between actions
Add the tag name as an output from the release prep stage, and allow it to be provided as an input to the release stage, so the tag can be passed from one to the next without relying on an action being triggered.
1 parent aff51ad commit 4720e4a

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

.github/workflows/prep-release.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ on:
2222
required: false
2323
type: boolean
2424
default: false
25+
outputs:
26+
release_tag:
27+
description: Name of the release tag
28+
value: ${{ jobs.prep-release.outputs.tag }}
2529

2630
permissions:
2731
contents: write
@@ -33,6 +37,8 @@ jobs:
3337
env:
3438
CYGPORT_FILE: ${{ inputs.cygport_file }}
3539
REQUESTED_TAG: ${{ inputs.release_tag }}
40+
outputs:
41+
tag: ${{ steps.tag-name.outputs.tag }}
3642

3743
steps:
3844

@@ -125,11 +131,12 @@ jobs:
125131
exit 1
126132
127133
- name: Check tag name
134+
id: tag-name
128135
run: |
129136
if ($Env:REQUESTED_TAG -eq "") {
130-
Write-Output "TAG=v$Env:CYGPORT_PVR" | Tee-Object -FilePath $Env:GITHUB_ENV
137+
Write-Output "tag=v$Env:CYGPORT_PVR" | Tee-Object -FilePath $Env:GITHUB_OUTPUT
131138
} elseif ($Env:REQUESTED_TAG.StartsWith("v$Env:CYGPORT_PVR")) {
132-
Write-Output "TAG=$Env:REQUESTED_TAG" | Tee-Object -FilePath $Env:GITHUB_ENV
139+
Write-Output "tag=$Env:REQUESTED_TAG" | Tee-Object -FilePath $Env:GITHUB_OUTPUT
133140
} else {
134141
Write-Output "::error title=Bad tag::Requested tag $Env:REQUESTED_TAG not prefixed by v$Env:CYGPORT_PVR"
135142
exit 1
@@ -144,11 +151,11 @@ jobs:
144151
- name: Create GitHub Release
145152
uses: softprops/action-gh-release@v1
146153
with:
147-
tag_name: ${{ env.TAG }}
154+
tag_name: ${{ steps.tag-name.outputs.tag }}
148155
draft: ${{ ! inputs.publish }}
149156
files: |
150157
${{ env.CYGPORT_PF }}.${{ env.CYGPORT_ARCH }}/dist/${{ env.CYGPORT_NAME }}/*
151158
${{ env.CYGPORT_PF }}.${{ env.CYGPORT_ARCH }}/dist/${{ env.CYGPORT_NAME }}/*/*
152159
fail_on_unmatched_files: true
153160
target_commitish: ${{ github.ref }}
154-
body: ${{ env.TAG }}
161+
body: ${{ steps.tag-name.outputs.tag }}

.github/workflows/release.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
required: false
1313
type: string
1414
default: cygport
15+
tag_name:
16+
description: Name of the tag for the release
17+
required: true
18+
type: string
1519
secrets:
1620
maintainer_key:
1721
description: RSA private key for uploading to Cygwin servers in OpenSSH format
@@ -104,17 +108,24 @@ jobs:
104108
- name: Get the release target branch
105109
id: target
106110
uses: actions/github-script@v6
111+
env:
112+
TAG_NAME: ${{ inputs.tag_name }}
107113
with:
108114
script: |
109-
const target_commitish = context.payload.release.target_commitish;
110-
if (target_commitish.startsWith('refs/heads/')) {
111-
target_ref = target_commitish.substring(11);
115+
const releaseRsp = await github.rest.repos.getReleaseByTag({
116+
owner: context.repo.owner,
117+
repo: context.repo.repo,
118+
tag: process.env.TAG_NAME
119+
});
120+
const targetCommitish = releaseRsp.data.target_commitish;
121+
if (targetCommitish.startsWith('refs/heads/')) {
122+
targetRef = targetCommitish.substring(11);
112123
} else if (target_commitish.startsWith('refs/tags/')) {
113-
target_ref = target.commitish.substring(10);
124+
targetRef = targetCommitish.substring(10);
114125
} else {
115-
core.setFailed('Unexpected target_commitish: ' + target_commitish);
126+
core.setFailed('Unexpected target_commitish: ' + targetCommitish);
116127
}
117-
core.setOutput('target_ref', target_ref);
128+
core.setOutput('target_ref', targetRef);
118129
119130
- name: Get build cache
120131
id: build-cache
@@ -183,7 +194,7 @@ jobs:
183194
184195
- name: Mirror to the Cygwin Git repositories
185196
env:
186-
TAG_NAME: ${{ github.event.release.tag_name }}
197+
TAG_NAME: ${{ inputs.tag_name }}
187198
run: git push "[email protected]:/git/cygwin-packages/$Env:CYGPORT_NAME" tag "$Env:TAG_NAME"
188199

189200
- name: Remove maintainer key

0 commit comments

Comments
 (0)