Skip to content

Commit

Permalink
ci: Share cache between loadtest and other tests
Browse files Browse the repository at this point in the history
This puts all those development tools that depend on the dynamically linked postgrestPackage
into a single cache group. Notably this now includes the loadtest, but does not include the
style/lint job anymore.

This also improves the creation of cache keys and their restore prefixes. The cache key
now depends on default.nix and shell.nix in the root folder and all .patch files in the
nix folder. Those may change the output of our nix derivations, so must be included. At
the same time, there is no reason to include the actions/setup-nix folder. This would
only lead to new caches being created every time we update one of the depndent actions
in this file. Finally, restoring caches from a different toolset makes zero sense, so
we remove that again. There is no point in having the style job fall back to the static
cache for example.
  • Loading branch information
wolfgangwalther committed Feb 6, 2024
1 parent 65c5c99 commit 742268e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
14 changes: 6 additions & 8 deletions .github/actions/setup-nix/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@ description: Installs nix, sets up cachix and installs a subset of tooling.
inputs:
authToken:
description: Token to pass to cachix
cache:
description: Cache id to use for cache-nix-action
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: nixbuild/nix-quick-install-action@v26
with:
nix_version: '2.13.6'
- name: Restore and cache Nix store
- name: Restore and save /nix/store cache
if: ${{ inputs.cache }}
uses: nix-community/[email protected]
with:
key: cache-nix-${{ runner.os }}-id-${{ inputs.cache-id }}-${{ hashFiles('nix/**/*.nix', '.github/actions/setup-nix/*') }}
key: cache-nix-${{ runner.os }}-${{ inputs.cache }}-${{ hashFiles('**/*.nix', 'nix/**/*.patch') }}
restore-keys: |
cache-nix-${{ runner.os }}-id-${{ inputs.cache-id }}-
cache-nix-${{ runner.os }}-id-common-
cache-nix-${{ runner.os }}-
cache-nix-${{ runner.os }}-${{ inputs.cache }}-
- uses: cachix/cachix-action@v14
with:
name: postgrest
Expand Down
30 changes: 17 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ concurrency:

jobs:
Prepopulate-Nix-Cache-Linux:
name: Prepopulate Nix cache for Linux runners
name: Prepopulate Nix "test" cache for Linux runners
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Nix Environment
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache-id: common
tools: style withTools memory tests release postgrestPackage
cache: test
tools: loadtest memory postgrestPackage tests withTools

Lint-Style:
name: Lint & check code style
Expand All @@ -40,8 +40,8 @@ jobs:
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache: style
tools: style
cache-id: common
- 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 @@ -63,8 +63,8 @@ jobs:
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache: test
tools: tests
cache-id: common

- name: Run coverage (IO tests and Spec tests against PostgreSQL 15)
run: postgrest-coverage
Expand Down Expand Up @@ -101,8 +101,8 @@ jobs:
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache: test
tools: tests withTools
cache-id: common

- name: Run spec tests
if: always()
Expand All @@ -123,8 +123,8 @@ jobs:
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache: test
tools: memory
cache-id: common
- name: Run memory tests
run: postgrest-test-memory

Expand All @@ -139,8 +139,8 @@ jobs:
- name: Setup Nix Environment
uses: ./.github/actions/setup-nix
with:
cache: test
tools: loadtest
cache-id: test-loadtest
- uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
with:
Expand All @@ -166,6 +166,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache: static

- name: Build static executable
run: nix-build -A postgrestStatic
Expand Down Expand Up @@ -194,6 +195,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
cache: all

- name: Build everything
run: |
Expand Down Expand Up @@ -503,11 +505,13 @@ jobs:
ISPRERELEASE: ${{ needs.Prepare-Release.outputs.isprerelease }}
steps:
- uses: actions/checkout@v4
- name: Setup Nix Environment
uses: ./.github/actions/setup-nix
with:
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
tools: release
# Only used for dockerhub description?
# - name: Setup Nix Environment
# uses: ./.github/actions/setup-nix
# with:
# authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
# cache: release
# tools: release
- name: Download Docker image
uses: actions/download-artifact@v4
with:
Expand Down

0 comments on commit 742268e

Please sign in to comment.