New Crowdin updates #397
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
# 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/[email protected] | |
- name: Add VSTest to PATH | |
uses: darenm/[email protected] | |
- 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 }} |