Skip to content

Commit

Permalink
chore(turbo): add build script and update package.json to use turbo r…
Browse files Browse the repository at this point in the history
…emote cache (#6354)

* chore(turbo): add build script and update package.json to use turbo build with remote caching

* chore(turbo): updated Turbo version

---------

Co-authored-by: Isaiah Hall <[email protected]>
  • Loading branch information
isaiahshall and Isaiah Hall authored Aug 5, 2024
1 parent 7b4b333 commit d88855e
Show file tree
Hide file tree
Showing 4 changed files with 1,842 additions and 1,854 deletions.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"scripts": {
"bootstrap": "yarn",
"bootstrap:ci": "yarn install --frozen-lockfile",
"build:all": "yarn build:crypto-dependencies && lerna run build",
"build:ci": "lerna run build --since origin/main --include-dependencies",
"build:clients:generic": "lerna run --scope '@aws-sdk/aws-echo-service' --include-dependencies build",
"build:clients:since:release": "yarn build:packages && lerna run build $(lerna changed | grep -e '@aws-sdk/[client|lib]-*' | sed 's/^/ --scope /' | tr '\n' ' ')",
"build:crypto-dependencies": "lerna run --scope '@aws-sdk/{types,util-utf8,util-locate-window,hash-node}' --include-dependencies build",
"build:e2e": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/{client-cloudformation,karma-credential-loader,client-s3-control,client-sts}' --include-dependencies build",
"build:packages": "lerna run build --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' --ignore '@aws-sdk/lib-*' --include-dependencies",
"build:protocols": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/aws-protocoltests-*' --include-dependencies build",
"build:server-protocols": "yarn build:crypto-dependencies && lerna run --scope '@aws-sdk/*-server' --include-dependencies build",
"build:all": "yarn build:crypto-dependencies && node ./scripts/turbo build",
"build:ci": "node ./scripts/turbo build -F=[origin/main...HEAD]...",
"build:clients:generic": "node ./scripts/turbo build -F=@aws-sdk/aws-echo-service...",
"build:clients:since:release": "yarn build:packages && node ./scripts/turbo build $(lerna changed | grep -e '@aws-sdk/[client|lib]-*' | sed 's/^/ -F=/' | tr '\n' ' ')",
"build:crypto-dependencies": "node ./scripts/turbo build -F=@aws-sdk/types... -F=@aws-sdk/util-locate-window...",
"build:e2e": "yarn build:crypto-dependencies && node ./scripts/turbo build -F=@aws-sdk/client-cloudformation... -F=@aws-sdk/karma-credential-loader... -F=@aws-sdk/client-s3-control... -F=@aws-sdk/client-sts...",
"build:packages": "node ./scripts/turbo build -F=!@aws-sdk/client-*... -F=!@aws-sdk/aws-*... -F=!@aws-sdk/lib-*...",
"build:protocols": "yarn build:crypto-dependencies && node ./scripts/turbo build -F=@aws-sdk/aws-protocoltests-*...",
"build:server-protocols": "yarn build:crypto-dependencies && node ./scripts/turbo build -F=@aws-sdk/*-server...",
"build:types:downlevel": "node --es-module-specifier-resolution=node ./scripts/downlevel-dts",
"clean": "yarn clear-build-cache && yarn clear-build-info && lerna clean",
"clear-build-docs": "rimraf ./clients/*/docs/ ./dist/docs/clients/*/docs/ ./clientDocs",
Expand Down Expand Up @@ -117,7 +117,7 @@
"ts-loader": "9.4.2",
"ts-mocha": "10.0.0",
"ts-node": "10.9.1",
"turbo": "2.0.9",
"turbo": "2.0.11",
"typescript": "~4.9.5",
"verdaccio": "5.25.0",
"webpack": "5.76.0",
Expand Down
22 changes: 22 additions & 0 deletions scripts/turbo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Turbo Build Script

This script is designed to handle the execution of Turborepo builds, using the remote cache when env variables are present.

## Prerequisites

Before running this script, ensure that you have installed dependencies with `yarn`.

## Environment Variables

To access the remote cache for Turborepo builds, you need to set the following environment variables:

- `AWS_JSV3_TURBO_CACHE_API_SECRET`: The API secret for authenticating with the remote cache.
- `AWS_JSV3_TURBO_CACHE_API_ENDPOINT`: The API endpoint for the remote cache.

## Usage

To run the Turborepo build, execute the following command:

```
node ./scripts/turbo build <Optional Turborepo Args>
```
37 changes: 37 additions & 0 deletions scripts/turbo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Build script to handle Turborepo build execution
const { spawnProcess } = require("../utils/spawn-process");
const path = require("path");

const runTurbo = async (task, args, apiSecret, apiEndpoint) => {
let command = ["turbo", "run", task];
if (apiSecret && apiEndpoint) {
command = command.concat([
`--api=${apiEndpoint}`,
"--team=aws-sdk-js",
`--token=${apiSecret}`,
"--concurrency=100%",
]);
}
command = command.concat(args);
const turboRoot = path.join(__dirname, "..", "..");
try {
return await spawnProcess("npx", command, { stdio: "inherit", cwd: turboRoot });
} catch (error) {
console.error("Error running turbo:", error);
}
};

const main = async () => {
const apiSecret = process.env.AWS_JSV3_TURBO_CACHE_API_SECRET;
const apiEndpoint = process.env.AWS_JSV3_TURBO_CACHE_API_ENDPOINT;

const args = process.argv.slice(2);

if (!apiSecret || !apiEndpoint) {
await runTurbo(args[0], args.slice(1));
} else {
await runTurbo(args[0], args.slice(1), apiSecret, apiEndpoint);
}
};

main();
Loading

0 comments on commit d88855e

Please sign in to comment.