Skip to content

Commit

Permalink
ci: cache Nix store with cache-nix-action (#2992)
Browse files Browse the repository at this point in the history
* ci: try nix-community/cache-nix-action

* ci: add cache-id param to setup-nix action

* ci: tidy up cache keys for non-nix jobs

* ci: merge-nix-caches-linux job

* ci: merge caches other way around

* ci: reduce number of caches

Should prevent disk overflow

* ci: change cache id prefix for merge

* ci: comment out cache merging job

* ci: revert cache id prefix

* ci: setup-nix: use latest cache-nix-action

Among others, makes action logs look more tidy (see nix-community/cache-nix-action@17d19d3)

* ci: use test-pg cache key for loadtest
  • Loading branch information
develop7 authored Nov 21, 2023
1 parent f7bf215 commit abcb21c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
14 changes: 12 additions & 2 deletions .github/actions/setup-nix/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ inputs:
description: Token to pass to cachix
tools:
description: Tools to install with nix-env -iA <tools>
cache-id:
description: Cache id to use for cache-nix-action
default: "default"

runs:
using: composite
steps:
- uses: cachix/install-nix-action@v23
- uses: nixbuild/nix-quick-install-action@v26
with:
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
nix_version: '2.13.6'
- name: Restore and cache Nix store
uses: nix-community/[email protected]
with:
key: cache-nix-${{ runner.os }}-id-${{ inputs.cache-id }}-${{ hashFiles('nix/**/*.nix') }}
restore-keys: |
cache-nix-${{ runner.os }}-common-
restore-key-hit: true
- uses: cachix/cachix-action@v12
with:
name: postgrest
Expand Down
39 changes: 36 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: style
cache-id: style
- name: Run linter (check locally with `nix-shell --run postgrest-lint`)
run: postgrest-lint
- name: Run style check (auto-format with `nix-shell --run postgrest-style`)
Expand All @@ -42,6 +43,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: tests
cache-id: test-pg

- name: Run coverage (IO tests and Spec tests against PostgreSQL 15)
run: postgrest-coverage
Expand Down Expand Up @@ -77,6 +79,9 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: tests withTools
# It seems like they are installing the same set of derivations, so we can assign them the same cache id.
# This would decrease the amount of caches dowloaded on merge cache step and will prevent disk space issues.
cache-id: test-pg

- name: Run spec tests
if: always()
Expand All @@ -96,6 +101,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: memory
cache-id: test-memory
- name: Run memory tests
run: postgrest-test-memory

Expand All @@ -109,6 +115,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: tests
cache-id: static-nix

- name: Build static executable
run: nix-build -A postgrestStatic
Expand All @@ -130,6 +137,32 @@ jobs:
path: postgrest-docker.tar.gz
if-no-files-found: error

# TODO: Enable this again in a PR by PostgREST admins, because regular users don't have permission to delete cache entries, which this job does.
#
# merge-nix-caches-linux:
# name: "Merge Nix caches (Linux)"
# needs: [Test-Nix, Test-Pg-Nix, Test-Memory-Nix, Build-Static-Nix, Lint-Style]
# runs-on: ubuntu-latest
# strategy:
# max-parallel: 1
# matrix:
# cache-id: ['static-nix', 'test-pg', 'style', 'test-memory']
# steps:
# - uses: actions/checkout@v4
# - uses: nixbuild/nix-quick-install-action@v26
# with:
# nix_version: '2.13.6'
# - name: Restore and cache Nix store
# uses: nix-community/cache-nix-action@v4
# with:
# key: cache-nix-${{ runner.os }}-common-${{ hashFiles('nix/**/*.nix') }}
# extra-restore-keys: |
# cache-nix-${{ runner.os }}-cid-
# purge: true
# purge-keys: |
# cache-nix-${{ runner.os }}-cid-
# cache-nix-${{ runner.os }}-common-
# purge-created-max-age: 0

Build-Macos-Nix:
name: Build MacOS (Nix)
Expand Down Expand Up @@ -180,7 +213,7 @@ jobs:
uses: actions/cache@v3
with:
path: ${{ matrix.cache }}
key: ${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }}
key: cache-stack-${{ runner.os }}-${{ hashFiles('stack.yaml.lock') }}
- name: Install dependencies
if: ${{ matrix.deps }}
run: ${{ matrix.deps }}
Expand Down Expand Up @@ -236,9 +269,9 @@ jobs:
uses: actions/cache@v3
with:
path: ~/.cabal
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
key: cache-cabal-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
restore-keys: |
${{ runner.os }}-${{ matrix.ghc }}-
cache-cabal-${{ runner.os }}-${{ matrix.ghc }}-
- name: Install dependencies
run: |
cabal update
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/loadtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: loadtest
cache-id: test-pg
- uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
with:
Expand Down Expand Up @@ -54,6 +55,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
tools: loadtest
cache-id: test-pg
- name: Run loadtest
run: |
postgrest-loadtest-against ${{ steps.get-latest-tag.outputs.tag }}
Expand Down

0 comments on commit abcb21c

Please sign in to comment.