92 lines
3.4 KiB
YAML
92 lines
3.4 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
|
|
|
|
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
|
|
- 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"
|