-
-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (104 loc) · 4.65 KB
/
Copy pathCreateRelease.yml
File metadata and controls
122 lines (104 loc) · 4.65 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Auto Release on Merge from Develop to Main (Ubuntu)
permissions:
contents: write
on:
pull_request:
types: [closed]
branches:
- main
jobs:
release:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.ref == 'develop'
runs-on: ubuntu-latest
steps:
- name: Checkout code (full history & tags)
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Git config
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
- name: Get latest tag
id: get_tag
run: |
git fetch --tags
latestTag=$(git tag --list 'v*' --sort=-v:refname | head -n 1)
if [ -z "$latestTag" ]; then
latestTag="v0.0.0"
fi
echo "Latest tag: $latestTag"
echo "latest_tag=$latestTag" >> $GITHUB_OUTPUT
- name: Calculate next tag (patch bump)
id: bump
run: |
version="${{ steps.get_tag.outputs.latest_tag }}"
version=${version#v}
IFS='.' read -r major minor patch <<< "$version"
patch=$((patch + 1))
newTag="v$major.$minor.$patch"
echo "New tag: $newTag"
echo "new_tag=$newTag" >> $GITHUB_OUTPUT
- name: Create and push tag
run: |
git tag ${{ steps.bump.outputs.new_tag }}
git push origin ${{ steps.bump.outputs.new_tag }}
- name: Generate release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api "repos/${{ github.repository }}/releases/generate-notes" \
-f tag_name="${{ steps.bump.outputs.new_tag }}" \
-f previous_tag_name="${{ steps.get_tag.outputs.latest_tag }}" \
--jq .body > release-notes.md
cat release-notes.md
- name: Copy README into module folder
shell: pwsh
run: |
# PowerShell Gallery renders a module's README.md if it's included in the published
# package; Publish-Module only packages the PiHoleShell/ folder, so it has to live there.
Copy-Item -Path README.md -Destination PiHoleShell/README.md -Force
- name: Zip folder
shell: pwsh
run: |
$modulePath = "PiHoleShell"
$manifest = Get-ChildItem -Path $modulePath -Filter PiHoleShell.psd1 -Recurse | Select-Object -First 1
if (-not $manifest) {
throw "No module manifest (*.psd1) found in $modulePath"
}
$version = $env:NEW_TAG -replace '^v', ''
(Get-Content $manifest.FullName) -replace '0.0.0', $version | Set-Content $manifest.FullName
Write-Host "Replacing 0.0.0 with $version in $($manifest.FullName)"
mkdir -p output
zip -r output/release.zip PiHoleShell
env:
NEW_TAG: ${{ steps.bump.outputs.new_tag }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.bump.outputs.new_tag }}
name: "Release ${{ steps.bump.outputs.new_tag }}"
body_path: release-notes.md
files: output/release.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Module to PowerShell Gallery
shell: pwsh
run: |
$apiKey = '${{ secrets.POWERSHELLGALLERY }}'
$modulePath = "PiHoleShell" # Change to your actual module folder
$manifest = Get-ChildItem -Path $modulePath -Filter PiHoleShell.psd1 -Recurse | Select-Object -First 1
if (-not $manifest) {
throw "No module manifest (*.psd1) found in $modulePath"
}
# Surgical replace rather than Update-ModuleManifest, which rewrites and reformats
# the entire file (drops comments, changes array literal styles, etc.). The source
# manifest always has this exact static placeholder, since the version/notes bump
# here is never committed back to the repo.
$releaseNotes = (Get-Content -Path release-notes.md -Raw).Trim()
$releaseNotesEscaped = $releaseNotes -replace "'", "''"
$manifestContent = Get-Content -Path $manifest.FullName -Raw
$manifestContent = $manifestContent.Replace("'Initial release targeting PowerShell 7+'", "'$releaseNotesEscaped'")
Set-Content -Path $manifest.FullName -Value $manifestContent -NoNewline
Write-Host "Publishing module: $($manifest.FullName)"
Publish-Module -Path $manifest.DirectoryName -NuGetApiKey $apiKey -Verbose