Skip to content

Commit

Permalink
添加workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Poker-sang committed Sep 19, 2024
1 parent bd827af commit 9bc7c1b
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: WinUI3Utilities Build Pipeline

on:
push:
branches-ignore:
- 'dependabot**'
tags-ignore:
- '**'
pull_request:
paths-ignore:
- '**.md'
- '.builds/**'
- '.specs/**'
schedule:
- cron: '0 0 * * *'

defaults:
run:
shell: pwsh

jobs:
build:
runs-on: windows-latest

strategy:
fail-fast: true
matrix:
configuration: [Release]
platform: ['x64','x86','arm64']

env:
SOLUTION_NAME: 'WinUI3Utilities.sln'
PACKAGE_PROJECT_NAME: 'WinUI3Utilities.Samples/WinUI3Utilities.Samples.csproj'
PROJECT_RESTORE_PLATFORM: "x64"
CONFIGURATION: ${{ matrix.configuration }}
PLATFORM: ${{ matrix.platform }}
DEFAULT_DIR: ${{ github.workspace }} # Default: D:\a\WinUI3Utilities.Samples\WinUI3Utilities.Samples\
APPX_PACKAGE_DIR: ${{ github.workspace }}\AppxPackages
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup MSBuild
id: setup_msbuild
uses: microsoft/setup-msbuild@v1

- name: Setup NuGet
id: setup-nuget
uses: NuGet/setup-nuget@v1.1.1

- name: Setup .NET 8
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

- name: Restore Files
id: restore_project
shell: pwsh
run: |
msbuild $env:SOLUTION_NAME `
-t:Restore `
-p:Platform=$env:PROJECT_RESTORE_PLATFORM `
-p:Configuration=$env:CONFIGURATION `
-p:PublishReadyToRun=true `
- name: Restore NuGet
id: restore_nuget
shell: pwsh
run: 'nuget restore $env:SOLUTION_NAME'

- name: Build Files (Release)
id: build_app_with_release
shell: pwsh
run: |
msbuild $env:PACKAGE_PROJECT_NAME `
-t:Build `
-p:Platform=$env:PLATFORM `
-p:Configuration=$env:CONFIGURATION `
-p:AppxBundle=Never `
48 changes: 48 additions & 0 deletions .github/workflows/check-xaml-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check XAML Formatting
on:
workflow_dispatch:
push:
branches:
- 'main'
- 'service/**'
paths:
- '**.xaml'
pull_request:
branches:
- 'main'
- 'service/**'
paths:
- '**.xaml'

jobs:
check-formatting:
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Install Xaml Styler
run: |
dotnet tool install --global XamlStyler.Console
- name: Check 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 job if necessary
if: steps.check-step.outcome == 'failure'
run: exit 1
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

defaults:
run:
shell: pwsh

jobs:
create_release:
name: Create release
outputs:
release_upload_url: ${{ steps.create_release.outputs.upload_url }}

runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create release
id: create_release
uses: shogo82148/actions-create-release@v1
with:
tag_name: ${{ github.ref_name }}
release_name: WinUI3Utilities ${{ github.ref_name }}

- name: Update release asset
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./WinUI3Utilities_PublicKey.cer

build:
needs: create_release
strategy:
matrix:
platform: ['x64','x86','arm64']

runs-on: windows-2022

env:
private_key: ${{ secrets.PRIVATE_KEY }}
private_key_thumbprint: ${{ secrets.PRIVATE_KEY_THUMBPRINT }}
private_key_password: ${{ secrets.PRIVATE_KEY_PASSWORD }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v2
with:
global-json-file: global.json
include-prerelease: true

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
with:
vs-prerelease: true

- name: Install pfx
run: |
[io.file]::WriteAllBytes("$PWD/temp.pfx",[convert]::FromBase64String($env:private_key))
Import-PfxCertificate -FilePath $PWD/temp.pfx -CertStoreLocation Cert:\CurrentUser\My -Password (ConvertTo-SecureString -AsPlainText "$env:private_key_password")
Remove-Item -Path "$PWD/temp.pfx"
- uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Restore the application
run: msbuild -t:restore -p:Platform=${{ matrix.platform }} -p:RestoreLockedMode=true -m

- name: Publish the application
run: msbuild -t:publish -p:Configuration=Release -p:Platform=${{ matrix.platform }} -p:GenerateAppxPackageOnBuild=true -p:PackageCertificateThumbprint="$env:private_key_thumbprint" -p:OutDir="$PWD\build" -m

- name: Copy files
run: |
$files = @(Get-ChildItem -Recurse|Where-Object -Property Name -Like WinUI3Utilities*.msix)
Copy-Item $files -Destination (New-Item -Path ./output -ItemType Directory -ErrorAction SilentlyContinue)
- name: Upload release asset
id: upload-release-asset1
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.create_release.outputs.release_upload_url }}
asset_path: ./output/*
Binary file added WinUI3Utilities_PublicKey.cer
Binary file not shown.

0 comments on commit 9bc7c1b

Please sign in to comment.