Skip to content

Commit

Permalink
github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmagee committed Jun 23, 2024
1 parent 55c3dd5 commit 4d40d3d
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 10 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/clickonce.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release

on:
push:
tags: [v*]

jobs:
release:
runs-on: windows-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- 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 [email protected]
- name: Run release script
shell: pwsh
run: ./release.ps1
42 changes: 32 additions & 10 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ permissions:
id-token: write

jobs:
if: false # This condition disables the job. Change to `true` or remove to enable.
release:
runs-on: windows-latest
environment:
name: github-pages
url: https://heroesreplay.github.io/HeroesProfile.Uploader/

steps:

- name: Checkout code
uses: actions/checkout@v4
with:
Expand All @@ -30,35 +35,51 @@ 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
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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>0.2.0.0</ApplicationVersion>
<BootstrapperEnabled>True</BootstrapperEnabled>
<Configuration>Release</Configuration>
<CreateWebPageOnPublish>True</CreateWebPageOnPublish>
<GenerateManifests>true</GenerateManifests>
<Install>True</Install>
<InstallFrom>Web</InstallFrom>
<InstallUrl>https://heroesreplay.github.io/HeroesProfile.Uploader/</InstallUrl>
<IsRevisionIncremented>False</IsRevisionIncremented>
<IsWebBootstrapper>True</IsWebBootstrapper>
<MapFileExtensions>True</MapFileExtensions>
<OpenBrowserOnPublish>False</OpenBrowserOnPublish>
<Platform>Any CPU</Platform>
<PublishDir>bin\publish\</PublishDir>
<PublishUrl>bin\publish\</PublishUrl>
<PublishProtocol>ClickOnce</PublishProtocol>
<PublishReadyToRun>False</PublishReadyToRun>
<PublishSingleFile>False</PublishSingleFile>
<SelfContained>True</SelfContained>
<SignatureAlgorithm>(none)</SignatureAlgorithm>
<SignManifests>False</SignManifests>
<TargetFramework>net8.0-windows</TargetFramework>
<UpdateEnabled>True</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateRequired>False</UpdateRequired>
<WebPageFileName>Publish.html</WebPageFileName>
</PropertyGroup>
<!-- <ItemGroup>
<BootstrapperPackage Include="Microsoft.NetCore.DesktopRuntime.6.0.x64">
<Install>True</Install>
<ProductName>.NET Desktop Runtime 6.0.10 (x64)</ProductName>
</BootstrapperPackage>
</ItemGroup> -->
</Project>
101 changes: 101 additions & 0 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4d40d3d

Please sign in to comment.