-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (92 loc) · 4.29 KB
/
build-and-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
on:
workflow_dispatch:
inputs:
Version:
description: "Version number"
required: true
default: "1.0.1"
SelfContained:
description: "Create Self-contained Build"
required: true
type: boolean
default: false
CreateRelease:
description: "Create GitHub Release"
required: true
type: boolean
default: false
name: 🏗️ Build & Release
run-name: 🏗️ Build & Release v${{ github.event.inputs.Version }}
permissions:
contents: write
env:
VERSION: ${{ github.event.inputs.Version }}
SELF_CONTAINED: ${{ github.event.inputs.SelfContained }}
TAG_NAME: v${{ github.event.inputs.CreateRelease }}
jobs:
build:
name: 🏗️ Build v${{ github.event.inputs.Version }}
runs-on: windows-2022
env:
APP_PROJECT_PATH: src\Magdys.ScreenPrivacyWatermark.App\Magdys.ScreenPrivacyWatermark.App.csproj
APP_PROJECT_OUTPUT: _temp\app
MSI_PROJECT_PATH: src/Magdys.ScreenPrivacyWatermark.Setup/Magdys.ScreenPrivacyWatermark.Setup.wixproj
MSI_PROJECT_OUTPUT: _temp\msi
MSI_FILE_NAME: SPW-${{github.event.inputs.Version}}-Setup
steps:
- name: 🦺 Validate version format
run: |
if ('${{ github.event.inputs.Version }}' -notmatch '^\d+\.\d+\.\d+$') {
Write-Output "Version format is invalid."
exit 1
}
- name: 📥 Checkout code
uses: actions/[email protected]
- name: 🛠️ Setup envs
run: |
echo "APP_PROJECT_OUTPUT=${{ runner.temp }}\app" | Out-File -FilePath $env:GITHUB_ENV -Append
echo "MSI_PROJECT_OUTPUT=${{ runner.temp }}\msi" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: 📃 List All env
run: Get-ChildItem env:* | Sort-Object -Property Name
- name: 📦 Cache NuGet packages
uses: actions/[email protected]
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.*proj') }}
restore-keys: |
${{ runner.os }}-nuget-${{ hashFiles('**/*.*proj') }}
- name: 🔄 Restore NuGet Packages
run: dotnet restore src
- name: 🏗️ Build App
if: github.event.inputs.SelfContained == false
run: dotnet publish ${{env.APP_PROJECT_PATH}} -c=Release -o=${{env.APP_PROJECT_OUTPUT}} --p:FileVersion=${{env.VERSION}} --p:AssemblyVersion=${{env.VERSION}} --p:Version=${{env.VERSION}} -p:SourceRevisionId=${{ github.sha }}
- name: 🏗️ Build App (Self-contained)
if: github.event.inputs.SelfContained
run: dotnet publish ${{env.APP_PROJECT_PATH}} -c=Release -o=${{env.APP_PROJECT_OUTPUT}} --p:FileVersion=${{env.VERSION}} --p:AssemblyVersion=${{env.VERSION}} --p:Version=${{env.VERSION}} -r=win-x64 --self-contained=true -p:SourceRevisionId=${{ github.sha }}
- name: 🔧 Setup WiX v5
run: dotnet tool install --global wix
- name: 🏭 Build MSI
run: dotnet build ${{env.MSI_PROJECT_PATH}} -c=Release -o=${{env.MSI_PROJECT_OUTPUT}} -p:Version=${{env.VERSION}} -p:AppDir=${{env.APP_PROJECT_OUTPUT}} -p:OutputName=${{env.MSI_FILE_NAME}} -p:SourceRevisionId=${{ github.sha }}
- name: 📤 Upload a Build Artifact
if: github.event.inputs.CreateRelease == false
uses: actions/[email protected]
with:
name: ${{env.MSI_FILE_NAME}}
path: ${{env.MSI_PROJECT_OUTPUT}}\${{env.MSI_FILE_NAME}}.msi
- name: 🏷️ Create tag ${{ github.event.inputs.Version }}
if: github.event.inputs.CreateRelease
run: |
git tag ${{ github.event.inputs.Version }}
git push origin ${{ github.event.inputs.Version }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 📝 Create release draft ${{ env.TAG_NAME }}
if: github.event.inputs.CreateRelease
run: gh release create ${{ env.TAG_NAME }} --target ${{ github.ref }} --draft --title "${{ env.TAG_NAME }}" --generate-notes --prerelease --draft
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 📤 Upload MSI to release ${{ env.TAG_NAME }}
if: github.event.inputs.CreateRelease
run: gh release upload ${{ env.TAG_NAME }} ${{env.MSI_PROJECT_OUTPUT}}\${{env.MSI_FILE_NAME}}.msi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}