1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2024-12-14 11:57:30 +00:00

Merge pull request #190 from zhaofengli/gha-integration-tests

Move integration tests to GitHub Actions
This commit is contained in:
Zhaofeng Li 2024-10-28 12:29:30 -06:00 committed by GitHub
commit 0fe1b1cd34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 176 additions and 2 deletions

View file

@ -6,6 +6,64 @@ env:
REGISTRY: ghcr.io
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
build:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4.1.7
- name: Install current Bash on macOS
if: runner.os == 'macOS'
run: |
command -v brew && brew install bash || true
- uses: DeterminateSystems/nix-installer-action@v14
continue-on-error: true # Self-hosted runners already have Nix installed
- name: Install Attic
run: |
if ! command -v attic &> /dev/null; then
./.github/install-attic-ci.sh
fi
- name: Configure Attic
continue-on-error: true
run: |
: "${ATTIC_SERVER:=https://staging.attic.rs/}"
: "${ATTIC_CACHE:=attic-ci}"
echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN"
attic use "$ATTIC_CACHE"
env:
ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }}
ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }}
ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }}
- name: Cache dev shell
run: |
.ci/cache-shell.sh
system=$(nix-instantiate --eval -E 'builtins.currentSystem')
echo system=$system >>$GITHUB_ENV
# TODO: Abstract all of this out, and use `attic push --stdin` (requires #232)
- name: Build packages
run: |
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
nix build --no-link --print-out-paths -L \
.#attic \
.#attic-client \
.#attic-server \
| if [ -n "$ATTIC_CACHE" ]; then
xargs attic push "ci:$ATTIC_CACHE"
else
cat
fi
tests:
strategy:
matrix:
@ -67,17 +125,101 @@ jobs:
- name: Push build artifacts
run: |
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
if [ -n "$ATTIC_TOKEN" ]; then
if [ -n "$ATTIC_CACHE" ]; then
nix build --no-link --print-out-paths -L \
.#internalMatrix."$system".\"${{ matrix.nix }}\".attic-tests \
.#internalMatrix."$system".\"${{ matrix.nix }}\".cargoArtifacts \
| xargs attic push "ci:$ATTIC_CACHE"
fi
nix-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4.1.7
- uses: DeterminateSystems/nix-installer-action@v14
continue-on-error: true # Self-hosted runners already have Nix installed
- name: Install Attic
run: |
if ! command -v attic &> /dev/null; then
./.github/install-attic-ci.sh
fi
- name: Configure Attic
continue-on-error: true
run: |
: "${ATTIC_SERVER:=https://staging.attic.rs/}"
: "${ATTIC_CACHE:=attic-ci}"
echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN"
attic use "$ATTIC_CACHE"
env:
ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }}
ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }}
ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }}
- id: set-matrix
name: Generate Nix Matrix
run: |
set -Eeu
matrix="$(nix eval --json '.#githubActions.matrix')"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
nix-matrix-job:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
needs:
- build
- nix-matrix
strategy:
matrix: ${{fromJSON(needs.nix-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v4.1.7
- name: Install current Bash on macOS
if: runner.os == 'macOS'
run: |
command -v brew && brew install bash || true
- uses: DeterminateSystems/nix-installer-action@v14
continue-on-error: true # Self-hosted runners already have Nix installed
- name: Install Attic
run: |
if ! command -v attic &> /dev/null; then
./.github/install-attic-ci.sh
fi
- name: Configure Attic
continue-on-error: true
run: |
: "${ATTIC_SERVER:=https://staging.attic.rs/}"
: "${ATTIC_CACHE:=attic-ci}"
echo ATTIC_CACHE=$ATTIC_CACHE >>$GITHUB_ENV
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
attic login --set-default ci "$ATTIC_SERVER" "$ATTIC_TOKEN"
attic use "$ATTIC_CACHE"
env:
ATTIC_SERVER: ${{ secrets.ATTIC_SERVER }}
ATTIC_CACHE: ${{ secrets.ATTIC_CACHE }}
ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }}
- name: Build ${{ matrix.attr }}
run: |
nix build --no-link --print-out-paths -L '.#${{ matrix.attr }}' \
| if [ -n "$ATTIC_CACHE" ]; then
xargs attic push "ci:$ATTIC_CACHE"
else
cat
fi
image:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs:
- build
- tests
permissions:
contents: read
@ -152,7 +294,7 @@ jobs:
- name: Push build artifacts
run: |
export PATH=$HOME/.nix-profile/bin:$PATH # FIXME
if [ -n "$ATTIC_TOKEN" ]; then
if [ -n "$ATTIC_CACHE" ]; then
nix build --no-link --print-out-paths -L \
.#attic-server-image \
.#attic-server-image-aarch64 \

View file

@ -56,6 +56,26 @@
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1729742964,
"narHash": "sha256-B4mzTcQ0FZHdpeWcpDYPERtyjJd/NIuaQ9+BV1h+MpA=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "e04df33f62cdcf93d73e9a04142464753a16db67",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1726042813,
@ -93,6 +113,7 @@
"crane": "crane",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"nix-github-actions": "nix-github-actions",
"nixpkgs": "nixpkgs",
"nixpkgs-stable": "nixpkgs-stable"
}

View file

@ -15,6 +15,11 @@
inputs.nixpkgs.follows = "nixpkgs";
};
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;

View file

@ -29,6 +29,12 @@ in
};
config = {
flake.githubActions = inputs.nix-github-actions.lib.mkGithubMatrix {
checks = {
inherit (self.checks) x86_64-linux;
};
};
perSystem = { self', pkgs, config, system, ... }: let
cfg = config.attic.integration-tests;