FluentHub PR Validation #221
Workflow file for this run
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
# Copyright (c) 2024 0x5BFA | |
# Licensed under the MIT License. See the LICENSE. | |
name: FluentHub CI | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- 'assets/**' | |
- 'builds/**' | |
- 'docs/**' | |
- '*.md' | |
pull_request: | |
paths-ignore: | |
- 'assets/**' | |
- 'builds/**' | |
- 'docs/**' | |
- '*.md' | |
run-name: ${{ github.event_name == 'pull_request' && 'FluentHub PR Validation' || 'FluentHub CI Validation' }} | |
env: | |
WORKING_DIR: '${{ github.workspace }}' # Default: 'D:\a\FluentHub\FluentHub' | |
APPX_SELFSIGNED_CERT_PATH: '${{ github.workspace }}\.github\workflows\FluentHub_SelfSigned.pfx' | |
ARTIFACTS_STAGING_DIR: '${{ github.workspace }}\artifacts' | |
APPX_PACKAGE_DIR: '${{ github.workspace }}\artifacts\AppxPackages' | |
PACKAGE_PROJECT_DIR: '${{ github.workspace }}\src\FluentHub.Package' | |
PACKAGE_PROJECT_PATH: '${{ github.workspace }}\src\FluentHub.Package\FluentHub.Package.wapproj' | |
APP_CREDENTIALS_PATH: '${{ github.workspace }}\src\FluentHub.App\AppCredentials.config' | |
SOLUTION_PATH: '${{ github.workspace }}\FluentHub.sln' | |
AUTOMATED_TESTS_ARCHITECTURE: 'x64' | |
AUTOMATED_TESTS_CONFIGURATION: 'Release' | |
jobs: | |
check-formatting: | |
if: github.repository_owner == '0x5bfa' | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: pwsh | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Install XamlStyler console | |
run: 'dotnet tool install --global XamlStyler.Console' | |
- name: Check XAML formatting | |
id: check-step | |
run: | | |
$changedFiles = (git diff --diff-filter=d --name-only HEAD~1) -split "\n" | Where-Object {$_ -like "*.xaml"} | |
foreach ($file in $changedFiles) | |
{ | |
xstyler -p -l None -f $file | |
if ($LASTEXITCODE -ne 0) | |
{ | |
echo "::error file=$file::Format check failed" | |
} | |
} | |
continue-on-error: true | |
- name: Fail if necessary | |
if: steps.check-step.outcome == 'failure' | |
run: exit 1 | |
build: | |
if: github.repository_owner == '0x5bfa' | |
runs-on: windows-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
configuration: [Debug, Release] | |
platform: [x64, arm64] | |
env: | |
CONFIGURATION: ${{ matrix.configuration }} | |
ARCHITECTURE: ${{ matrix.platform }} | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
- name: Setup MSBuild | |
uses: microsoft/setup-msbuild@v2 | |
- name: Setup NuGet | |
uses: NuGet/setup-nuget@v2 | |
- name: Setup .NET 8 | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Save base64 credentials into a file | |
shell: pwsh | |
run: | | |
$bytes = [Convert]::FromBase64String($env:GH_CREDENTIALS_SECRET) | |
[IO.File]::WriteAllBytes($env:APP_CREDENTIALS_PATH, $bytes) | |
env: | |
GH_CREDENTIALS_SECRET: '${{ secrets.GH_CREDENTIALS_JSON_BASE64 }}' | |
- name: Restore NuGet | |
shell: pwsh | |
run: 'nuget restore $env:SOLUTION_PATH' | |
- name: Restore FluentHub | |
shell: pwsh | |
run: | | |
msbuild $env:SOLUTION_PATH ` | |
-t:Restore ` | |
-p:Platform=$env:ARCHITECTURE ` | |
-p:Configuration=$env:CONFIGURATION ` | |
-p:PublishReadyToRun=true | |
- if: env.CONFIGURATION != env.AUTOMATED_TESTS_CONFIGURATION || env.ARCHITECTURE != env.AUTOMATED_TESTS_ARCHITECTURE | |
name: Build FluentHub | |
run: | | |
msbuild ` | |
$env:PACKAGE_PROJECT_PATH ` | |
-t:Build ` | |
-clp:ErrorsOnly ` | |
-p:Configuration=$env:CONFIGURATION ` | |
-p:Platform=$env:ARCHITECTURE ` | |
-p:AppxBundle=Never | |
- if: env.CONFIGURATION == env.AUTOMATED_TESTS_CONFIGURATION && env.ARCHITECTURE == env.AUTOMATED_TESTS_ARCHITECTURE | |
name: Create self signed cert as a pfx file | |
run: ./scripts/Generate-SelfCertPfx.ps1 -Destination "$env:APPX_SELFSIGNED_CERT_PATH" | |
- if: env.CONFIGURATION == env.AUTOMATED_TESTS_CONFIGURATION && env.ARCHITECTURE == env.AUTOMATED_TESTS_ARCHITECTURE | |
name: Build & package Files | |
run: | | |
msbuild ` | |
$env:PACKAGE_PROJECT_PATH ` | |
-t:Build ` | |
-t:_GenerateAppxPackage ` | |
-clp:ErrorsOnly ` | |
-p:Configuration=$env:CONFIGURATION ` | |
-p:Platform=$env:ARCHITECTURE ` | |
-p:AppxBundlePlatforms=$env:AUTOMATED_TESTS_ARCHITECTURE ` | |
-p:AppxBundle=Always ` | |
-p:UapAppxPackageBuildMode=SideloadOnly ` | |
-p:AppxPackageDir=$env:APPX_PACKAGE_DIR ` | |
-p:AppxPackageSigningEnabled=true ` | |
-p:PackageCertificateKeyFile=$env:APPX_SELFSIGNED_CERT_PATH ` | |
-p:PackageCertificatePassword="" ` | |
-p:PackageCertificateThumbprint="" | |
- name: Upload the packages to the Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: 'Appx Packages (${{ env.CONFIGURATION }}, ${{ env.ARCHITECTURE }})' | |
path: ${{ env.ARTIFACTS_STAGING_DIR }} | |
- if: env.ARCHITECTURE == env.AUTOMATED_TESTS_ARCHITECTURE && env.CONFIGURATION == env.AUTOMATED_TESTS_CONFIGURATION | |
name: Get artifact size | |
id: get_artifact_size | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
const { data: artifacts } = await github.rest.actions.listArtifactsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
const artifact = artifacts.artifacts.find(a => a.name === 'Appx Packages (${{ env.CONFIGURATION }}, ${{ env.ARCHITECTURE }})'); | |
if (artifact) | |
{ | |
console.log('Artifact Size: ${artifact.size_in_bytes} bytes'); | |
core.setOutput("artifact-size", artifact.size_in_bytes); | |
return "${artifact.size_in_bytes}" | |
} | |
else | |
{ | |
console.log('Artifact not found.'); | |
return "0" | |
} | |
- if: env.ARCHITECTURE == env.AUTOMATED_TESTS_ARCHITECTURE && env.CONFIGURATION == env.AUTOMATED_TESTS_CONFIGURATION | |
name: Display artifact size | |
run: 'echo "Artifact size is ${{ steps.get_artifact_size.outputs.artifact-size }} bytes."' | |
#- if: github.event_name == 'pull_request' && env.ARCHITECTURE == env.AUTOMATED_TESTS_ARCHITECTURE && env.CONFIGURATION == env.AUTOMATED_TESTS_CONFIGURATION | |
# uses: marocchino/sticky-pull-request-comment@v1 | |
# with: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# header: ci-comment | |
# message: 'Artifact size is ${{ steps.get_artifact_size.outputs.artifact-size }} bytes.' |