Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 285 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
DESKTOP_PROJECT: Letra200bSharp.Avalonia.Desktop/Letra200bSharp.Avalonia.Desktop.csproj
ANDROID_PROJECT: Letra200bSharp.Avalonia.Android/Letra200bSharp.Avalonia.Android.csproj

LIBRARY_PROJECTS: >-
Letra200bSharp/Letra200bSharp.csproj
Letra200bSharp.200b/Letra200bSharp.200b.csproj
FEED_URL: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json

# Stages: Resolve Version -> Test (Linux, Windows, macOS) -> Pack NuGet
# -> Build (Windows, Linux, Android apps)
# -> Build docs
# -> Pre-release (pull requests) / Tag & Release (main)
# -> on a new release: Publish to GitHub Packages, Publish to nuget.org, Deploy docs
# Pre-release and release need every test, package and app build to succeed.
jobs:
version:
name: Resolve Version
runs-on: ubuntu-latest
outputs:
# Full version stamped into the build and artifact names: "1.5.0" on main,
# "1.5.0-pr.12.34" (PR number, workflow run number) on a pull request.
# Full version stamped into the build and artifact names: "2.0.0" on main,
# "2.0.0-pr.12.34" (PR number, workflow run number) on a pull request.
version: ${{ steps.resolve.outputs.version }}
version_prefix: ${{ steps.resolve.outputs.version_prefix }}
version_suffix: ${{ steps.resolve.outputs.version_suffix }}
Expand Down Expand Up @@ -83,6 +93,184 @@ jobs:

echo "### Version \`$VERSION\`" >> "$GITHUB_STEP_SUMMARY"

