|
| 1 | +name: Sandboxed Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +# Run the suite with every socket except loopback closed. Terragrunt virtualizes |
| 7 | +# its side effects through the venv bundle, so a test that reaches the network is |
| 8 | +# either exercising an unvirtualized code path or is an integration test hiding in |
| 9 | +# the untagged suite. Both are worth catching here rather than as a flake on a day |
| 10 | +# the registry is slow. |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + name: Sandboxed Test |
| 14 | + runs-on: ubuntu-latest |
| 15 | + env: |
| 16 | + GOGC: "400" |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v6 |
| 21 | + with: |
| 22 | + fetch-depth: 1 |
| 23 | + |
| 24 | + - name: Use mise to install dependencies |
| 25 | + uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1 |
| 26 | + with: |
| 27 | + version: 2026.5.12 |
| 28 | + env: |
| 29 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - id: go-cache-paths |
| 32 | + run: | |
| 33 | + echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT" |
| 34 | + echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT" |
| 35 | + shell: bash |
| 36 | + |
| 37 | + - name: Go Build Cache |
| 38 | + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5 |
| 39 | + with: |
| 40 | + path: ${{ steps.go-cache-paths.outputs.go-build }} |
| 41 | + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}-ubuntu-amd64 |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-go-build- |
| 44 | +
|
| 45 | + - name: Go Mod Cache |
| 46 | + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5 |
| 47 | + with: |
| 48 | + path: ${{ steps.go-cache-paths.outputs.go-mod }} |
| 49 | + key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}-ubuntu-amd64 |
| 50 | + restore-keys: | |
| 51 | + ${{ runner.os }}-go-mod- |
| 52 | +
|
| 53 | + # Ubuntu 24.04 confines unprivileged user namespaces with AppArmor, which is |
| 54 | + # what `unshare --map-root-user --net` needs. The check below is what |
| 55 | + # actually gates the run, so a runner image that never restricted them is |
| 56 | + # free to ignore this. |
| 57 | + - name: Permit unprivileged user namespaces |
| 58 | + run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 || true |
| 59 | + shell: bash |
| 60 | + |
| 61 | + # `go test` compiles outside the sandbox, so warm the module cache first and |
| 62 | + # keep the sandbox scoped to what the test binaries do. |
| 63 | + - name: Warm build cache |
| 64 | + run: go build ./... && go mod download |
| 65 | + shell: bash |
| 66 | + |
| 67 | + - name: Verify the sandbox blocks egress |
| 68 | + run: ./.github/scripts/ci/no-network-exec.sh --check |
| 69 | + shell: bash |
| 70 | + |
| 71 | + - name: Run Tests |
| 72 | + run: go test -exec "$PWD/.github/scripts/ci/no-network-exec.sh" -timeout 45m ./... |
| 73 | + shell: bash |
0 commit comments