-
Notifications
You must be signed in to change notification settings - Fork 4
60 lines (46 loc) · 1.93 KB
/
nix.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: CI
on:
push:
branches: ["main"] # Only trigger on pushes to the main branch
pull_request:
branches: ["*"]
workflow_dispatch:
jobs:
build:
runs-on: x86_64-linux
steps:
- uses: actions/checkout@v4
- uses: cachix/cachix-action@v15
with:
name: nammayatri
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
skipPush: true
- name: Build all flake outputs
run: om ci
- name: Login to GitHub Container Registry
# if: github.event_name == 'push' && github.event.pull_request.merged == true
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
# if: github.event_name == 'push' && github.event.pull_request.merged == true
run: |
set -euo pipefail
ARG1="${{ github.event.inputs.arg1 }}" # Change to pass an argument if needed
shift 1 || true
# Do a git status, because the docker tag is based on working copy status
git status
docker load -i "$(nix build ".#$ARG1" --print-out-paths --no-update-lock-file)"
IMAGE_NAME="$(nix eval --json .#packages.x86_64-linux."$ARG1".buildArgs | jq -r '"\(.name):\(.tag)"')"
echo "Built and loaded: ${IMAGE_NAME}"
echo "Logging in to Docker Registry"
# Use a temp directory as $HOME, because 'docker login' stores the password insecurely.
HOME="$(mktemp -d)"
export HOME
# Remove the image so it doesn't eat up disk space over time.
trap 'docker rmi "${IMAGE_NAME}"; rm -rf "$HOME"' EXIT
echo "${{ secrets.DOCKER_PASS }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin "${{ secrets.DOCKER_SERVER }}"
docker push "${IMAGE_NAME}"
docker logout "${{ secrets.DOCKER_SERVER }}"