test:
name: Test (${{ matrix.name }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
checks: write # trx-parser publishes a check run per TRX file
strategy:
fail-fast: false
matrix:
include:
- name: Linux
os: ubuntu-latest
- name: Windows
os: windows-latest
- name: macOS
os: macos-latest

steps:
- uses: actions/checkout@v7
with:
persist-credentials: false

- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: 'ga'

- name: Cache NuGet
uses: actions/cache@v6
with:
path: ${{ env.NUGET_PACKAGES }}
key: nuget-test-${{ runner.os }}-${{ hashFiles('**/*.csproj', 'Directory.Packages.props', 'Directory.Build.props', 'BuildVersion.props') }}
restore-keys: nuget-test-${{ runner.os }}-

# Protocol (including the ESC sequence-number regression), driver registration, the
# renderer's features and history compatibility. net10.0 only, so no workload is needed.
- name: Test
shell: bash
run: |
dotnet test --project Letra200bSharp.Tests \
-c Release \
-p:TargetFrameworks=net10.0 \
--results-directory TestResults \
--report-trx \
--report-trx-filename "${{ matrix.name }}.trx"

- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: test-results-${{ matrix.name }}
path: |
TestResults/*.trx
TestResults/*.html
if-no-files-found: warn

# A fork's pull request gets a read-only token, which can't create check runs.
- name: Publish test reports
if: >-
always() && hashFiles('TestResults/*.trx') != '' &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: NasAmin/trx-parser@c720607ac80bcd6124fcb482e96e0bfe159f5b2f # v0.8.1
with:
TRX_PATH: ${{ github.workspace }}/TestResults
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPORT_PREFIX: ${{ matrix.name }}

pack:
name: Pack NuGet
runs-on: ubuntu-latest
needs: [version, test]
env:
VERSION_SUFFIX: ${{ needs.version.outputs.version_suffix }}

steps:
- uses: actions/checkout@v7
with:
persist-credentials: false

- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: 'ga'

- name: Cache NuGet
uses: actions/cache@v6
with:
path: ${{ env.NUGET_PACKAGES }}
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', 'Directory.Packages.props', 'Directory.Build.props', 'BuildVersion.props') }}
restore-keys: nuget-${{ runner.os }}-

# The LetraTag 200B driver also targets net10.0-android.
- name: Install android workload
run: dotnet workload install android

- name: Pack
run: |
for PROJECT in $LIBRARY_PROJECTS; do
dotnet pack "$PROJECT" \
-c Release \
-o artifacts \
-p:VersionSuffix="$VERSION_SUFFIX" \
-p:ContinuousIntegrationBuild=true \
-p:EnableWindowsTargeting=true
done
ls -lh artifacts

- name: Upload NuGet artifact
uses: actions/upload-artifact@v7
with:
name: nupkg
path: |
artifacts/*.nupkg
artifacts/*.snupkg
if-no-files-found: error

docs:
name: Build docs
runs-on: ubuntu-latest
needs: [version]

steps:
- uses: actions/checkout@v7
with:
persist-credentials: false

- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: 'ga'

- name: Cache NuGet
uses: actions/cache@v6
with:
path: ${{ env.NUGET_PACKAGES }}
key: nuget-docs-${{ runner.os }}-${{ hashFiles('**/*.csproj', 'Directory.Packages.props', 'Directory.Build.props', 'BuildVersion.props', 'dotnet-tools.json') }}
restore-keys: nuget-docs-${{ runner.os }}-

# DocFX reads the API reference from the built libraries and their XML docs (see
# docs/docfx.json) - net10.0 only, so no workload is needed.
- name: Build libraries
run: |
dotnet build Letra200bSharp.200b/Letra200bSharp.200b.csproj \
-c Release \
-p:TargetFrameworks=net10.0 \
-p:CopyLocalLockFileAssemblies=true

- name: Build site
run: |
dotnet tool restore
dotnet docfx docs/docfx.json --warningsAsErrors

- name: Upload site
uses: actions/upload-pages-artifact@v5
with:
path: docs/_site

# Published with each new release, so the site always documents the released packages.
deploy-docs:
name: Deploy docs
runs-on: ubuntu-latest
needs: [version, docs, release]
if: needs.version.outputs.tag_exists != 'true'
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}

steps:
- name: Deploy to GitHub Pages
id: deploy
uses: actions/deploy-pages@v5

build-windows:
name: Build Windows (${{ matrix.rid }})
runs-on: windows-latest
Expand Down Expand Up @@ -289,7 +477,7 @@ jobs:
prerelease:
name: PR Pre-release
runs-on: ubuntu-latest
needs: [version, build-windows, build-linux, build-android]
needs: [version, test, pack, build-windows, build-linux, build-android]
# Same-repository PRs only. A fork's pull_request run gets a read-only token, and this
# deliberately doesn't use pull_request_target: that would run untrusted fork code with a
# write token. Fork PRs still build and upload workflow artifacts, just no GitHub pre-release.
Expand Down Expand Up @@ -325,7 +513,7 @@ jobs:
- name: Collect pre-release assets
run: |
mkdir -p release
find dist -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.apk' \) \
find dist -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.apk' -o -name '*.nupkg' -o -name '*.snupkg' \) \
-exec cp {} release/ \;
cd release
sha256sum * > SHA256SUMS
Expand All @@ -334,7 +522,7 @@ jobs:
- name: Attest build provenance
uses: actions/attest-build-provenance@v4
with:
subject-path: 'release/*.zip, release/*.tar.gz, release/*.apk'
subject-path: 'release/*.zip, release/*.tar.gz, release/*.apk, release/*.nupkg, release/*.snupkg'

# One pre-release per PR, replaced on every push so testers always have a single, current
# link. Each run gets its own tag (pr-<N>-<run>-<attempt>): the repository uses immutable
Expand Down Expand Up @@ -395,7 +583,7 @@ jobs:
release:
name: Tag & Release
runs-on: ubuntu-latest
needs: [version, build-windows, build-linux, build-android]
needs: [version, test, pack, build-windows, build-linux, build-android]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
permissions:
contents: write
Expand All @@ -416,7 +604,7 @@ jobs:
- name: Collect release assets
run: |
mkdir -p release
find dist -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.apk' \) \
find dist -type f \( -name '*.zip' -o -name '*.tar.gz' -o -name '*.apk' -o -name '*.nupkg' -o -name '*.snupkg' \) \
-exec cp {} release/ \;
ls -lh release

