Files
Hearth/.github/workflows/ci.yml
T
Greboh 232bd1a4de
ci / build (push) Successful in 48s
ci / image (push) Successful in 1m27s
fix: pipeline
2026-11-08 15:24:20 +01:00

99 lines
3.7 KiB
YAML

name: ci
# Runs on Gitea Actions (git.greboh.dev), which reads .github/workflows when .gitea/workflows does not exist.
# Pull requests: build, test and build the image without pushing.
# Push to master (direct or merged PR) or a manual run on master: release.
# GitVersion picks the next version (patch by default, "+semver: minor|major" in a commit message for more),
# the image is pushed as <version> and latest, and the git tag v<version> is pushed so the next release counts from it.
# Argo CD Image Updater (infrastructure repo) deploys the newest <version>; nothing is committed back.
# Releases run one at a time because the runner runs one job at a time (capacity 1), so each one
# computes its version after the previous one pushed its tag.
on:
push:
branches: [master]
paths-ignore: [deploy/**, '**.md']
pull_request:
branches: [master]
workflow_dispatch:
env:
IMAGE: git.greboh.dev/greboh/hearth-api
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
# Inside the runner's shared tool cache, so the SDK and packages carry over between runs.
DOTNET_INSTALL_DIR: /opt/hostedtoolcache/dotnet
NUGET_PACKAGES: /opt/hostedtoolcache/nuget
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
# global.json (SDK pin, Microsoft Testing Platform runner) lives in src/
working-directory: src
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
# Hearth.Api references every module, so this compiles everything that ships.
# The AppHost (local dev only) is skipped: its Aspire packages are hundreds of MB per restore.
- run: dotnet build Hosts/Hearth.Api/Hearth.Api.csproj -c Release
- name: Run tests
run: |
mapfile -t projects < <(git ls-files '*Tests.csproj')
if [ ${#projects[@]} -eq 0 ]; then
echo "No test projects found"
exit 0
fi
for project in "${projects[@]}"; do
dotnet test "$project" -c Release
done
image:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
env:
RELEASE: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# GitVersion is a .NET tool; Gitea's runner image has no .NET.
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- uses: gittools/actions/gitversion/setup@v4
with:
versionSpec: 6.x
- id: gitversion
uses: gittools/actions/gitversion/execute@v4
# The built-in token cannot push to the package registry; REGISTRY_TOKEN is a personal access token with write:package.
- uses: docker/login-action@v3
if: env.RELEASE == 'true'
with:
registry: git.greboh.dev
username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
# Default docker builder on the runner's Docker-in-Docker daemon: its layer cache carries over between jobs.
- uses: docker/build-push-action@v6
with:
context: .
push: ${{ env.RELEASE == 'true' }}
tags: |
${{ env.IMAGE }}:${{ steps.gitversion.outputs.majorMinorPatch }}
${{ env.IMAGE }}:latest
- name: Push release tag
if: env.RELEASE == 'true'
env:
TAG: v${{ steps.gitversion.outputs.majorMinorPatch }}
run: |
if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null; then
echo "$TAG already exists"
exit 0
fi
git tag "$TAG" "$GITHUB_SHA"
git push origin "$TAG"