Skip to content

chore(treefmt): add treefmt-nix and format codebase #15

chore(treefmt): add treefmt-nix and format codebase

chore(treefmt): add treefmt-nix and format codebase #15

name: Publish Container
on:
workflow_dispatch:
push:
branches: [main]
tags:
- "v*"
paths:
- "src/**"
- "flake.nix"
- "flake.lock"
- "deps.edn"
- "deps-lock.json"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container via Nix
run: nix build .#container
- name: Load image
id: load
run: |
IMG_ID=$(docker load < result | sed 's/^Loaded image: //')
echo "image=$IMG_ID" >> "$GITHUB_OUTPUT"
# Extract semver, branch, sha, etc.
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=branch
- name: Tag + Push
run: |
IMAGE=${{ steps.load.outputs.image }}
TARGET=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# read tags safely (handles spaces/newlines)
echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | while read -r tag; do
echo "Tagging $IMAGE as $tag"
docker tag "$IMAGE" "$tag"
docker push "$tag"
done
# Optionally tag as 'latest' for main branch
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "Tagging $IMAGE as $TARGET:latest"
docker tag "$IMAGE" "$TARGET:latest"
docker push "$TARGET:latest"
fi