From 340c7aa4f2e48b54f562cfbc6f1743ac085c5221 Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Wed, 2 Jul 2025 10:26:49 +0200 Subject: [PATCH 1/7] feat: add github actions cache to all templates use `nix-community/cache-nix-action/restore` and `nix-community/cache-nix-action/save` actions to cache Nix store and improve CI performance. --- template/Go/.github/workflows/test.yml | 9 ++++++++- template/Node.js/.github/workflows/test.yml | 10 +++++++++- template/Python/.github/workflows/test.yml | 10 +++++++++- template/Rust/.github/workflows/test.yml | 10 +++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/template/Go/.github/workflows/test.yml b/template/Go/.github/workflows/test.yml index 0bac655..6d32e48 100644 --- a/template/Go/.github/workflows/test.yml +++ b/template/Go/.github/workflows/test.yml @@ -15,7 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v26 + - uses: nixbuild/nix-quick-install-action@v30 + - uses: nix-community/cache-nix-action/restore@v6 + with: + primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 with: name: devenv @@ -24,3 +27,7 @@ jobs: - name: Build the devenv shell and run any pre-commit hooks run: devenv test + - uses: nix-community/cache-nix-action/save@v6 + if: always() + with: + primary-key: ${{ runner.os }}-nix diff --git a/template/Node.js/.github/workflows/test.yml b/template/Node.js/.github/workflows/test.yml index 0bac655..faf954a 100644 --- a/template/Node.js/.github/workflows/test.yml +++ b/template/Node.js/.github/workflows/test.yml @@ -15,7 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v26 + - uses: nixbuild/nix-quick-install-action@v30 + - uses: nix-community/cache-nix-action/restore@v6 + with: + primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 with: name: devenv @@ -24,3 +27,8 @@ jobs: - name: Build the devenv shell and run any pre-commit hooks run: devenv test + + - uses: nix-community/cache-nix-action/save@v6 + if: always() + with: + primary-key: ${{ runner.os }}-nix diff --git a/template/Python/.github/workflows/test.yml b/template/Python/.github/workflows/test.yml index 0bac655..faf954a 100644 --- a/template/Python/.github/workflows/test.yml +++ b/template/Python/.github/workflows/test.yml @@ -15,7 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v26 + - uses: nixbuild/nix-quick-install-action@v30 + - uses: nix-community/cache-nix-action/restore@v6 + with: + primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 with: name: devenv @@ -24,3 +27,8 @@ jobs: - name: Build the devenv shell and run any pre-commit hooks run: devenv test + + - uses: nix-community/cache-nix-action/save@v6 + if: always() + with: + primary-key: ${{ runner.os }}-nix diff --git a/template/Rust/.github/workflows/test.yml b/template/Rust/.github/workflows/test.yml index 0bac655..faf954a 100644 --- a/template/Rust/.github/workflows/test.yml +++ b/template/Rust/.github/workflows/test.yml @@ -15,7 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v26 + - uses: nixbuild/nix-quick-install-action@v30 + - uses: nix-community/cache-nix-action/restore@v6 + with: + primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 with: name: devenv @@ -24,3 +27,8 @@ jobs: - name: Build the devenv shell and run any pre-commit hooks run: devenv test + + - uses: nix-community/cache-nix-action/save@v6 + if: always() + with: + primary-key: ${{ runner.os }}-nix From 06836f06728e8c914545294bd6bdb57caa8798aa Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Wed, 2 Jul 2025 10:27:11 +0200 Subject: [PATCH 2/7] ci(test): add nix cache --- .github/workflows/test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0bac655..faf954a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v26 + - uses: nixbuild/nix-quick-install-action@v30 + - uses: nix-community/cache-nix-action/restore@v6 + with: + primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 with: name: devenv @@ -24,3 +27,8 @@ jobs: - name: Build the devenv shell and run any pre-commit hooks run: devenv test + + - uses: nix-community/cache-nix-action/save@v6 + if: always() + with: + primary-key: ${{ runner.os }}-nix From 4a00a1346ad7bb68e08ceb862d9e7d456ffe03e7 Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Thu, 3 Jul 2025 10:31:42 +0200 Subject: [PATCH 3/7] fix: handle cache updates --- template/Go/.github/workflows/test.yml | 5 +++++ template/Node.js/.github/workflows/test.yml | 5 +++++ template/Python/.github/workflows/test.yml | 5 +++++ template/Rust/.github/workflows/test.yml | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/template/Go/.github/workflows/test.yml b/template/Go/.github/workflows/test.yml index 6d32e48..a1f8c06 100644 --- a/template/Go/.github/workflows/test.yml +++ b/template/Go/.github/workflows/test.yml @@ -8,6 +8,9 @@ on: jobs: tests: + permissions: + actions: write + contents: read strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -31,3 +34,5 @@ jobs: if: always() with: primary-key: ${{ runner.os }}-nix + purge: true + purge-primary-key: always diff --git a/template/Node.js/.github/workflows/test.yml b/template/Node.js/.github/workflows/test.yml index faf954a..27d21ad 100644 --- a/template/Node.js/.github/workflows/test.yml +++ b/template/Node.js/.github/workflows/test.yml @@ -8,6 +8,9 @@ on: jobs: tests: + permissions: + actions: write + contents: read strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -32,3 +35,5 @@ jobs: if: always() with: primary-key: ${{ runner.os }}-nix + purge: true + purge-primary-key: always diff --git a/template/Python/.github/workflows/test.yml b/template/Python/.github/workflows/test.yml index faf954a..27d21ad 100644 --- a/template/Python/.github/workflows/test.yml +++ b/template/Python/.github/workflows/test.yml @@ -8,6 +8,9 @@ on: jobs: tests: + permissions: + actions: write + contents: read strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -32,3 +35,5 @@ jobs: if: always() with: primary-key: ${{ runner.os }}-nix + purge: true + purge-primary-key: always diff --git a/template/Rust/.github/workflows/test.yml b/template/Rust/.github/workflows/test.yml index faf954a..27d21ad 100644 --- a/template/Rust/.github/workflows/test.yml +++ b/template/Rust/.github/workflows/test.yml @@ -8,6 +8,9 @@ on: jobs: tests: + permissions: + actions: write + contents: read strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -32,3 +35,5 @@ jobs: if: always() with: primary-key: ${{ runner.os }}-nix + purge: true + purge-primary-key: always From bee362018a637713e6a11077febb999d86dd0e51 Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Thu, 3 Jul 2025 10:31:51 +0200 Subject: [PATCH 4/7] ci: handle cache updates --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index faf954a..27d21ad 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,9 @@ on: jobs: tests: + permissions: + actions: write + contents: read strategy: matrix: os: [ubuntu-latest, macos-latest] @@ -32,3 +35,5 @@ jobs: if: always() with: primary-key: ${{ runner.os }}-nix + purge: true + purge-primary-key: always From 1bbfbfd90d11f81dcc314219e8cd44cd1299742d Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Thu, 3 Jul 2025 12:37:24 +0200 Subject: [PATCH 5/7] ci: save cache if missing or .locks are changed --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27d21ad..67d6ca8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v30 - uses: nix-community/cache-nix-action/restore@v6 + id: cache-restore with: primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 @@ -32,7 +33,7 @@ jobs: run: devenv test - uses: nix-community/cache-nix-action/save@v6 - if: always() + if: always() && (steps.cache-restore.outputs.hit-primary-key != 'true' || contains(github.event.files, '*.lock')) with: primary-key: ${{ runner.os }}-nix purge: true From 61e420e2bcec3062b3ffe1b9c1d94a5380c4de1a Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Thu, 3 Jul 2025 12:41:11 +0200 Subject: [PATCH 6/7] style: break long line into multiple lines --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 67d6ca8..7994394 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,10 @@ jobs: run: devenv test - uses: nix-community/cache-nix-action/save@v6 - if: always() && (steps.cache-restore.outputs.hit-primary-key != 'true' || contains(github.event.files, '*.lock')) + if: | + always() && + (steps.cache-restore.outputs.hit-primary-key != 'true' || + contains(github.event.files, '*.lock')) with: primary-key: ${{ runner.os }}-nix purge: true From 57d97b4a1113a5a9db7a63f3d593de459b9e06da Mon Sep 17 00:00:00 2001 From: Pejman Yaghmaie Date: Thu, 3 Jul 2025 14:30:59 +0200 Subject: [PATCH 7/7] feat: save cache if missing or .locks are changed --- template/Go/.github/workflows/test.yml | 6 +++++- template/Node.js/.github/workflows/test.yml | 6 +++++- template/Python/.github/workflows/test.yml | 6 +++++- template/Rust/.github/workflows/test.yml | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/template/Go/.github/workflows/test.yml b/template/Go/.github/workflows/test.yml index a1f8c06..959aab3 100644 --- a/template/Go/.github/workflows/test.yml +++ b/template/Go/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v30 - uses: nix-community/cache-nix-action/restore@v6 + id: cache-restore with: primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 @@ -31,7 +32,10 @@ jobs: - name: Build the devenv shell and run any pre-commit hooks run: devenv test - uses: nix-community/cache-nix-action/save@v6 - if: always() + if: | + always() && + (steps.cache-restore.outputs.hit-primary-key != 'true' || + contains(github.event.files, '*.lock')) with: primary-key: ${{ runner.os }}-nix purge: true diff --git a/template/Node.js/.github/workflows/test.yml b/template/Node.js/.github/workflows/test.yml index 27d21ad..7994394 100644 --- a/template/Node.js/.github/workflows/test.yml +++ b/template/Node.js/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v30 - uses: nix-community/cache-nix-action/restore@v6 + id: cache-restore with: primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 @@ -32,7 +33,10 @@ jobs: run: devenv test - uses: nix-community/cache-nix-action/save@v6 - if: always() + if: | + always() && + (steps.cache-restore.outputs.hit-primary-key != 'true' || + contains(github.event.files, '*.lock')) with: primary-key: ${{ runner.os }}-nix purge: true diff --git a/template/Python/.github/workflows/test.yml b/template/Python/.github/workflows/test.yml index 27d21ad..7994394 100644 --- a/template/Python/.github/workflows/test.yml +++ b/template/Python/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v30 - uses: nix-community/cache-nix-action/restore@v6 + id: cache-restore with: primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 @@ -32,7 +33,10 @@ jobs: run: devenv test - uses: nix-community/cache-nix-action/save@v6 - if: always() + if: | + always() && + (steps.cache-restore.outputs.hit-primary-key != 'true' || + contains(github.event.files, '*.lock')) with: primary-key: ${{ runner.os }}-nix purge: true diff --git a/template/Rust/.github/workflows/test.yml b/template/Rust/.github/workflows/test.yml index 27d21ad..7994394 100644 --- a/template/Rust/.github/workflows/test.yml +++ b/template/Rust/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: - uses: actions/checkout@v4 - uses: nixbuild/nix-quick-install-action@v30 - uses: nix-community/cache-nix-action/restore@v6 + id: cache-restore with: primary-key: ${{ runner.os }}-nix - uses: cachix/cachix-action@v14 @@ -32,7 +33,10 @@ jobs: run: devenv test - uses: nix-community/cache-nix-action/save@v6 - if: always() + if: | + always() && + (steps.cache-restore.outputs.hit-primary-key != 'true' || + contains(github.event.files, '*.lock')) with: primary-key: ${{ runner.os }}-nix purge: true