Update receive-fogimage and test choco publish #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tag, Release, and Publish to PSGallery and Chocolatey Community Repo | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- master | |
jobs: | |
run-build-test: | |
if: github.event.pull_request.merged == true | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Run the build test workflow | |
run: gh workflow run build-test.yml | |
env: | |
GH_TOKEN: ${{ github.token }} | |
confirm-build-test: | |
needs: run-build-test | |
runs-on: windows-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Wait for the runs to start | |
run: start-sleep 60 | |
- name: Get run IDs | |
run: | | |
$runid=((& gh run list --workflow build-test.yml --json databaseId --limit 1) | convertfrom-json).databaseId | |
echo "RUNID=$runid" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
- name: confirm build succeeded | |
run: | | |
$runstatus="" | |
while (($runstatus -ne "success") -AND ($runstatus -ne "failure")) { | |
start-sleep 15 | |
$runstatus=((& gh run view $env:RUNID --exit-status --json conclusion) | Convertfrom-json).conclusion | |
} | |
if ($runstatus -eq "failure") { | |
exit 1 | |
} else { | |
exit 0 | |
} | |
publish-built-module: | |
needs: confirm-build-test | |
runs-on: windows-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
GalKey: ${{ secrets.PSGALLERY }} | |
ChocoKey: ${{ secrets.CHOCOLATEY }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: fregante/[email protected] | |
- name: Build and publish module | |
run: | | |
"Building and publishing module and committing changes" | out-host; | |
Install-PSResource -Name PlatyPS -TrustRepository -Version 0.14.2 -Scope CurrentUser -AcceptLicense | |
$releaseNote = (git log -1 --pretty=%B) | |
"Setting release note to last commit message:`n$releaseNote" | out-host; | |
"Building docs, module, and incrementing version..." | out-host; | |
.\build.ps1 -releasenote "$($releaseNote | out-string)" | |
$version = (Test-ModuleManifest .\FogApi\FogApi.psd1).version | |
"Pushing Changes from publish" | out-host; | |
git add -A | |
git commit -m "$($releaseNote | out-string) - publish build for $version" | |
git push | |
"Publishing module to gallery..." | out-host; | |
Publish-PSResource -apikey $env:GalKey -Path .\_module_build\FogApi -Repository PSGallery; | |
"Creating Github Release..." | out-host; | |
gh release create $version --latest --generate-notes --target master | |
"Adding link to release notes doc page in release..." | out-host; | |
$notes = (gh release view $version --json body | convertfrom-json).body | |
$notes += "`n**Full Release Note History**: https://fogapi.readthedocs.io/en/latest/ReleaseNotes/" | |
gh release edit $version -n $notes | |
"Zipping up built and published module..." | out-host; | |
Compress-Archive -Path .\_module_build\FogApi -DestinationPath ".\_module_build\FogApi.$version.BuiltModule.zip" | |
"Downloading published nupkg..." | out-host; | |
$webClient = [System.Net.WebClient]::new(); | |
$url = "https://www.powershellgallery.com/api/v2/package/FogApi/$version" | |
$webClient.DownloadFile($url,"$PWD\_module_build\FogApi.$version.psgallery.nupkg") | |
"Adding assets to release..." | out-host; | |
gh release upload $version ".\_module_build\FogApi.$version.psgallery.nupkg" | |
gh release upload $version ".\_module_build\FogApi.$version.BuiltModule.zip" | |
"building choco package from local build and temp psresource repo..." | out-host; | |
.\build-choco.ps1 -uselocal; | |
"adding choco package and zip to release" | out-host; | |
copy-item ".\FogApi.$version.nupkg" ".\FogApi.$version.chocolatey.nupkg" | |
gh release upload $version ".\FogApi.$version.chocolatey.nupkg" | |
remove-item ".\FogApi.$version.chocolatey.nupkg" -force -recurse -ea 0; | |
gh release upload $version ".\fogapi.$version.IncludeXml.zip" | |
try { | |
"publishing choco package..." | out-host; | |
choco apikey add -s "https://push.chocolatey.org/" -k="$env:ChocoKey" | |
choco push "FogApi.$version.nupkg" --source https://push.chocolatey.org/ | |
} catch { | |
"Choco package could not be published, there may be a version still pending approval" | out-host; | |
} | |