Skip to content
/ bits Public

Improve CI

Improve CI #178

Workflow file for this run

name: CI
on:
push:
branches: [main, morph]
pull_request:
branches: [main, morph]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-24.04
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/determinate-nix-action@v3
- uses: DeterminateSystems/flakehub-cache-action@v3
- name: Install devenv
run: nix profile install nixpkgs#devenv
- name: Check formatting
run: devenv shell -- treefmt --fail-on-change
test:
name: Test
runs-on: ubuntu-24.04
permissions:
id-token: write
contents: read
services:
postgres:
image: pgvector/pgvector:pg17
env:
POSTGRES_USER: bits
POSTGRES_PASSWORD: please
POSTGRES_DB: bits_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U bits -d bits_test"
--health-interval 5s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/determinate-nix-action@v3
- uses: DeterminateSystems/flakehub-cache-action@v3
- name: Install devenv
run: nix profile install nixpkgs#devenv
- name: Build devenv shell
run: devenv shell -- echo '🚀 Happy hacking!'
- name: Cache Maven deps
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
~/.deps.clj
key: clj-${{ hashFiles('deps.edn') }}
restore-keys: clj-
- name: Run tests
env:
DATABASE_URL: jdbc:postgresql://localhost:5432/bits_test?user=bits&password=please
run: devenv shell -- clojure -M:test:runner:linux-x86_64
- name: Upload captured browser sessions
if: failure()
uses: actions/upload-artifact@v4
with:
name: browser-sessions
path: target/browser-sessions
if-no-files-found: ignore
build:
name: Build ${{ matrix.arch }}
runs-on: ${{ matrix.runner }}
needs: [lint, test]
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
output: bits-container-amd64
- arch: arm64
runner: ubuntu-24.04-arm64
output: bits-container-arm64
permissions:
id-token: write
contents: read
packages: write
outputs:
version: ${{ steps.tag.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/determinate-nix-action@v3
- uses: DeterminateSystems/flakehub-cache-action@v3
- name: Install devenv
run: nix profile install nixpkgs#devenv
- name: Build container
run: devenv build outputs.${{ matrix.output }}
- name: Get output path
id: build
run: |
image_path=$(devenv build outputs.${{ matrix.output }})
echo "image_path=$image_path" >> "$GITHUB_OUTPUT"
- name: Load and tag image
id: tag
run: |
docker load < "${{ steps.build.outputs.image_path }}"
# Extract version tag (format: YYYYMMDD-sha)
version=$(docker images bits --format '{{.Tag}}' | head -1)
image="ghcr.io/${{ github.repository }}"
docker tag "bits:$version" "$image:$version-${{ matrix.arch }}"
echo "image=$image" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: docker/login-action@v3
if: github.event_name == 'push'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
if: github.event_name == 'push'
run: |
docker push "${{ steps.tag.outputs.image }}:${{ steps.tag.outputs.version }}-${{ matrix.arch }}"
manifest:
name: Create manifest
runs-on: ubuntu-24.04
needs: [build]
if: github.event_name == 'push'
permissions:
packages: write
steps:
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifest
run: |
image="ghcr.io/${{ github.repository }}"
version="${{ needs.build.outputs.version }}"
docker manifest create "$image:$version" \
"$image:$version-amd64" \
"$image:$version-arm64"
docker manifest push "$image:$version"
docker manifest create "$image:latest" \
"$image:$version-amd64" \
"$image:$version-arm64"
docker manifest push "$image:latest"