|
| 1 | +name: Boxel Test Subset |
| 2 | + |
| 3 | +# The boxel monorepo pins a subset of this repo's system-level definitions |
| 4 | +# (packages/catalog/test-subset.json there) and tests the platform against it. |
| 5 | +# The deployed catalog realm serves this repo's main, so a change to one of |
| 6 | +# those files has to keep boxel's tests passing before it merges. This |
| 7 | +# workflow runs the boxel tests the manifest names against this checkout |
| 8 | +# whenever a change touches a subset file. |
| 9 | +# |
| 10 | +# A pull request is tested against the boxel branch of the same name when one |
| 11 | +# exists, so a catalog change and the boxel change that depends on it can be |
| 12 | +# validated together before either merges; otherwise against boxel main. |
| 13 | +# A manual run can name any boxel ref. |
| 14 | +# |
| 15 | +# It is a no-op when the boxel checkout has no manifest, and for pull |
| 16 | +# requests that touch no subset file. |
| 17 | + |
| 18 | +on: |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + boxel_ref: |
| 22 | + description: boxel ref to test against (branch, tag or sha) |
| 23 | + required: false |
| 24 | + default: main |
| 25 | + push: |
| 26 | + branches: [main] |
| 27 | + pull_request: |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: read |
| 31 | + pull-requests: read |
| 32 | + |
| 33 | +concurrency: |
| 34 | + group: boxel-test-subset-${{ github.head_ref || github.run_id }} |
| 35 | + cancel-in-progress: true |
| 36 | + |
| 37 | +jobs: |
| 38 | + scope: |
| 39 | + name: Decide whether the boxel test subset is touched |
| 40 | + runs-on: ubuntu-latest |
| 41 | + outputs: |
| 42 | + boxel_ref: ${{ steps.ref.outputs.boxel_ref }} |
| 43 | + run: ${{ steps.scope.outputs.run }} |
| 44 | + host_filters: ${{ steps.scope.outputs.host_filters }} |
| 45 | + realm_server_files: ${{ steps.scope.outputs.realm_server_files }} |
| 46 | + steps: |
| 47 | + - name: Pick the boxel ref |
| 48 | + id: ref |
| 49 | + env: |
| 50 | + REQUESTED: ${{ inputs.boxel_ref }} |
| 51 | + BRANCH: ${{ github.head_ref || github.ref_name }} |
| 52 | + run: | |
| 53 | + ref="$REQUESTED" |
| 54 | + if [ -z "$ref" ]; then |
| 55 | + if git ls-remote --exit-code --heads https://github.com/cardstack/boxel.git "$BRANCH" >/dev/null; then |
| 56 | + ref="$BRANCH" |
| 57 | + else |
| 58 | + ref=main |
| 59 | + fi |
| 60 | + fi |
| 61 | + echo "Testing against boxel@$ref" |
| 62 | + echo "boxel_ref=$ref" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 65 | + with: |
| 66 | + repository: cardstack/boxel |
| 67 | + ref: ${{ steps.ref.outputs.boxel_ref }} |
| 68 | + sparse-checkout: packages/catalog |
| 69 | + path: boxel |
| 70 | + |
| 71 | + - name: Decide scope |
| 72 | + id: scope |
| 73 | + env: |
| 74 | + GH_TOKEN: ${{ github.token }} |
| 75 | + run: | |
| 76 | + manifest=boxel/packages/catalog/test-subset.json |
| 77 | + if [ ! -f "$manifest" ]; then |
| 78 | + echo "::notice::boxel@${{ steps.ref.outputs.boxel_ref }} has no catalog test subset; nothing to run" |
| 79 | + echo "run=false" >> "$GITHUB_OUTPUT" |
| 80 | + exit 0 |
| 81 | + fi |
| 82 | + run=true |
| 83 | + if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then |
| 84 | + # Both file listings are capped (3,000 files for a PR, 300 for a |
| 85 | + # compare), and a full list may hide a subset file, so a full |
| 86 | + # list counts as touching the subset. |
| 87 | + # A rename lists its old path only as previous_filename; include it |
| 88 | + # so moving a subset file away runs the tests, whose sync then |
| 89 | + # fails on the missing file. |
| 90 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 91 | + gh api "repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}/files" \ |
| 92 | + --paginate --jq '.[] | .filename, (.previous_filename // empty)' > changed.txt |
| 93 | + listed=$(gh api "repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}" --jq .changed_files) |
| 94 | + cap=3000 |
| 95 | + else |
| 96 | + gh api "repos/$GITHUB_REPOSITORY/compare/${{ github.event.before }}...${{ github.sha }}" > compare.json |
| 97 | + jq -r '.files[] | .filename, (.previous_filename // empty)' compare.json > changed.txt |
| 98 | + listed=$(jq '.files | length' compare.json) |
| 99 | + cap=300 |
| 100 | + fi |
| 101 | + jq -r '.files[].path' "$manifest" > subset.txt |
| 102 | + if [ "$listed" -ge "$cap" ]; then |
| 103 | + echo "The change lists $listed files, at the API's cap, so it may touch a subset file" |
| 104 | + elif grep -qxFf subset.txt changed.txt; then |
| 105 | + echo "Touched subset files:"; grep -xFf subset.txt changed.txt |
| 106 | + else |
| 107 | + echo "No subset file touched" |
| 108 | + run=false |
| 109 | + fi |
| 110 | + fi |
| 111 | + echo "run=$run" >> "$GITHUB_OUTPUT" |
| 112 | + echo "host_filters=$(jq -c '.tests.host // []' "$manifest")" >> "$GITHUB_OUTPUT" |
| 113 | + echo "realm_server_files=$(jq -r '.tests.realmServer // [] | join(",")' "$manifest")" >> "$GITHUB_OUTPUT" |
| 114 | +
|
| 115 | + host: |
| 116 | + name: Boxel host tests against this catalog |
| 117 | + needs: scope |
| 118 | + if: needs.scope.outputs.run == 'true' && needs.scope.outputs.host_filters != '[]' |
| 119 | + runs-on: ubuntu-latest |
| 120 | + env: |
| 121 | + # The checkout below is the exact commit under test; keep |
| 122 | + # catalog-update.sh from pulling it elsewhere, and serve the subset |
| 123 | + # definitions from it rather than from boxel's pin. |
| 124 | + SKIP_CATALOG_UPDATE: "1" |
| 125 | + CATALOG_TEST_SUBSET_SOURCE: packages/catalog/contents |
| 126 | + # Serve only the subset, as boxel's own host CI does, rather than |
| 127 | + # indexing the whole catalog. |
| 128 | + CATALOG_SOURCE: test-subset |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 131 | + with: |
| 132 | + repository: cardstack/boxel |
| 133 | + ref: ${{ needs.scope.outputs.boxel_ref }} |
| 134 | + |
| 135 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 136 | + with: |
| 137 | + path: packages/catalog/contents |
| 138 | + |
| 139 | + - uses: ./.github/actions/init |
| 140 | + |
| 141 | + - name: Build common dependencies |
| 142 | + run: pnpm run build-common-deps |
| 143 | + |
| 144 | + - name: Build Host for tests |
| 145 | + run: NODE_OPTIONS='--max-old-space-size=8192' pnpm build |
| 146 | + working-directory: packages/host |
| 147 | + |
| 148 | + - name: Disable TCP/UDP network offloading |
| 149 | + run: sudo ethtool -K eth0 tx off rx off |
| 150 | + |
| 151 | + - name: Install D-Bus helpers |
| 152 | + run: | |
| 153 | + sudo apt-get update |
| 154 | + sudo apt-get install -y dbus-x11 upower |
| 155 | + sudo service dbus restart |
| 156 | + sudo service upower restart |
| 157 | +
|
| 158 | + - name: Start test services |
| 159 | + run: mise run test-services:host | tee -a /tmp/server.log & |
| 160 | + |
| 161 | + - name: Create realm users |
| 162 | + run: pnpm register-realm-users |
| 163 | + working-directory: packages/matrix |
| 164 | + |
| 165 | + - name: Wait for the stack |
| 166 | + run: | |
| 167 | + for url in \ |
| 168 | + 'https://localhost:4201/base/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson' \ |
| 169 | + 'https://localhost:4201/catalog/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson' \ |
| 170 | + 'https://localhost:4202/test/_readiness-check?acceptHeader=application%2Fvnd.api%2Bjson' \ |
| 171 | + 'http://localhost:8008'; do |
| 172 | + timeout 900 bash -c "until curl -skf '$url' >/dev/null; do sleep 5; done" |
| 173 | + done |
| 174 | +
|
| 175 | + - name: Host tests the subset feeds |
| 176 | + working-directory: packages/host |
| 177 | + env: |
| 178 | + DBUS_SYSTEM_BUS_ADDRESS: unix:path=/run/dbus/system_bus_socket |
| 179 | + HOST_FILTERS: ${{ needs.scope.outputs.host_filters }} |
| 180 | + run: | |
| 181 | + status=0 |
| 182 | + while IFS= read -r filter; do |
| 183 | + echo "::group::ember test --filter \"$filter\"" |
| 184 | + dbus-run-session -- pnpm exec ember test --path ./dist --filter "$filter" || status=1 |
| 185 | + echo "::endgroup::" |
| 186 | + done < <(jq -r '.[]' <<<"$HOST_FILTERS") |
| 187 | + exit $status |
| 188 | +
|
| 189 | + - name: Print realm server logs |
| 190 | + if: ${{ !cancelled() }} |
| 191 | + run: cat /tmp/server.log |
| 192 | + |
| 193 | + realm-server: |
| 194 | + name: Boxel realm-server tests against this catalog |
| 195 | + needs: scope |
| 196 | + if: needs.scope.outputs.run == 'true' && needs.scope.outputs.realm_server_files != '' |
| 197 | + runs-on: ubuntu-latest |
| 198 | + env: |
| 199 | + SKIP_CATALOG_UPDATE: "1" |
| 200 | + CATALOG_TEST_SUBSET_SOURCE: packages/catalog/contents |
| 201 | + steps: |
| 202 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 203 | + with: |
| 204 | + repository: cardstack/boxel |
| 205 | + ref: ${{ needs.scope.outputs.boxel_ref }} |
| 206 | + |
| 207 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 208 | + with: |
| 209 | + path: packages/catalog/contents |
| 210 | + |
| 211 | + - uses: ./.github/actions/init |
| 212 | + |
| 213 | + - name: Build common dependencies |
| 214 | + run: pnpm run build-common-deps |
| 215 | + |
| 216 | + - name: Build Host for the prerenderer |
| 217 | + run: NODE_OPTIONS='--max-old-space-size=8192' pnpm build |
| 218 | + working-directory: packages/host |
| 219 | + |
| 220 | + - name: Warm test Docker images |
| 221 | + uses: ./.github/actions/warm-test-images |
| 222 | + |
| 223 | + # test-services:realm-server serves the subset as the catalog realm; |
| 224 | + # CATALOG_TEST_SUBSET_SOURCE makes the subset this checkout's copy. |
| 225 | + - name: Start test services |
| 226 | + run: mise run test-services:realm-server | tee -a /tmp/server.log & |
| 227 | + |
| 228 | + - name: Create realm users |
| 229 | + run: pnpm register-realm-users |
| 230 | + working-directory: packages/matrix |
| 231 | + |
| 232 | + - name: Realm-server tests the subset feeds |
| 233 | + run: pnpm test:wait-for-servers |
| 234 | + working-directory: packages/realm-server |
| 235 | + env: |
| 236 | + TEST_FILES: ${{ needs.scope.outputs.realm_server_files }} |
| 237 | + |
| 238 | + - name: Print realm server logs |
| 239 | + if: ${{ !cancelled() }} |
| 240 | + run: cat /tmp/server.log |
0 commit comments