Skip to content

Commit 8aadf0d

Browse files
authored
Make package publication retryable (#14)
Co-authored-by: DerTolleEmil <10513218+DerTolleEmil@users.noreply.github.com>
1 parent 502025a commit 8aadf0d

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
44
release:
55
types:
66
- published
7+
workflow_dispatch:
8+
inputs:
9+
release_tag:
10+
description: Published release tag to retry
11+
required: true
12+
type: string
713

814
permissions:
915
contents: read
@@ -27,14 +33,29 @@ jobs:
2733
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2834
with:
2935
fetch-depth: 0
30-
ref: ${{ github.event.release.tag_name }}
36+
ref: ${{ inputs.release_tag || github.event.release.tag_name }}
3137

3238
- name: Download release assets
3339
shell: pwsh
3440
env:
3541
GH_TOKEN: ${{ github.token }}
36-
RELEASE_TAG: ${{ github.event.release.tag_name }}
42+
RELEASE_TAG: ${{ inputs.release_tag || github.event.release.tag_name }}
43+
REPOSITORY: ${{ github.repository }}
3744
run: |
45+
$release = gh release view $env:RELEASE_TAG `
46+
--repo $env:REPOSITORY `
47+
--json isDraft,isPrerelease,tagName |
48+
ConvertFrom-Json
49+
if ($LASTEXITCODE -ne 0) {
50+
throw "Failed to resolve release '$env:RELEASE_TAG'."
51+
}
52+
if ($release.tagName -cne $env:RELEASE_TAG -or $release.isDraft) {
53+
throw "Release '$env:RELEASE_TAG' must be published before its packages can be published."
54+
}
55+
if ($release.isPrerelease) {
56+
throw 'GitHub prereleases cannot publish ACMP packages.'
57+
}
58+
3859
$null = New-Item `
3960
-ItemType Directory `
4061
-Path .\artifacts\release `
@@ -50,8 +71,8 @@ jobs:
5071
shell: pwsh
5172
env:
5273
EVENT_COMMIT: ${{ github.sha }}
53-
IS_PRERELEASE: ${{ github.event.release.prerelease }}
54-
RELEASE_TAG: ${{ github.event.release.tag_name }}
74+
EVENT_NAME: ${{ github.event_name }}
75+
RELEASE_TAG: ${{ inputs.release_tag || github.event.release.tag_name }}
5576
REPOSITORY: ${{ github.repository }}
5677
run: |
5778
$stableVersionPattern = '(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)'
@@ -71,16 +92,13 @@ jobs:
7192
if ($manifest.primaryTag -cne $env:RELEASE_TAG) {
7293
throw "Release tag '$env:RELEASE_TAG' does not match manifest tag '$($manifest.primaryTag)'."
7394
}
74-
if ($env:IS_PRERELEASE -eq 'true') {
75-
throw 'GitHub prereleases cannot publish ACMP packages.'
76-
}
77-
7895
$headCommit = git rev-parse HEAD
7996
if ($LASTEXITCODE -ne 0) {
8097
throw 'Failed to resolve the checked-out release commit.'
8198
}
8299
if ($manifest.commit -cne $headCommit -or
83-
$env:EVENT_COMMIT -cne $headCommit) {
100+
($env:EVENT_NAME -ceq 'release' -and
101+
$env:EVENT_COMMIT -cne $headCommit)) {
84102
throw "Release assets were prepared for '$($manifest.commit)', but the release points to '$headCommit'."
85103
}
86104
@@ -275,6 +293,15 @@ jobs:
275293
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
276294
VERSION: ${{ needs.validate.outputs.powershell_version }}
277295
run: |
296+
$gallery = Get-PSRepository `
297+
-Name PSGallery `
298+
-ErrorAction SilentlyContinue
299+
if ($null -eq $gallery) {
300+
Register-PSRepository `
301+
-Default `
302+
-ErrorAction Stop
303+
}
304+
278305
$existing = Find-Module `
279306
-Name ACMP `
280307
-RequiredVersion $env:VERSION `

‎BUILDING.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ It does not rebuild the packages. It:
161161
- pushes the prepared `.nupkg` to NuGet; and
162162
- extracts and publishes the prepared PowerShell module archive.
163163

164+
If publication fails after the release has been published, fix the workflow on
165+
`main`, then run `Publish Release` manually with the existing primary release
166+
tag. The retry downloads and validates the published assets again, skips
167+
packages that already exist, and publishes any missing package.
168+
164169
The `.nupkg`, `ACMP.dll`, and `ACMP.PowerShell.dll` published by this process
165170
are the files produced by the preparation build.
166171

0 commit comments

Comments
 (0)