From deee5f073492d1594641caa232c364d5bd480010 Mon Sep 17 00:00:00 2001 From: Nathan Hammond Date: Mon, 15 May 2023 14:03:11 +0800 Subject: [PATCH] CI cacheitem consistency check. --- .../turborepo-compare-cache-item.yml | 79 +++++++++++++++++++ cli/internal/cache/cache_http.go | 1 + scripts/server.js | 42 ++++++++++ 3 files changed, 122 insertions(+) create mode 100644 .github/workflows/turborepo-compare-cache-item.yml create mode 100755 scripts/server.js diff --git a/.github/workflows/turborepo-compare-cache-item.yml b/.github/workflows/turborepo-compare-cache-item.yml new file mode 100644 index 00000000000000..becc939b2cea81 --- /dev/null +++ b/.github/workflows/turborepo-compare-cache-item.yml @@ -0,0 +1,79 @@ +name: Turborepo Compare Cache Item + +on: + workflow_dispatch: + inputs: + version: + description: Turborepo release to test. + type: string + default: "canary" + +jobs: + generate_cache_artifact: + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + + steps: + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: create-turbo + run: | + npm install -g pnpm turbo@${{ inputs.version }} + pnpm dlx create-turbo@${{ inputs.version }} my-turborepo pnpm + + - name: Run build + run: | + cd my-turborepo + turbo run build --filter=docs --filter=web --summarize --skip-infer -vvv + + - name: Grab Turborepo artifacts + uses: actions/upload-artifact@v3 + with: + name: cache-item-${{ matrix.os }}-${{ inputs.version }} + path: | + my-turborepo/node_modules/.cache/turbo + my-turborepo/.turbo/runs + retention-days: 1 + + use_cache_artifact: + needs: generate_cache_artifact + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + cache_os: [macos-latest, ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + + steps: + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: create-turbo + run: | + npm install -g pnpm turbo@${{ inputs.version }} + pnpm dlx create-turbo@${{ inputs.version }} my-turborepo pnpm + + - name: Download cache artifacts + uses: actions/download-artifact@v3 + with: + name: cache-item-${{ matrix.cache_os }}-${{ inputs.version }} + path: my-turborepo + + - name: Check for cache hit + run: | + cd my-turborepo + rm .turbo/runs/*.json + turbo run build --filter=docs --filter=web --summarize --skip-infer -vvv + cat .turbo/runs/*.json | jq -e '.execution.cached == 2' + + - name: Check for functional server + run: | + curl https://raw.githubusercontent.com/vercel/turbo/main/scripts/server.js -O + node server.js my-turborepo/apps/docs diff --git a/cli/internal/cache/cache_http.go b/cli/internal/cache/cache_http.go index 9793426a9c4617..e32c6b5782f479 100644 --- a/cli/internal/cache/cache_http.go +++ b/cli/internal/cache/cache_http.go @@ -85,6 +85,7 @@ func (cache *httpCache) write(w io.WriteCloser, anchor turbopath.AbsoluteSystemP if err != nil { _ = cacheItem.Close() cacheErrorChan <- err + return } } diff --git a/scripts/server.js b/scripts/server.js new file mode 100755 index 00000000000000..71ccbf644f2459 --- /dev/null +++ b/scripts/server.js @@ -0,0 +1,42 @@ +#!/usr/bin/env node + +const { spawn } = require("child_process"); +const { platform } = require("process"); + +const path = process.argv[2]; + +async function main() { + let errored = false; + + await new Promise((resolve) => { + const command = platform === "win32" ? "pnpm.cmd" : "pnpm"; + const server = spawn(command, ["run", "start"], { cwd: path }); + + server.stdout.on("data", (data) => { + console.log("stdout:"); + console.log(`${data}`); + + // Stable for 5s. + setTimeout(() => { + server.kill(); + }, 5000); + }); + + server.stderr.on("data", (data) => { + console.log("stderr:"); + console.log(`${data}`); + + errored = true; + server.kill(); + }); + + server.on("exit", () => { + console.log(`exit: ${+errored}`); + resolve(); + }); + }); + + process.exit(errored); +} + +main();