name: build and publish containers

on:
  push:
    branches:
      - main
    paths:
      - "**.nix"
      - flake.lock
  schedule:
    - cron: "0 0 * * 1,3,5"

jobs:
  build:
    runs-on: nixos-latest
    strategy:
      matrix:
        container: [ nixos ]
        version: [ "24.11", "unstable" ]
    steps:
      - name: checkout
        uses: actions/checkout@v4
        with:
          ref: 'main'
      - name: nix package names
        id: pkgs
        run: |
          echo "pkgs-name=${{ matrix.container }}-${{ matrix.version }}" | tr -d . >>"${GITHUB_OUTPUT}"
      - name: build
        uses: actions/nix/build@main
        with:
          package: ${{ steps.pkgs.outputs.pkgs-name }}
          out-link: ${{ steps.pkgs.outputs.pkgs-name }}
      - name: load image into podman
        run: |
          podman load < ${{ steps.pkgs.outputs.pkgs-name }}
      - name: publish image
        uses: actions/push-to-registry@v2
        with:
          image: oci-images/nixos-runner/${{ matrix.container }}
          tags: ${{ matrix.version }}
          registry: git.flyinggecko.org
          username: flyinggecko
          password: ${{ secrets.REGISTRY_TOKEN }}