Skip to content

Commit

Permalink
CI cacheitem consistency check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Hammond authored and Nathan Hammond committed May 17, 2023
1 parent 165a33b commit deee5f0
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/turborepo-compare-cache-item.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions cli/internal/cache/cache_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (cache *httpCache) write(w io.WriteCloser, anchor turbopath.AbsoluteSystemP
if err != nil {
_ = cacheItem.Close()
cacheErrorChan <- err
return
}
}

Expand Down
42 changes: 42 additions & 0 deletions scripts/server.js
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit deee5f0

Please sign in to comment.