Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/actions/build-local-sdk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Build SDK packages locally'
description: 'Restore workspace dependencies and build the SDK outputs needed by this job.'
inputs:
setup:
description: 'Set up the build Node version and restore workspace dependencies.'
default: 'true'
package-path:
description: 'Comma-separated package paths whose SDK dependencies to build; use . only for repo-wide checks.'
default: ''
targets:
description: 'Nx targets to build for the selected packages and their dependencies.'
default: 'build:transpile build:types'
runs:
using: composite
steps:
- name: Set up build Node
if: inputs.setup == 'true'
uses: ./.github/actions/setup-node
- name: Restore workspace dependencies
if: inputs.setup == 'true'
uses: ./.github/actions/install-dependencies
- name: Select SDK packages
id: projects
env:
INPUT_PACKAGE_PATH: ${{ inputs.package-path }}
run: node "$GITHUB_ACTION_PATH/select-projects.mjs" >> "$GITHUB_OUTPUT"
shell: bash
- name: Build SDK packages
env:
BUILD_PROJECTS: ${{ steps.projects.outputs.projects }}
run: |
node scripts/verify-packages-versions.js
pnpm exec nx run-many -t ${{ inputs.targets }} --projects="$BUILD_PROJECTS" --parallel=4
shell: bash
43 changes: 43 additions & 0 deletions .github/actions/build-local-sdk/select-projects.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';

const readPackage = directory => JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf8'));
const workspaces = readPackage('.').workspaces;
const names = new Set(workspaces.map(directory => readPackage(directory).name));
const packagePath = process.env.INPUT_PACKAGE_PATH;
if (!packagePath) {
throw new Error('Select a package path, or explicitly use . for repo-wide checks.');
}
const roots = [
...new Set(
packagePath.split(',').flatMap(directory => {
if (directory === '.') {
return [...names];
}
if (workspaces.includes(directory)) {
return [readPackage(directory).name];
}
return fs.globSync('**/package.json', { cwd: directory, exclude: ['**/node_modules/**'] }).flatMap(file => {
const manifest = readPackage(path.join(directory, path.dirname(file)));
return Object.keys({ ...manifest.dependencies, ...manifest.devDependencies }).filter(name => names.has(name));
});
}),
),
];
if (!roots.length) {
throw new Error(`No workspace dependencies found for ${packagePath}`);
}

// pnpm's ... selector includes workspace dependencies, including shared test runners and build tools.
const packages = JSON.parse(
execFileSync('pnpm', [...roots.flatMap(name => ['--filter', `${name}...`]), '-r', 'list', '--depth=-1', '--json'], {
encoding: 'utf8',
}),
);
const projects = packages.map(pkg => pkg.name);
if (!projects.length) {
throw new Error(`No SDK build projects selected for ${packagePath}`);
}
process.stderr.write(`Selected ${projects.length} workspace projects for ${packagePath}: ${projects.join(', ')}\n`);
process.stdout.write(`projects=${projects.join(',')}\n`);
7 changes: 6 additions & 1 deletion .github/actions/prepare-e2e-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ inputs:
github-token:
description: 'Token to download artifacts from `artifacts-run-id`. Only needed when that is set.'
default: ''
download-artifacts:
description: 'Download SDK artifacts instead of using outputs already built in this workspace.'
default: 'true'

runs:
using: 'composite'
Expand Down Expand Up @@ -53,6 +56,7 @@ runs:
# upload-artifact strips the path through the first `*`, so the tarballs are stored as <pkg>/*.tgz and have to be
# downloaded into packages/.
- name: Restore tarball artifacts
if: inputs.download-artifacts == 'true'
uses: actions/download-artifact@v8
with:
name: build-tarball-output
Expand All @@ -61,6 +65,7 @@ runs:
github-token: ${{ inputs.github-token }}

- name: Restore test-utils tarball artifact
if: inputs.download-artifacts == 'true'
uses: actions/download-artifact@v8
with:
name: build-test-utils-tarball-output
Expand All @@ -79,7 +84,7 @@ runs:

# The Lambda functions install the built workspace packages directly (see `src/stack.ts`).
- name: Restore build artifacts
if: inputs.test-application == 'aws-serverless'
if: inputs.download-artifacts == 'true' && inputs.test-application == 'aws-serverless'
uses: actions/download-artifact@v8
with:
name: build-output
Expand Down
34 changes: 34 additions & 0 deletions .github/actions/setup-nx-planner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Set up Nx planner'
description: 'Restores only the locked Nx runtime needed for affected-project selection.'

runs:
using: 'composite'
steps:
- name: Compute planner cache key
id: dependencies
shell: bash
run: |
node scripts/dependency-hash-key.js >> "$GITHUB_OUTPUT"
if [ -x node_modules/.bin/nx ]; then echo 'installed=true' >> "$GITHUB_OUTPUT"; fi

- name: Restore Nx runtime
id: cache
uses: actions/cache@v6.1.0
with:
path: ${{ runner.temp }}/nx-planner
key: nx-planner-v2-${{ steps.dependencies.outputs.hash }}-${{ runner.os }}-${{ runner.arch }}

# A miss uses the regular install; develop also seeds this cache from its existing install.
- name: Install dependencies on cache miss
if: steps.cache.outputs.cache-hit != 'true' && steps.dependencies.outputs.installed != 'true'
uses: ./.github/actions/install-dependencies

- name: Package Nx runtime
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: node "$GITHUB_ACTION_PATH/package-runtime.mjs" "$RUNNER_TEMP/nx-planner"

- name: Use cached Nx runtime
if: steps.cache.outputs.cache-hit == 'true' && steps.dependencies.outputs.installed != 'true'
shell: bash
run: ln -s "$RUNNER_TEMP/nx-planner/node_modules" node_modules
19 changes: 19 additions & 0 deletions .github/actions/setup-nx-planner/package-runtime.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'node:fs';
import { execFileSync } from 'node:child_process';
import path from 'node:path';
import { createRequire } from 'node:module';

const require = createRequire(path.join(process.cwd(), 'package.json'));
const nxPackage = fs.realpathSync(require.resolve('nx/package.json'));
const destination = path.resolve(process.argv[2]);
const modules = path.join(destination, 'node_modules');

// Nx lists its runtime dependency closure directly; pnpm links it all in this directory.
const nxDependencies = path.resolve(nxPackage, '../..');
fs.rmSync(destination, { recursive: true, force: true });
fs.mkdirSync(destination, { recursive: true });
execFileSync('cp', ['-RL', nxDependencies, modules]);
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
// Nx's pnpm lockfile reader requires the install metadata, even without workspace dependencies.
fs.copyFileSync('node_modules/.modules.yaml', path.join(modules, '.modules.yaml'));
fs.mkdirSync(path.join(modules, '.bin'), { recursive: true });
fs.symlinkSync('../nx/dist/bin/nx.js', path.join(modules, '.bin/nx'));
Loading
Loading