33 workflow_call :
44 inputs :
55 version-tag :
6- description : ' Version tag to use (e.g., 0.9.7 or v0.9.7) - leave empty to use current commit'
6+ description : ' Version tag (e.g., v0.9.7) - leave empty to use latest commit'
77 required : false
88 type : string
99 publish :
1818 secrets :
1919 NUGETAPIKEY_PSGALLERY :
2020 description : ' NuGet API Key for publishing to PSGallery'
21+ required : false
2122
2223jobs :
2324 build :
@@ -33,26 +34,27 @@ jobs:
3334 repository : ${{ github.repository }}
3435 ref : ${{ inputs['version-tag'] || '' }}
3536 fetch-depth : 0
37+ fetch-tags : true
3638
37- - name : Install GitVersion 6.5.1
39+ - name : Install GitVersion tool
3840 uses : gittools/actions/gitversion/setup@d0139503a9321f76b4a417dfdc8aebcec24decdd # v4.2.0
3941 with :
4042 versionSpec : ' 6.5.1'
4143
42- - name : Determine semantic version for build
44+ - name : Get semantic build version
4345 uses : gittools/actions/gitversion/execute@d0139503a9321f76b4a417dfdc8aebcec24decdd # v4.2.0
4446 with :
4547 configFilePath : GitVersion.yml
4648 disableShallowCloneCheck : true
4749
48- - name : Install and cache PowerShell modules
50+ - name : Restore cached PowerShell modules
4951 uses : potatoqualitee/psmodulecache@ee5e9494714abf56f6efbfa51527b2aec5c761b8 # v6.2.1
5052 with :
5153 modules-to-cache : ${{ inputs['module-list'] }}
5254 shell : pwsh
5355 updatable : false
5456
55- - name : Determine release type and version for build
57+ - name : Determine release type and build version
5658 shell : pwsh
5759 run : |
5860 switch ("${{ github.event_name }}") {
@@ -125,33 +127,40 @@ jobs:
125127 env :
126128 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
127129 run : |
128- git fetch --tags
129- $previousTag = git tag --sort=-v:refname |
130- Where-Object { $_ -match '^v?\d+\.\d+\.\d+' } |
131- Select-Object -Skip 1 -First 1
132- $uri = "https://api.github.com/repos/${{ github.repository }}/releases/generate-notes"
130+ #git fetch --tags
131+ # Find previous tag based on release type
132+ # - For 'Prerelease', use the latest tag (Release notes are generated from last commit to latest tag)
133+ # - For 'Release', use the second latest tag (Release notes are generated from last tag to second latest tag)
134+ $tags = git tag --sort=-v:refname
135+ switch ($releaseType) {
136+ 'Prerelease' { $previousTag = $tags[0] }
137+ 'Release' { $previousTag = $tags[1] }
138+ default { $previousTag = $tags[0] }
139+ }
133140
141+ # Generate release notes via GitHub API
142+ $uri = "https://api.github.com/repos/${{ github.repository }}/releases/generate-notes"
134143 $body = @{
135144 tag_name = 'v${{ env.majorMinorPatch }}'
136145 target_commitish = "main"
137146 previous_tag_name = $previousTag
138147 }
139-
140148 $requestParams = @{
141149 Method = 'Post'
142150 Uri = $uri
143151 Headers = @{
144- Authorization = "Bearer $env: GITHUB_TOKEN"
145- Accept = 'application/vnd.github+json'
152+ Authorization = "Bearer ${{ env. GITHUB_TOKEN }} "
153+ Accept = 'application/vnd.github+json'
146154 }
147- Body = ($body | ConvertTo-Json)
155+ Body = ($body | ConvertTo-Json -Depth 3 )
148156 ContentType = 'application/json'
149157 }
150158 $result = Invoke-RestMethod @requestParams
151159
152- Write-Output 'releaseNotes<<EOF' >> $env:GITHUB_OUTPUT
153- Write-Output ($result.body.ToString()) >> $env:GITHUB_OUTPUT
154- Write-Output 'EOF' >> $env:GITHUB_OUTPUT
160+ # Output release notes
161+ Write-Output 'releaseNotes<<EOF' >> $env:GITHUB_OUTPUT
162+ Write-Output ($result.body.ToString()) >> $env:GITHUB_OUTPUT
163+ Write-Output 'EOF' >> $env:GITHUB_OUTPUT
155164
156165 - name : Create release
157166 uses : ncipollo/release-action@v1
@@ -181,7 +190,7 @@ jobs:
181190 git push origin HEAD:main
182191
183192 - name : Publish build package to PSGallery
184- if : github.ref_name == 'main' && (github.event_name == 'workflow_dispatch' || github.event_name == 'push')
193+ if : github.ref_name == 'main' && (env.NUGETAPIKEY_PSGALLERY != '')
185194 shell : pwsh
186195 env :
187196 NUGETAPIKEY_PSGALLERY : ${{ secrets.NUGETAPIKEY_PSGALLERY }}
0 commit comments