-
-
Notifications
You must be signed in to change notification settings - Fork 18
137 lines (110 loc) · 4.76 KB
/
Build MSIX sideload package.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Build MSIX package, sign with self-signed certificate, and upload to GitHub action artifacts.
# You can download the MSIX package from artifacts and install it via sideloading.
name: Build MSIX sideload package
on: [push, pull_request, workflow_dispatch]
jobs:
# Create a draft release if there's a tag starting with "v" associated with this commit.
create-draft-release:
runs-on: ubuntu-latest
steps:
- name: Create draft release
if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v')
uses: ncipollo/release-action@v1
with:
draft: true
generateReleaseNotes: true
build:
needs: create-draft-release
runs-on: windows-latest
strategy:
matrix:
configuration: [Release]
platform: [x64, arm64]
env:
SOLUTION_NAME: EnergyStarX.sln
PACKAGE_PROJECT_NAME: EnergyStarX
TEST_PROJECT_NAME: EnergyStarX.Test
CERT_FILE_NAME: GitHubActionsWorkflow.pfx
defaults:
run:
working-directory: ./src
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild@v1.1
- name: Add VSTest to PATH
uses: darenm/Setup-VSTest@v1.2
- name: Restore dependencies
run: dotnet restore $env:SOLUTION_NAME
- name: Build solution
run: |
msbuild $env:SOLUTION_NAME `
/p:Configuration=${{ matrix.configuration }} `
/p:Platform=${{ matrix.platform }}
- name: 🧪 Unit testing
if: matrix.platform == 'x64' # GitHub Action only provides x64 Windows machines, which cannot run cross-compiled ARM64 tests
run: vstest.console.exe ${env:TEST_PROJECT_NAME}\bin\${{ matrix.platform }}\${{ matrix.configuration }}\**\${env:TEST_PROJECT_NAME}.dll
- name: Get MSIX package output directory
run: |
$msixPackageDir = "${{ github.workspace }}\Packages\${{ matrix.platform }}\"
"MSIX_PACKAGE_DIR=$msixPackageDir" >> $env:GITHUB_ENV
# Replace secrets in code, like Visual Studio App Center secret
- name: Replace secrets in code
run: |
function Replace-StringInFile {
param ($filePath, $oldString, $newString)
$file = Get-ChildItem $filePath
$fileContent = Get-Content $file
$matchCount = ($fileContent | Select-String -Pattern $oldString -AllMatches).Matches.Count
$fileContent = $fileContent.Replace($oldString, $newString)
$fileContent > $file
Write-Host "Replaced `"$oldString`" in `"$filePath`" for $matchCount times"
}
Replace-StringInFile ".\EnergyStarX\Constants\Secrets.cs" "{{AppCenterSecret}}" "${{ secrets.APP_CENTER_SECRET }}"
# Decode the Base64 encoded pfx certificate from GitHub secrets and save it to file
- name: Decode the certificate and save it to file
run: |
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.BASE64_ENCODED_PFX }}")
$certificatePath = $env:CERT_FILE_NAME
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
- name: 📦 Build and sign MSIX package
run: |
$certificateAbsolutePath = (Get-Item $env:CERT_FILE_NAME).FullName
msbuild $env:PACKAGE_PROJECT_NAME `
/p:Configuration=${{ matrix.configuration }} `
/p:Platform=${{ matrix.platform }} `
/p:RuntimeIdentifier=win-${{ matrix.platform }} `
`
/p:GenerateAppxPackageOnBuild=true `
/p:AppxPackageDir="$env:MSIX_PACKAGE_DIR" `
/p:AppxBundle=Never `
/p:UapAppxPackageBuildMode=SideloadOnly `
`
/p:AppxPackageSigningEnabled=True `
/p:PackageCertificateKeyFile="$certificateAbsolutePath" `
/p:AppxPackageSigningTimestampDigestAlgorithm=SHA256 `
`
/p:SelfContained=true `
/p:PublishReadyToRun=false
# Remove framework packages not of current platform to reduce artifact size
Get-ChildItem "$env:MSIX_PACKAGE_DIR\*\Dependencies\*" `
| Where-Object -Property Name -NE ${{ matrix.platform }} `
| ForEach-Object { Remove-Item -Recurse $_ }
- name: Delete the certificate file
run: Remove-Item -path $env:CERT_FILE_NAME
- name: Get GitHub action artifact name
run: |
$folderName = (Get-ChildItem $env:MSIX_PACKAGE_DIR)[0].Name
$shortHash = $env:GITHUB_SHA.Substring(0, 7)
$artifactName = "$folderName-$shortHash"
"ARTIFACT_NAME=$artifactName" >> $env:GITHUB_ENV
- name: 🚀 Upload MSIX package to GitHub action artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.MSIX_PACKAGE_DIR }}