-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublishModuleToPowerShellGallery.yaml
More file actions
101 lines (91 loc) · 3.59 KB
/
PublishModuleToPowerShellGallery.yaml
File metadata and controls
101 lines (91 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Publish Module to PowerShell Gallery
on:
push:
branches:
- main
paths:
- '{{ModuleName}}/{{ModuleName}}.psd1'
workflow_dispatch:
permissions:
contents: write
jobs:
publish:
name: Publish Module
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
# Never publish the un-initialized template — the .psd1 still has
# {{ModuleName}} and {{GUID}} placeholders. Same marker as CI.yaml:
# CHANGELOG.template.md exists only pre-init. hashFiles() is not allowed
# in jobs.<job_id>.if, so we evaluate it in a step and gate the
# version-detection and release-check steps on the resulting output;
# everything downstream cascades on those steps' outputs and skips
# naturally when they don't run.
- name: Detect template state
id: template_guard
shell: bash
run: |
if [ -f CHANGELOG.template.md ]; then
echo "is_template=true" >> "$GITHUB_OUTPUT"
else
echo "is_template=false" >> "$GITHUB_OUTPUT"
fi
- name: Get Module Version
id: version
if: steps.template_guard.outputs.is_template == 'false'
shell: pwsh
run: |
$manifest = Import-PowerShellDataFile -Path ./{{ModuleName}}/{{ModuleName}}.psd1
$version = $manifest.ModuleVersion
Write-Host "Module version: $version"
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Check if Release Exists
id: check_release
if: steps.template_guard.outputs.is_template == 'false'
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "v${{ steps.version.outputs.version }}" > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "GitHub release v${{ steps.version.outputs.version }} already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "GitHub release v${{ steps.version.outputs.version }} does not exist"
fi
- name: Check if PSGallery Version Exists
id: check_psgallery
if: steps.check_release.outputs.exists == 'false'
shell: pwsh
run: |
$version = "${{ steps.version.outputs.version }}"
$published = Find-Module -Name {{ModuleName}} -RequiredVersion $version -Repository PSGallery -ErrorAction SilentlyContinue
if ($published) {
Write-Host "PSGallery version $version already exists"
"exists=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
} else {
Write-Host "PSGallery version $version not found - will publish"
"exists=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
}
- name: Bootstrap
if: steps.check_release.outputs.exists == 'false'
shell: pwsh
run: ./build.ps1 -Task Init -Bootstrap
- name: Create GitHub Release
if: steps.check_release.outputs.exists == 'false'
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ steps.version.outputs.version }}" \
--title "v${{ steps.version.outputs.version }}" \
--generate-notes
- name: Publish to PSGallery
if: steps.check_release.outputs.exists == 'false' && steps.check_psgallery.outputs.exists == 'false'
shell: pwsh
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
run: ./build.ps1 -Task Publish -Bootstrap