|
| 1 | +name: E2E |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +env: |
| 13 | + CARGO_TERM_COLOR: always |
| 14 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" |
| 15 | + |
| 16 | +jobs: |
| 17 | + discover-e2e: |
| 18 | + name: Discover E2E tests |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + tests: ${{ steps.discover.outputs.tests }} |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout the repo |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + persist-credentials: false |
| 28 | + |
| 29 | + - name: Build matrix data |
| 30 | + id: discover |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | +
|
| 35 | + mapfile -t tests < <(find tests/e2e -maxdepth 1 -type f -name '*.sh' | sort) |
| 36 | + if [[ "${#tests[@]}" -eq 0 ]]; then |
| 37 | + echo "No e2e tests found" >&2 |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + matrix_json="$(printf '%s\n' "${tests[@]}" | jq -R -s -c 'split("\n")[:-1]')" |
| 42 | + echo "tests=${matrix_json}" >> "$GITHUB_OUTPUT" |
| 43 | + echo "Discovered e2e tests: ${matrix_json}" |
| 44 | +
|
| 45 | + build-e2e-binary: |
| 46 | + name: Build e2e binary |
| 47 | + runs-on: ubuntu-latest |
| 48 | + needs: [discover-e2e] |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout the repo |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + persist-credentials: false |
| 55 | + |
| 56 | + - name: Rust cache |
| 57 | + uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 |
| 58 | + with: |
| 59 | + shared-key: e2e-linux-release |
| 60 | + |
| 61 | + - name: Build yarn-bin |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | + cargo build -r -p zpm |
| 66 | + tar -czf e2e-binary-yarn-bin.tgz -C target/release yarn-bin |
| 67 | +
|
| 68 | + - name: Upload e2e binary |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: e2e-binary-yarn-bin |
| 72 | + path: e2e-binary-yarn-bin.tgz |
| 73 | + |
| 74 | + run-e2e: |
| 75 | + name: Run ${{ matrix.test }} |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: [discover-e2e, build-e2e-binary] |
| 78 | + strategy: |
| 79 | + fail-fast: false |
| 80 | + matrix: |
| 81 | + test: ${{ fromJson(needs.discover-e2e.outputs.tests) }} |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Checkout the repo |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + persist-credentials: false |
| 88 | + |
| 89 | + - name: Download e2e binary |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: e2e-binary-yarn-bin |
| 93 | + path: . |
| 94 | + |
| 95 | + - name: Extract e2e binary |
| 96 | + shell: bash |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | + mkdir -p target/release |
| 100 | + tar -xzf e2e-binary-yarn-bin.tgz -C target/release |
| 101 | +
|
| 102 | + - name: Resolve test metadata |
| 103 | + id: meta |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + set -euo pipefail |
| 107 | + test_name="$(basename "${{ matrix.test }}" .sh)" |
| 108 | + echo "test_name=${test_name}" >> "$GITHUB_OUTPUT" |
| 109 | +
|
| 110 | + - name: Prepare e2e artifact paths |
| 111 | + id: artifact-paths |
| 112 | + shell: bash |
| 113 | + env: |
| 114 | + TEST_SCRIPT: ${{ matrix.test }} |
| 115 | + TEST_NAME: ${{ steps.meta.outputs.test_name }} |
| 116 | + run: | |
| 117 | + set -euo pipefail |
| 118 | + artifact_dir="e2e-artifacts/${TEST_NAME}" |
| 119 | + log_file="${artifact_dir}/run.log" |
| 120 | + status_file="${artifact_dir}/status.json" |
| 121 | + mkdir -p "${artifact_dir}" |
| 122 | +
|
| 123 | + echo "artifact_dir=${artifact_dir}" >> "$GITHUB_OUTPUT" |
| 124 | + echo "log_file=${log_file}" >> "$GITHUB_OUTPUT" |
| 125 | + echo "status_file=${status_file}" >> "$GITHUB_OUTPUT" |
| 126 | +
|
| 127 | + - name: Run test in Docker sandbox action |
| 128 | + id: run-in-sandbox |
| 129 | + uses: ./.github/actions/run-e2e-sandbox |
| 130 | + with: |
| 131 | + test-name: ${{ steps.meta.outputs.test_name }} |
| 132 | + log-file: ${{ steps.artifact-paths.outputs.log_file }} |
| 133 | + |
| 134 | + - name: Write test status |
| 135 | + id: write-status |
| 136 | + shell: bash |
| 137 | + env: |
| 138 | + TEST_SCRIPT: ${{ matrix.test }} |
| 139 | + STATUS_FILE: ${{ steps.artifact-paths.outputs.status_file }} |
| 140 | + EXIT_CODE: ${{ steps.run-in-sandbox.outputs.exit-code || '1' }} |
| 141 | + run: | |
| 142 | + set -euo pipefail |
| 143 | + jq -n \ |
| 144 | + --arg test "${TEST_SCRIPT}" \ |
| 145 | + --argjson exitCode "${EXIT_CODE}" \ |
| 146 | + '{test:$test, exitCode:$exitCode}' > "${STATUS_FILE}" |
| 147 | +
|
| 148 | + - name: Fail job if test failed |
| 149 | + if: ${{ steps.run-in-sandbox.outputs.exit-code != '0' }} |
| 150 | + shell: bash |
| 151 | + run: | |
| 152 | + set -euo pipefail |
| 153 | + exit 1 |
| 154 | +
|
| 155 | + - name: Upload e2e logs and status |
| 156 | + if: always() |
| 157 | + uses: actions/upload-artifact@v4 |
| 158 | + with: |
| 159 | + name: e2e-result-${{ steps.meta.outputs.test_name }} |
| 160 | + path: e2e-artifacts/${{ steps.meta.outputs.test_name }} |
| 161 | + if-no-files-found: warn |
| 162 | + |
| 163 | + report-e2e-failures: |
| 164 | + name: Report e2e failures |
| 165 | + runs-on: ubuntu-latest |
| 166 | + needs: [run-e2e] |
| 167 | + if: always() && github.ref == 'refs/heads/main' |
| 168 | + permissions: |
| 169 | + contents: read |
| 170 | + issues: write |
| 171 | + |
| 172 | + steps: |
| 173 | + - name: Checkout the repo |
| 174 | + uses: actions/checkout@v4 |
| 175 | + |
| 176 | + - name: Setup Node.js |
| 177 | + uses: actions/setup-node@v4 |
| 178 | + with: |
| 179 | + node-version: 22 |
| 180 | + |
| 181 | + - name: Download e2e result artifacts |
| 182 | + continue-on-error: true |
| 183 | + uses: actions/download-artifact@v4 |
| 184 | + with: |
| 185 | + path: e2e-artifacts |
| 186 | + pattern: e2e-result-* |
| 187 | + merge-multiple: false |
| 188 | + |
| 189 | + - name: Create or update GitHub issues for failing tests |
| 190 | + env: |
| 191 | + E2E_ARTIFACTS_DIR: e2e-artifacts |
| 192 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 193 | + shell: bash |
| 194 | + run: | |
| 195 | + yarn node --experimental-strip-types scripts/e2e/report-failures.ts |
0 commit comments