ci: optimize workflow with paths-filter and workspace-aware gates
This commit is contained in:
parent
d3d74995e8
commit
1b9ed0cd22
2 changed files with 91 additions and 52 deletions
140
.github/workflows/nix.yml
vendored
140
.github/workflows/nix.yml
vendored
|
|
@ -2,69 +2,105 @@ name: Nix CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
branches: [ master ]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
flake-check:
|
# Detect which workspaces have changed to save CI minutes
|
||||||
|
filter:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
workspaces: ${{ steps.filter.outputs.changes }}
|
||||||
|
any_changed: ${{ steps.filter.outputs.workspaces_any_changed }}
|
||||||
|
global_changed: ${{ steps.filter.outputs.global }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: DeterminateSystems/nix-installer-action@v11
|
- uses: dorny/paths-filter@v3
|
||||||
- uses: DeterminateSystems/magic-nix-cache-action@v8
|
id: filter
|
||||||
- name: Nix flake check
|
|
||||||
run: nix flake check --accept-flake-config
|
|
||||||
|
|
||||||
build-servers:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: flake-check
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: DeterminateSystems/nix-installer-action@v11
|
|
||||||
- uses: DeterminateSystems/magic-nix-cache-action@v8
|
|
||||||
- name: Build server packages
|
|
||||||
run: |
|
|
||||||
nix build --accept-flake-config .#chainfire-server .#flaredb-server .#iam-server .#plasmavmc-server .#prismnet-server .#flashdns-server .#fiberlb-server .#lightningstor-server .#creditservice-server
|
|
||||||
|
|
||||||
integration-matrix:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: build-servers
|
|
||||||
env:
|
|
||||||
PLASMA_E2E: "1"
|
|
||||||
# SKIP_PLASMA defaults to 0; set repo/runner var to 1 only when qemu-img/KVM is unavailable.
|
|
||||||
SKIP_PLASMA: ${{ vars.SKIP_PLASMA || '0' }}
|
|
||||||
LOG_DIR: .cccc/work/integration-matrix/${{ github.run_id }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: DeterminateSystems/nix-installer-action@v11
|
|
||||||
- uses: DeterminateSystems/magic-nix-cache-action@v8
|
|
||||||
- name: Run integration matrix (Noop hypervisor gate)
|
|
||||||
run: |
|
|
||||||
nix develop -c ./scripts/integration-matrix.sh
|
|
||||||
- name: Upload integration-matrix logs
|
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
with:
|
||||||
name: integration-matrix-logs
|
filters: |
|
||||||
path: .cccc/work/integration-matrix/
|
global:
|
||||||
|
- 'flake.nix'
|
||||||
|
- 'flake.lock'
|
||||||
|
- 'nix/**'
|
||||||
|
- '.github/workflows/nix.yml'
|
||||||
|
- 'Cargo.toml'
|
||||||
|
- 'Cargo.lock'
|
||||||
|
chainfire: 'chainfire/**'
|
||||||
|
flaredb: 'flaredb/**'
|
||||||
|
iam: 'iam/**'
|
||||||
|
plasmavmc: 'plasmavmc/**'
|
||||||
|
prismnet: 'prismnet/**'
|
||||||
|
flashdns: 'flashdns/**'
|
||||||
|
fiberlb: 'fiberlb/**'
|
||||||
|
lightningstor: 'lightningstor/**'
|
||||||
|
nightlight: 'nightlight/**'
|
||||||
|
creditservice: 'creditservice/**'
|
||||||
|
k8shost: 'k8shost/**'
|
||||||
|
apigateway: 'apigateway/**'
|
||||||
|
deployer: 'deployer/**'
|
||||||
|
|
||||||
integration-matrix-kvm:
|
# Run CI gates for changed workspaces
|
||||||
if: ${{ vars.NESTED_KVM == '1' }}
|
# Uses the provider-agnostic 'photoncloud-gate' defined in nix/ci/flake.nix
|
||||||
|
gate:
|
||||||
|
needs: filter
|
||||||
|
if: ${{ needs.filter.outputs.any_changed == 'true' || needs.filter.outputs.global_changed == 'true' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: integration-matrix
|
strategy:
|
||||||
env:
|
fail-fast: false
|
||||||
PLASMA_E2E: "1"
|
matrix:
|
||||||
SKIP_PLASMA: "0"
|
# If global files changed, run all. Otherwise run only changed ones.
|
||||||
LOG_DIR: .cccc/work/integration-matrix-kvm/${{ github.run_id }}
|
workspace: ${{ fromJSON(needs.filter.outputs.global_changed == 'true' && '["chainfire", "flaredb", "iam", "plasmavmc", "prismnet", "flashdns", "fiberlb", "lightningstor", "nightlight", "creditservice", "k8shost", "apigateway", "deployer"]' || needs.filter.outputs.workspaces) }}
|
||||||
|
name: gate (${{ matrix.workspace }})
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: DeterminateSystems/nix-installer-action@v11
|
- uses: DeterminateSystems/nix-installer-action@v11
|
||||||
- uses: DeterminateSystems/magic-nix-cache-action@v8
|
- uses: DeterminateSystems/magic-nix-cache-action@v8
|
||||||
- name: Run integration matrix (KVM lane)
|
|
||||||
|
- name: Run PhotonCloud Gate
|
||||||
run: |
|
run: |
|
||||||
nix develop -c ./scripts/integration-matrix.sh
|
nix run .#gate-ci -- --workspace ${{ matrix.workspace }} --tier 0 --no-logs
|
||||||
- name: Upload integration-matrix-kvm logs
|
|
||||||
if: always()
|
# Build server packages (tier 1+)
|
||||||
uses: actions/upload-artifact@v4
|
build:
|
||||||
with:
|
needs: [filter, gate]
|
||||||
name: integration-matrix-kvm-logs
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||||
path: .cccc/work/integration-matrix-kvm/
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
workspace: ${{ fromJSON(needs.filter.outputs.global_changed == 'true' && '["chainfire", "flaredb", "iam", "plasmavmc", "prismnet", "flashdns", "fiberlb", "lightningstor", "nightlight", "creditservice", "k8shost", "apigateway", "deployer"]' || needs.filter.outputs.workspaces) }}
|
||||||
|
name: build (${{ matrix.workspace }})
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: DeterminateSystems/nix-installer-action@v11
|
||||||
|
- uses: DeterminateSystems/magic-nix-cache-action@v8
|
||||||
|
|
||||||
|
- name: Build server
|
||||||
|
run: |
|
||||||
|
# Only build if the workspace has a corresponding package in flake.nix
|
||||||
|
# We check if it exists before building to avoid failure on non-package workspaces
|
||||||
|
if nix flake show --json | jq -e ".packages.\"x86_64-linux\".\"${{ matrix.workspace }}-server\"" > /dev/null; then
|
||||||
|
nix build .#${{ matrix.workspace }}-server --accept-flake-config
|
||||||
|
else
|
||||||
|
echo "No server package found for ${{ matrix.workspace }}, skipping build."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Summary job for PR status checks
|
||||||
|
ci-status:
|
||||||
|
needs: [filter, gate]
|
||||||
|
if: always()
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Check CI Status
|
||||||
|
run: |
|
||||||
|
if [[ "${{ needs.gate.result }}" == "failure" ]]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ "${{ needs.filter.outputs.any_changed }}" == "true" || "${{ needs.filter.outputs.global_changed }}" == "true" ]]; then
|
||||||
|
if [[ "${{ needs.gate.result }}" == "skipped" ]]; then
|
||||||
|
echo "Gate was skipped despite changes. This is unexpected."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "CI passed or was correctly skipped."
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,9 @@
|
||||||
drv = gate;
|
drv = gate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# CI-optimized gate (alias)
|
||||||
|
packages.gate-ci = gate;
|
||||||
|
|
||||||
# Checks are minimal and mirror tier0 (provider-agnostic).
|
# Checks are minimal and mirror tier0 (provider-agnostic).
|
||||||
checks.gate-tier0 = pkgs.runCommand "photoncloud-gate-tier0" { } ''
|
checks.gate-tier0 = pkgs.runCommand "photoncloud-gate-tier0" { } ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue