zfin-vestwell/.forgejo/workflows/zig-build.yaml
Emil Lerch cc23a51b44
All checks were successful
Generic zig build / build (push) Successful in 1m22s
Generic zig build / deploy (push) Successful in 15s
CI for binary
2026-08-28 20:20:19 -07:00

92 lines
3.4 KiB
YAML

name: Generic zig build
on:
workflow_dispatch:
push:
branches:
- '*'
env:
BUILD_TARGET: x86_64-linux-musl
BUILD_OPTIMIZATION: ReleaseSafe
BINARY_NAME: zfin-vestwell
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Zig
uses: https://codeberg.org/mlugg/setup-zig@v2.2.1
# Needs network: build.zig.zon pins srf and zfin at git.lerch.org, and
# `zig build` resolves them here. The Docker build itself needs none.
- name: Build project
run: zig build --summary all
# Gates the image: `deploy` has `needs: build`, so a test failure means
# nothing is published.
- name: Run tests
run: zig build test --summary all
# Static musl is what makes the `FROM scratch` runtime image possible.
- name: Package
run: zig build -Dtarget="$BUILD_TARGET" -Doptimize="$BUILD_OPTIMIZATION"
- name: Upload
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARY_NAME }}
path: zig-out/bin/${{ env.BINARY_NAME }}
- name: Notify
uses: https://git.lerch.org/lobo/action-notify-ntfy@v2
if: always() && env.GITEA_ACTIONS == 'true'
with:
host: ${{ secrets.NTFY_HOST }}
topic: ${{ secrets.NTFY_TOPIC }}
status: ${{ job.status }}
user: ${{ secrets.NTFY_USER }}
password: ${{ secrets.NTFY_PASSWORD }}
deploy:
runs-on: ubuntu-latest
container:
image: ghcr.io/catthehacker/ubuntu:act-22.04
needs: build
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.BINARY_NAME }}
# The artifact lands beside the Dockerfile because the image build uses
# `context: docker` -- nothing outside that directory is visible to it.
- name: "Make executable actually executable"
run: chmod 755 ${{ env.BINARY_NAME }} && mv ${{ env.BINARY_NAME }} docker
- name: Get short ref
id: vars
run: echo "shortsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Login to Gitea
uses: docker/login-action@v2
with:
registry: git.lerch.org
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_PUSH }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: docker
push: true
tags: |
git.lerch.org/${{ github.repository }}:${{ steps.vars.outputs.shortsha }}
git.lerch.org/${{ github.repository }}:latest
# The Cronicle event pins an immutable tag rather than tracking `:latest`,
# because `:latest` moves on a push to any branch. Print the tag so it can
# be copied out of the run log when deploying.
- name: Deployable tag
run: |
echo "::notice::deploy tag git.lerch.org/${{ github.repository }}:${{ steps.vars.outputs.shortsha }}"
echo "git.lerch.org/${{ github.repository }}:${{ steps.vars.outputs.shortsha }}"
- name: Notify
uses: https://git.lerch.org/lobo/action-notify-ntfy@v2
if: always()
with:
host: ${{ secrets.NTFY_HOST }}
topic: ${{ secrets.NTFY_TOPIC }}
status: ${{ job.status }}
user: ${{ secrets.NTFY_USER }}
password: ${{ secrets.NTFY_PASSWORD }}