|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [master] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ci-${{ github.event.pull_request.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + ci: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + timeout-minutes: 120 |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 # full history for change detection |
| 21 | + |
| 22 | + - name: Initialize submodules |
| 23 | + run: git submodule update --init --depth 1 --jobs 4 |
| 24 | + |
| 25 | + - name: Check for docs-only changes |
| 26 | + id: filter |
| 27 | + run: | |
| 28 | + base="${{ github.event.pull_request.base.sha }}" |
| 29 | + head="${{ github.sha }}" |
| 30 | + non_docs=$(git diff --name-only "$base" "$head" | grep -cvE '\.(md|txt)$' || true) |
| 31 | + echo "skip_build=$( [[ "$non_docs" -eq 0 ]] && echo true || echo false )" >> "$GITHUB_OUTPUT" |
| 32 | +
|
| 33 | + - name: Install Nix |
| 34 | + if: steps.filter.outputs.skip_build != 'true' |
| 35 | + uses: DeterminateSystems/nix-installer-action@main |
| 36 | + |
| 37 | + - name: Setup Nix cache |
| 38 | + if: steps.filter.outputs.skip_build != 'true' |
| 39 | + uses: DeterminateSystems/magic-nix-cache-action@main |
| 40 | + # For faster CI, consider adding a dedicated binary cache: |
| 41 | + # cachix-name: logos-workspace |
| 42 | + # cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} |
| 43 | + |
| 44 | + - name: Add workspace tools to PATH |
| 45 | + if: steps.filter.outputs.skip_build != 'true' |
| 46 | + run: echo "${{ github.workspace }}/scripts" >> "$GITHUB_PATH" |
| 47 | + |
| 48 | + - name: Detect changes |
| 49 | + if: steps.filter.outputs.skip_build != 'true' |
| 50 | + id: changes |
| 51 | + run: | |
| 52 | + base="${{ github.event.pull_request.base.sha }}" |
| 53 | + head="${{ github.sha }}" |
| 54 | +
|
| 55 | + # Infrastructure = flake config, nix support files, workspace scripts |
| 56 | + infra=false |
| 57 | + if git diff --name-only "$base" "$head" | grep -qE '^(flake\.(nix|lock)|nix/|scripts/)'; then |
| 58 | + infra=true |
| 59 | + fi |
| 60 | + echo "infra=$infra" >> "$GITHUB_OUTPUT" |
| 61 | +
|
| 62 | + # Repos with changed submodule pointers |
| 63 | + changed="" |
| 64 | + while IFS= read -r line; do |
| 65 | + [[ -z "$line" ]] && continue |
| 66 | + repo=$(echo "$line" | cut -d/ -f2) |
| 67 | + [[ -n "$repo" ]] && changed="$changed $repo" |
| 68 | + done < <(git diff --name-only "$base" "$head" -- repos/) |
| 69 | + changed=$(echo "$changed" | xargs -n1 2>/dev/null | sort -u | xargs 2>/dev/null || true) |
| 70 | + echo "changed=$changed" >> "$GITHUB_OUTPUT" |
| 71 | +
|
| 72 | + # Expand to include downstream dependents (parsed from dep-graph.nix). |
| 73 | + # Each line in dep-graph.nix looks like: |
| 74 | + # repo-name = { deps = [ "dep1" "dep2" ]; hasTests = ...; }; |
| 75 | + # Grep for "repo" (quoted) matches lines where repo appears in a deps array. |
| 76 | + affected="$changed" |
| 77 | + for repo in $changed; do |
| 78 | + dependents=$(grep "\"$repo\"" nix/dep-graph.nix 2>/dev/null | \ |
| 79 | + sed 's/^[[:space:]]*\([^[:space:]]*\).*/\1/' || true) |
| 80 | + affected="$affected $dependents" |
| 81 | + done |
| 82 | + affected=$(echo "$affected" | xargs -n1 2>/dev/null | sort -u | xargs 2>/dev/null || true) |
| 83 | + echo "affected=$affected" >> "$GITHUB_OUTPUT" |
| 84 | +
|
| 85 | + echo "## Change Detection" >> "$GITHUB_STEP_SUMMARY" |
| 86 | + echo "- Infrastructure changed: \`$infra\`" >> "$GITHUB_STEP_SUMMARY" |
| 87 | + echo "- Changed repos: \`${changed:-none}\`" >> "$GITHUB_STEP_SUMMARY" |
| 88 | + echo "- Affected repos (+ dependents): \`${affected:-none}\`" >> "$GITHUB_STEP_SUMMARY" |
| 89 | +
|
| 90 | + - name: Validate dep-graph.nix is up to date |
| 91 | + if: steps.filter.outputs.skip_build != 'true' |
| 92 | + run: | |
| 93 | + cp nix/dep-graph.nix /tmp/dep-graph-before.nix |
| 94 | + ws sync-graph --quiet |
| 95 | + if ! diff -q nix/dep-graph.nix /tmp/dep-graph-before.nix >/dev/null 2>&1; then |
| 96 | + echo "::error::nix/dep-graph.nix is stale — run 'ws sync-graph' and commit the result" |
| 97 | + diff --color=never -u /tmp/dep-graph-before.nix nix/dep-graph.nix || true |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: Build changed repos and dependents |
| 102 | + if: steps.filter.outputs.skip_build != 'true' && steps.changes.outputs.infra != 'true' && steps.changes.outputs.affected != '' |
| 103 | + run: | |
| 104 | + failed=0 |
| 105 | + for repo in ${{ steps.changes.outputs.affected }}; do |
| 106 | + [[ ! -f "repos/$repo/flake.nix" ]] && continue |
| 107 | + echo "::group::Build $repo" |
| 108 | + if ! ws build "$repo" --quiet; then |
| 109 | + echo "::error::Build failed: $repo" |
| 110 | + failed=1 |
| 111 | + fi |
| 112 | + echo "::endgroup::" |
| 113 | + done |
| 114 | + exit $failed |
| 115 | +
|
| 116 | + - name: Build core chain (infrastructure changed) |
| 117 | + if: steps.filter.outputs.skip_build != 'true' && steps.changes.outputs.infra == 'true' |
| 118 | + run: | |
| 119 | + failed=0 |
| 120 | + for repo in logos-cpp-sdk logos-module logos-liblogos logos-package logos-app-poc; do |
| 121 | + echo "::group::Build $repo" |
| 122 | + if ! ws build "$repo" --quiet; then |
| 123 | + echo "::error::Build failed: $repo" |
| 124 | + failed=1 |
| 125 | + fi |
| 126 | + echo "::endgroup::" |
| 127 | + done |
| 128 | + exit $failed |
| 129 | +
|
| 130 | + - name: Run tests |
| 131 | + if: steps.filter.outputs.skip_build != 'true' |
| 132 | + run: ws test --all --quiet |
0 commit comments