Skip to content

Commit

Permalink
build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas694 committed Sep 12, 2021
1 parent b104225 commit 169a743
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 1 deletion.
119 changes: 119 additions & 0 deletions .github/workflows/build+deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Builds

on:
push:
branches: [ main ]
tags:
- '[v]?[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:

env:
AppName: WpfImageViewer
# prefix version number with e.g. "v" or nothing
VersionNumberPrefix: v

jobs:

build:

strategy:
matrix:
configuration: [Release]

runs-on: windows-latest

outputs:
tag: ${{ steps.create_tag.outputs.tag }}

env:
ScriptsPath: .\.github\workflows
AssemblyInfoPath: src\Properties\AssemblyInfo.cs
SolutionPath: src\WpfImageViewer.sln
OutputPath: src/bin/Release

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get version
id: get_version
run: |
${{ env.ScriptsPath }}\get-version.ps1 -versionInfoFile "${{ github.workspace }}\${{ env.AssemblyInfoPath }}"
- name: Create tag
id: create_tag
run: |
${{ env.ScriptsPath }}\create-tag.ps1 -githubRef "${{ github.ref }}" -versionNumber "${{ steps.get_version.outputs.VersionNumber }}"
- name: Update AssemblyInfo
run: |
$v = "${{ steps.create_tag.outputs.tag }}.${{ github.run_number }}"
${{ env.ScriptsPath }}\set-version.ps1 -versionInfoFile "${{ github.workspace }}\${{ env.AssemblyInfoPath }}" -versionNumber "$v"
- name: Setup MSBuild.exe
uses: microsoft/[email protected]

- name: Setup NuGet.exe for use with actions
uses: NuGet/[email protected]

- name: Restore NuGet Packages
run: nuget restore ${{ env.SolutionPath }}

- name: Build
run: msbuild ${{ env.SolutionPath }} /p:Configuration=Release

- name: Add files
run: |
Copy-Item "LICENSE" -Destination "${{ env.OutputPath }}\LICENSE.txt"
Copy-Item "LICENSE 3RD PARTY" -Destination "${{ env.OutputPath }}\LICENSE 3RD PARTY.txt"
Remove-Item "${{ env.OutputPath }}\*.pdb"
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.AppName }}-${{ env.VersionNumberPrefix }}${{ steps.create_tag.outputs.tag }}
path: ${{ env.OutputPath }}

deploy:
needs: [build]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
configuration: [Release]

runs-on: windows-latest

steps:
- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.build.outputs.tag }}
release_name: ${{ env.AppName }}-${{ env.VersionNumberPrefix }}${{ needs.build.outputs.tag }}
draft: true
prerelease: false

- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: ${{ env.AppName }}-${{ env.VersionNumberPrefix }}${{ needs.build.outputs.tag }}
path: ${{ env.AppName }}

- name: Zip files
uses: thedoctor0/zip-release@master
with:
type: 'zip'
filename: '${{ env.AppName }}-${{ env.VersionNumberPrefix }}${{ needs.build.outputs.tag }}.zip'
path: ${{ env.AppName }}

- name: Upload release assets
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: .\${{ env.AppName }}-${{ env.VersionNumberPrefix }}${{ needs.build.outputs.tag }}.zip
asset_name: ${{ env.AppName }}-${{ env.VersionNumberPrefix }}${{ needs.build.outputs.tag }}.zip
asset_content_type: application/zip
9 changes: 9 additions & 0 deletions .github/workflows/create-tag.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
param ([Parameter(Mandatory=$true)][string]$githubRef, [Parameter(Mandatory=$true)][string]$versionNumber)

if ( $githubRef.StartsWith("refs/tags/") ) {
$t = $githubRef.replace('refs/tags/v','').replace('refs/tags/','')
} else {
[VERSION]$vs = $versionNumber -replace '^.+((\d+\.){3}\d+).+', '$1'
$t = '{0}.{1}.{2}' -f $vs.Major,$vs.Minor,$vs.Build
}
echo "::set-output name=tag::$t"
12 changes: 12 additions & 0 deletions .github/workflows/get-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param ([Parameter(Mandatory=$true)][string]$versionInfoFile)

$RegularExpression = [regex] 'AssemblyFileVersion\(\"(.*)\"\)'
$fileContent = Get-Content $versionInfoFile
foreach ($content in $fileContent)
{
$match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
if ($match.Success) {
$v = $match.groups[1].value
echo "::set-output name=VersionNumber::$v"
}
}
14 changes: 14 additions & 0 deletions .github/workflows/set-version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
param ([Parameter(Mandatory=$true)][string]$versionInfoFile, [Parameter(Mandatory=$true)][string]$versionNumber)

$regex = [regex] '^\[assembly: (Assembly(File){0,1}Version)\("(.*)"\)\]$'
$file = Get-ChildItem

(Get-Content -Path $versionInfoFile) |
ForEach-Object {
if ($_ -Match $regex) {
'[assembly: {0}("{1}")]' -f $matches[1], $versionNumber
} else {
$_
}
} |
Out-File -Encoding utf8 -FilePath $versionInfoFile
3 changes: 2 additions & 1 deletion src/WpfImageViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Resources\AppIcon.ico</ApplicationIcon>
Expand Down

0 comments on commit 169a743

Please sign in to comment.