Expand All @@ -429,7 +617,7 @@ jobs:
- name: Attest build provenance
uses: actions/attest-build-provenance@v4
with:
subject-path: 'release/*.zip, release/*.tar.gz, release/*.apk'
subject-path: 'release/*.zip, release/*.tar.gz, release/*.apk, release/*.nupkg, release/*.snupkg'

- name: Tag release
id: tag
Expand Down Expand Up @@ -466,7 +654,7 @@ jobs:
DESCRIPTION="Version v$VERSION already released — bump <VersionPrefix> in BuildVersion.props, or add [no-new-version] to the commit message."
elif [ "${{ steps.gh_release.outcome }}" = "success" ]; then
STATE=success
DESCRIPTION="Released v$VERSION with Windows, Linux and Android artifacts."
DESCRIPTION="Released v$VERSION with the apps and the NuGet packages."
else
STATE=failure
DESCRIPTION="Release failed with an unexpected error."
Expand All @@ -475,3 +663,90 @@ jobs:
-f state="$STATE" \
-f description="$DESCRIPTION" \
-f context="release"

publish-github:
name: Publish to GitHub Packages
runs-on: ubuntu-latest
needs: [version, release]
if: needs.version.outputs.tag_exists != 'true'
permissions:
packages: write

steps:
- name: Download NuGet artifact
uses: actions/download-artifact@v8
with:
name: nupkg
path: nupkg

- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: 'ga'

# The same packages attested and attached in the release job.
- name: Push to GitHub Packages
run: |
dotnet nuget push "nupkg/*.nupkg" \
--source "$FEED_URL" \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate

# nuget.org with Trusted Publishing (https://www.nuget.org/account/trustedpublishing): the
# workflow's OIDC token is exchanged for a short-lived API key, so no key is ever stored. Set the
# repository variable NUGET_USER to the nuget.org account owning the trusted publishing policy
# for this workflow (ci.yml); without it, skip.
publish-nuget:
name: Publish to nuget.org
runs-on: ubuntu-latest
needs: [version, release]
if: needs.version.outputs.tag_exists != 'true'
permissions:
id-token: write # nuget.org Trusted Publishing
env:
NUGET_USER: ${{ vars.NUGET_USER }}

steps:
- name: Check configuration
id: config
run: |
if [ -n "$NUGET_USER" ]; then
echo "enabled=true" >> "$GITHUB_OUTPUT"
else
echo "::warning::The NUGET_USER repository variable isn't configured - skip nuget.org"
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi

- name: Download NuGet artifact
if: steps.config.outputs.enabled == 'true'
uses: actions/download-artifact@v8
with:
name: nupkg
path: nupkg

- name: Setup .NET
if: steps.config.outputs.enabled == 'true'
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: 'ga'

- name: Log in to nuget.org
id: login
if: steps.config.outputs.enabled == 'true'
uses: NuGet/login@v1
with:
user: ${{ env.NUGET_USER }}

# The .snupkg symbol packages next to each .nupkg are pushed with it.
- name: Push to nuget.org
if: steps.config.outputs.enabled == 'true'
env:
API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
run: |
dotnet nuget push "nupkg/*.nupkg" \
--source https://api.nuget.org/v3/index.json \
--api-key "$API_KEY" \
--skip-duplicate
echo "### nuget.org: pushed $(ls nupkg/*.nupkg | xargs -n1 basename | tr '\n' ' ')" >> "$GITHUB_STEP_SUMMARY"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# Test reports (dotnet test --results-directory TestResults)
TestResults/
4 changes: 2 additions & 2 deletions BuildVersion.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<!-- The release version: bump this, and merging to main tags and publishes vX.Y.Z.
CI passes a pre-release VersionSuffix for pull request builds (pr.12.34 -> 1.6.0-pr.12.34). -->
<VersionPrefix>1.7.0</VersionPrefix>
CI passes a pre-release VersionSuffix for pull request builds (pr.12.34 -> 2.0.0-pr.12.34). -->
<VersionPrefix>2.0.0</VersionPrefix>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>

Expand Down
Loading
Loading