-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
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
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 |
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
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" |
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
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" | ||
} | ||
} |
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
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 |
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