From 8b969ac700cb521c2ab9a0921a95fab389b6cb55 Mon Sep 17 00:00:00 2001 From: Patrick Magee Date: Sun, 23 Jun 2024 09:44:27 +0100 Subject: [PATCH] github actions --- .github/workflows/build.yaml | 2 +- .../{deploy.yaml => release-windows-v1.yaml} | 44 ++++++-- .github/workflows/release-windows-v2.yaml | 30 ++++++ .github/workflows/release.yaml | 3 +- .../PublishProfiles/CLickOnceProfile.pubxml | 41 +++++++ release.ps1 | 101 ++++++++++++++++++ 6 files changed, 208 insertions(+), 13 deletions(-) rename .github/workflows/{deploy.yaml => release-windows-v1.yaml} (63%) create mode 100644 .github/workflows/release-windows-v2.yaml create mode 100644 Heroesprofile.Uploader.Windows/Properties/PublishProfiles/CLickOnceProfile.pubxml create mode 100644 release.ps1 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 65e64a8..0deb4b9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Build +name: Build (dagger) on: push: branches: diff --git a/.github/workflows/deploy.yaml b/.github/workflows/release-windows-v1.yaml similarity index 63% rename from .github/workflows/deploy.yaml rename to .github/workflows/release-windows-v1.yaml index 0a7d995..9338cb3 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/release-windows-v1.yaml @@ -1,4 +1,4 @@ -name: Deploy +name: ClickOnce Release v1 on: push: @@ -12,9 +12,14 @@ permissions: jobs: release: + if: false # This condition disables the job. Change to `true` or remove to enable. runs-on: windows-latest + environment: + name: github-pages + url: https://heroesreplay.github.io/HeroesProfile.Uploader/ steps: + - name: Checkout code uses: actions/checkout@v4 with: @@ -30,17 +35,29 @@ jobs: - name: Install dotnet-mage run: dotnet tool install --global microsoft.dotnet.mage --version 8.0.0 - - name: Build and Publish - run: | - - $version = "${{ github.ref }}" + - name: Prepare version and publish directory + id: version + run: | + $version = "${{ github.ref }}" -replace "refs/tags/v", "" $publishDir = ".\publish\$version" - echo "PUBLISH_DIR=$publishDir" >> $GITHUB_ENV + echo "APP_PUBLISH_DIR=$publishDir" >> $GITHUB_ENV + echo "APP_VERSION=$version" >> $GITHUB_ENV + - name: Publish application + run: | dotnet publish .\Heroesprofile.Uploader.Windows ` --self-contained ` --os win ` - -o $publishDir + -o $env:PUBLISH_DIR + env: + APP_PUBLISH_DIR: ${{ env.APP_PUBLISH_DIR }} + APP_VERSION: ${{ env.APP_VERSION }} + + - name: ClickOnce manifest and application + run: | + + $publishDir = $env:APP_PUBLISH_DIR + $version = $env:APP_VERSION dotnet mage -al Heroesprofile.Uploader.exe ` -TargetDirectory $publishDir @@ -48,17 +65,21 @@ jobs: dotnet mage -new Application ` -ToFile $publishDir\Heroesprofile.Uploader.manifest ` -FromDirectory $publishDir ` - -Version ${{ github.ref_name }} ` + -Version $version ` -IconFile .\Heroesprofile.Uploader.Windows\Resources\uploader_icon_dark.ico dotnet mage -new Deployment ` -Install true ` -Publisher "Patrick Magee" ` - -Version ${{ github.ref_name }} ` + -Version $version ` -AppManifest $publishDir\Heroesprofile.Uploader.manifest ` -ToFile Heroesprofile.Uploader.application ` -ProviderUrl https://heroesreplay.github.io/HeroesProfile.Uploader/ + env: + APP_PUBLISH_DIR: ${{ env.APP_PUBLISH_DIR }} + APP_VERSION: ${{ env.APP_VERSION }} + - name: Setup Pages uses: actions/configure-pages@v5 with: @@ -68,9 +89,10 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: ${{ env.PUBLISH_DIR }} + path: ${{ env.APP_PUBLISH_DIR }} env: - PUBLISH_DIR: ${{ env.PUBLISH_DIR }} + APP_PUBLISH_DIR: ${{ env.APP_PUBLISH_DIR }} + APP_VERSION: ${{ env.APP_VERSION }} - name: Deploy to GitHub Pages id: deployment diff --git a/.github/workflows/release-windows-v2.yaml b/.github/workflows/release-windows-v2.yaml new file mode 100644 index 0000000..df43bbe --- /dev/null +++ b/.github/workflows/release-windows-v2.yaml @@ -0,0 +1,30 @@ +name: ClickOnce Release v2 +permissions: + contents: write + packages: write + pages: write + +on: + push: + tags: [v*] + +jobs: + release: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: 'true' + fetch-depth: 0 + + - name: Setup Git + run: | + git config --global url."https://user:${{ secrets.GITHUB_TOKEN }}@github".insteadOf https://github + git config --global user.name github-actions + git config --global user.email github-actions@github.com + + - name: Run release script + shell: pwsh + run: ./release.ps1 \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c6ce095..980e50a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Release +name: Release (dagger) on: push: @@ -11,6 +11,7 @@ permissions: jobs: release: + if: false # This condition disables the job. Change to `true` or remove to enable. runs-on: ubuntu-latest steps: diff --git a/Heroesprofile.Uploader.Windows/Properties/PublishProfiles/CLickOnceProfile.pubxml b/Heroesprofile.Uploader.Windows/Properties/PublishProfiles/CLickOnceProfile.pubxml new file mode 100644 index 0000000..1ae076f --- /dev/null +++ b/Heroesprofile.Uploader.Windows/Properties/PublishProfiles/CLickOnceProfile.pubxml @@ -0,0 +1,41 @@ + + + + + 0 + 0.2.0.0 + True + Release + True + true + True + Web + https://heroesreplay.github.io/HeroesProfile.Uploader/ + False + True + True + False + Any CPU + bin\publish\ + bin\publish\ + ClickOnce + False + False + True + (none) + False + net8.0-windows + True + Foreground + False + Publish.html + + + \ No newline at end of file diff --git a/release.ps1 b/release.ps1 new file mode 100644 index 0000000..489ced3 --- /dev/null +++ b/release.ps1 @@ -0,0 +1,101 @@ +# Copied from https://janjones.me/posts/clickonce-installer-build-publish-github/. + +[CmdletBinding(PositionalBinding = $false)] +param ( + [switch]$OnlyBuild = $false +) + +$appName = "Heroesprofile.Uploader" +$projDir = "Heroesprofile.Uploader.Windows" + +Set-StrictMode -version 2.0 +$ErrorActionPreference = "Stop" + +Write-Output "Working directory: $pwd" + +# Find MSBuild. +$msBuildPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" ` + -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe ` + -prerelease | select-object -first 1 +Write-Output "MSBuild: $((Get-Command $msBuildPath).Path)" + +# Load current Git tag. +$tag = $(git describe --tags) +Write-Output "Tag: $tag" + +# Parse tag into a three-number version. +$version = $tag.Split('-')[0].TrimStart('v') +$version = "$version.0" +Write-Output "Version: $version" + +# Clean output directory. +$publishDir = "bin/publish" +$outDir = "$projDir/$publishDir" +if (Test-Path $outDir) { + Remove-Item -Path $outDir -Recurse +} + +# Publish the application. +Push-Location $projDir +try { + Write-Output "Restoring:" + dotnet restore -r win-x64 + Write-Output "Publishing:" + $msBuildVerbosityArg = "/v:m" + if ($env:CI) { + $msBuildVerbosityArg = "" + } + & $msBuildPath /target:publish /p:PublishProfile=ClickOnceProfile ` + /p:ApplicationVersion=$version /p:Configuration=Release ` + /p:PublishDir=$publishDir /p:PublishUrl=$publishDir ` + $msBuildVerbosityArg + + # Measure publish size. + $publishSize = (Get-ChildItem -Path "$publishDir/Application Files" -Recurse | + Measure-Object -Property Length -Sum).Sum / 1Mb + Write-Output ("Published size: {0:N2} MB" -f $publishSize) +} +finally { + Pop-Location +} + +if ($OnlyBuild) { + Write-Output "Build finished." + exit +} + +# Clone `gh-pages` branch. +$ghPagesDir = "gh-pages" +if (-Not (Test-Path $ghPagesDir)) { + git clone $(git config --get remote.origin.url) -b gh-pages ` + --depth 1 --single-branch $ghPagesDir +} + +Push-Location $ghPagesDir +try { + # Remove previous application files. + Write-Output "Removing previous files..." + if (Test-Path "Application Files") { + Remove-Item -Path "Application Files" -Recurse + } + if (Test-Path "$appName.application") { + Remove-Item -Path "$appName.application" + } + + # Copy new application files. + Write-Output "Copying new files..." + Copy-Item -Path "../$outDir/Application Files", "../$outDir/$appName.application" ` + -Destination . -Recurse + + # Stage and commit. + Write-Output "Staging..." + git add -A + Write-Output "Committing..." + git commit -m "Update to v$version" + + # Push. + git push +} +finally { + Pop-Location +} \ No newline at end of file