Skip to content

Commit 1d2246b

Browse files
committed
Add a github workflow that runs on all pushes
1 parent db7b51e commit 1d2246b

File tree

4 files changed

+181
-1
lines changed

4 files changed

+181
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Cache Nix
2+
description: Cache Nix to speedup future workflow runs
3+
4+
inputs:
5+
cache-id:
6+
description: A unique ID to differentiate caches
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- shell: bash
13+
run: |
14+
sudo systemctl stop nix-daemon
15+
sudo chown -R "${USER}:" /nix
16+
17+
sudo mkdir -p /tmp/nix-cache
18+
19+
if [ -d /nix/store ]; then
20+
sudo cp -r /nix/store /tmp/nix-cache/
21+
fi
22+
23+
if [ -d /nix/var/nix/db ]; then
24+
sudo mkdir -p /tmp/nix-cache/var/nix
25+
sudo cp -r /nix/var/nix/db /tmp/nix-cache/var/nix/
26+
fi
27+
28+
if [ -d /nix/var/nix/profiles ]; then
29+
sudo mkdir -p /tmp/nix-cache/var/nix
30+
sudo cp -r /nix/var/nix/profiles /tmp/nix-cache/var/nix/
31+
fi
32+
33+
sudo chown -R "${USER}:" /tmp/nix-cache
34+
sudo rm -rf /nix
35+
36+
- uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684
37+
with:
38+
path: /tmp/nix-cache
39+
key: nix-cache-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ inputs.cache-id }}-${{ hashFiles('**/flake.lock') }}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Setup Nix
2+
description: Setup Nix, with caching support, to speed up future workflow runs
3+
4+
inputs:
5+
cache-id:
6+
description: A unique ID to differentiate caches
7+
required: true
8+
9+
outputs:
10+
was-cached:
11+
description: Whether the cache was restored or not
12+
value: ${{ steps.nix-restore-and-save.outputs.cache-hit == 'true' || steps.nix-restore.outputs.cache-hit == 'true' }}
13+
14+
runs:
15+
using: composite
16+
steps:
17+
# This step runs ONLY on scheduled workflows.
18+
# It both restores existing cache AND saves updated cache when the job completes.
19+
- name: Restore and Save Nix Cache
20+
id: nix-restore-and-save
21+
if: ${{ github.event_name == 'schedule' }}
22+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
23+
with:
24+
path: /tmp/nix-cache
25+
key: nix-cache-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ inputs.cache-id }}-${{ hashFiles('**/flake.lock') }}
26+
27+
# This step runs on NON-scheduled events.
28+
# It only restores existing cache without saving updates.
29+
# This prevents cache thrashing on every PR.
30+
- name: Restore Nix Cache
31+
id: nix-restore
32+
if: ${{ github.event_name != 'schedule' }}
33+
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684
34+
with:
35+
path: /tmp/nix-cache
36+
key: nix-cache-${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ inputs.cache-id }}-${{ hashFiles('**/flake.lock') }}
37+
38+
- name: Setup Nix from Cache
39+
if: ${{ steps.nix-restore-and-save.outputs.cache-hit == 'true' || steps.nix-restore.outputs.cache-hit == 'true' }}
40+
shell: bash
41+
run: |
42+
set -ex
43+
sudo mkdir -p /nix
44+
sudo chown -R "${USER}:" /nix
45+
46+
sudo mkdir -p /etc/nix
47+
echo "extra-experimental-features = flakes nix-command" > nix.conf
48+
sudo mv nix.conf /etc/nix/nix.conf
49+
50+
# Restore nix directories from cache
51+
if [ -d /tmp/nix-cache/store ]; then
52+
sudo cp -r /tmp/nix-cache/store /nix/
53+
fi
54+
55+
if [ -d /tmp/nix-cache/var ]; then
56+
sudo cp -r /tmp/nix-cache/var /nix/
57+
fi
58+
59+
echo "/nix/var/nix/profiles/per-user/root/profile/bin" >> $GITHUB_PATH
60+
echo "/nix/var/nix/profiles/default/bin" >> $GITHUB_PATH
61+
62+
sudo chown -R "${USER}:" /nix
63+
64+
- name: Install Nix
65+
if: ${{ steps.nix-restore-and-save.outputs.cache-hit != 'true' && steps.nix-restore.outputs.cache-hit != 'true' }}
66+
uses: DeterminateSystems/nix-installer-action@3ebd1aebb47f95493b62de6eec0cac3cd74e50a9

.github/workflows/all.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: All
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
merge_group:
8+
pull_request:
9+
push:
10+
branches:
11+
- main
12+
schedule:
13+
- cron: "0 0 * * *"
14+
workflow_dispatch:
15+
inputs:
16+
commit_sha:
17+
description: Git commit sha, on which, to run this workflow
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
21+
cancel-in-progress: true
22+
23+
defaults:
24+
run:
25+
shell: nix develop ./tools/nix --command bash {0}
26+
27+
jobs:
28+
lint-spacing-and-indentation:
29+
name: All - lint-spacing-and-indentation
30+
runs-on: ubuntu-24.04
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
34+
with:
35+
ref: ${{ github.event.inputs.commit_sha }}
36+
37+
- name: Setup Nix
38+
id: setup-nix
39+
uses: ./.github/actions/setup_nix
40+
with:
41+
cache-id: all
42+
43+
- name: Lint Spacing and Indentation
44+
run: make lint-spacing-and-indentation
45+
46+
- name: Cache Nix
47+
uses: ./.github/actions/cache_nix
48+
if: ${{ steps.setup-nix.outputs.was-cached != 'true' }}
49+
with:
50+
cache-id: all
51+
52+
lint-commit-messages:
53+
name: All - lint-commit-messages
54+
runs-on: ubuntu-24.04
55+
steps:
56+
- name: Checkout
57+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
58+
with:
59+
ref: ${{ github.event.inputs.commit_sha }}
60+
61+
- name: Setup Nix
62+
id: setup-nix
63+
uses: ./.github/actions/setup_nix
64+
with:
65+
cache-id: all
66+
67+
- name: Lint Commit Messages
68+
run: make lint-commit-messages
69+
70+
- name: Cache Nix
71+
uses: ./.github/actions/cache_nix
72+
if: ${{ steps.setup-nix.outputs.was-cached != 'true' }}
73+
with:
74+
cache-id: all

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ lint-spacing-and-indentation:
1919
# Lint commit message conventions defined in
2020
# the ./tools/commitlint/commitlint.config.js file.
2121
lint-commit-messages:
22-
commitlint --edit --config ./tools/commitlint/commitlint.config.js
22+
commitlint --config ./tools/commitlint/commitlint.config.js \
23+
--from $$(git rev-list --max-parents=0 HEAD) --to HEAD
2324

2425
.PHONY: default help lint lint-spacing-and-indentation lint-commit-messages

0 commit comments

Comments
 (0)