Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init e2e test workflow for Package Manager Support #533

Merged
merged 57 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
2f4e039
test: init e2e flow test
0618 Oct 25, 2023
04e6ee4
fix GH hash
0618 Oct 25, 2023
d88786b
use dynamic pkg manager
0618 Oct 25, 2023
c0eb0d4
setup nodejs with npm
0618 Oct 25, 2023
215acbf
setup more pkg managers
0618 Oct 25, 2023
95842bb
install pkg managers
0618 Oct 25, 2023
aaebae2
fix yarn1 and change step name
0618 Oct 25, 2023
45d990c
fix yarn1
0618 Oct 25, 2023
ee1c6c3
fix yarn1
0618 Oct 25, 2023
f856bb8
split yarn1 into 2 steps
0618 Oct 25, 2023
1b11e6e
fix yarn1
0618 Oct 25, 2023
fd937e1
fix yarn1 win
0618 Oct 25, 2023
6e6d06f
exclude bun on windows
0618 Oct 25, 2023
41c89ea
yarn1 windows
0618 Oct 25, 2023
c690620
setup yarn3
0618 Oct 25, 2023
fd2d010
yarn3
0618 Oct 25, 2023
f030ce0
yarn3 yarnPath
0618 Oct 25, 2023
974bfa6
yarn use 3rd party action
0618 Oct 25, 2023
a938e15
try yarn3
0618 Oct 26, 2023
c71302f
set yarn 3.6.x
0618 Oct 26, 2023
71af9a8
set yarn berry
0618 Oct 26, 2023
b28d8b9
set yarn stable and pass --yes
0618 Oct 26, 2023
b41bb05
feat: add env ci support
0618 Oct 26, 2023
e722f11
test: update unit tests
0618 Oct 26, 2023
7dca6da
feat: create amplify --yes option
0618 Oct 26, 2023
70fad76
chore: remove un-used code
0618 Oct 26, 2023
dc2df4b
feat: support Panage Manager env var
0618 Oct 26, 2023
c423170
chore: add comments
0618 Oct 27, 2023
518a43c
Merge branch 'main' into env-ci
0618 Oct 27, 2023
7b88772
chore: remove env.CI
0618 Oct 27, 2023
a085162
chore: update changeset
0618 Oct 27, 2023
988637e
chore: rename PACKAGE_MANAGER_EXECUTABLE
0618 Oct 27, 2023
be3a456
fix: tests
0618 Oct 27, 2023
fb7fa3f
Merge branch 'env-ci' into poc/e2e-test
0618 Oct 27, 2023
3d6d301
use Env Var PACKAGE_MANAGER_EXECUTABLE
0618 Oct 27, 2023
2b90bcc
Merge branch 'main' into poc/e2e-test
0618 Oct 27, 2023
4d3ebc3
fix npm -> npx, remove bun
0618 Oct 27, 2023
7ca0144
fix npm -> npx
0618 Oct 30, 2023
347dae0
change -- --yes
0618 Oct 30, 2023
c0b1bde
Merge branch 'main' into poc/e2e-test
0618 Oct 30, 2023
16fdea3
chore: update package.lock
0618 Oct 30, 2023
d3dc3ec
Merge branch 'update-package-lock' into poc/e2e-test
0618 Oct 30, 2023
3f0f5b2
chore: remove @alpha
0618 Oct 30, 2023
c3b7998
fix: clean up yarn
0618 Oct 30, 2023
a574541
fix: change yarn1 to yarn
0618 Oct 30, 2023
73ff607
chore: rename yarn step
0618 Oct 30, 2023
00b9499
chore: use env
0618 Oct 30, 2023
fbf5b1a
fix: yarn-stable env var
0618 Oct 30, 2023
9c6d8a6
add comments
0618 Oct 30, 2023
185be00
Merge branch 'main' into poc/e2e-test
0618 Oct 30, 2023
a59cf5a
Merge branch 'main' into poc/e2e-test
0618 Oct 31, 2023
3aba42f
Merge branch 'poc/package-manager-support' into poc/e2e-test
0618 Oct 31, 2023
633ec61
chore: update sample app with new imports (#541)
Amplifiyer Oct 31, 2023
863dc24
feat: use "use client"; directive in generated react components (#540)
sdstolworthy Oct 31, 2023
d0119b2
fix: flatten prop types auth (#534)
awsluja Oct 31, 2023
47d2a4f
Merge branch 'main' into poc/e2e-test
0618 Oct 31, 2023
3de87ad
chore: add TODO
0618 Oct 31, 2023
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
6 changes: 6 additions & 0 deletions .changeset/metal-tomatoes-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-amplify': patch
---

1. Create Amplify (temporarily) uses environment variable for Package Manager
2. Create Amplify uses `yes` option to choose the default value for prompts
55 changes: 55 additions & 0 deletions .github/workflows/poc-e2e-flow-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Description: This workflow mimic the flow of behaviors when user using Amplify CLI;

name: 'poc-e2e-flow-test'

on: # TODO: need to change the trigger
push:
branches:
- poc/e2e-test
Comment on lines +5 to +8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we'll need to hook this up into health_checks.
Which means either stuffing this into health_checks OR investing in reusable workflow. See https://docs.github.com/en/actions/using-workflows/reusing-workflows (we did this for canaries in classic CLI).

@edwardfoyle what do you think? health_checks.yml started to be quite big.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add it to health_checks once it's merged to main


jobs:
create-amplify-project:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should figure out how to change this from create-amplify-project to
run_e2e_with_package_manager , so that all e2e tests that do call package manager use it (sandbox, pipeline deploy in addition to create amplify).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's a workflow, we can make is a re-usable GH workflow, however, it seems like just a shared workflow setup (metrics, etc), which I think we have to write it each time

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [18]
pkg-manager: [npm, yarn, yarn-stable, pnpm]
runs-on: ${{ matrix.os }}
env:
PACKAGE_MANAGER_EXECUTABLE: ${{ matrix.pkg-manager }} # TODO: remove PACKAGE_MANAGER_EXECUTABLE once CLI is able to getPackageManager().
steps:
- name: Checkout aws-amplify/amplify-cli repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1. TODO: try only fetch .github/workflow
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 #4.0.0
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Local Publish create-amplify
shell: bash
run: npm run install:local && npm run build && npm run vend
- name: ${{matrix.pkg-manager}}-create-amplify-project
if: matrix.pkg-manager != 'yarn-stable'
shell: bash
run: |
mkdir -p /tmp/amplify-project; cd /tmp/amplify-project
npm install -g ${{matrix.pkg-manager}}
echo "$(${{matrix.pkg-manager}}) config set registry http://localhost:4873"
${{matrix.pkg-manager}} config set registry http://localhost:4873
echo "$(${{matrix.pkg-manager}}) config get registry"
${{matrix.pkg-manager}} config get registry
${{matrix.pkg-manager}} create amplify --yes

- name: yarn-stable-create-amplify-project
if: matrix.pkg-manager == 'yarn-stable'
shell: bash
run: |
mkdir -p /tmp/amplify-project; cd /tmp/amplify-project
corepack enable
echo "yarn set version stable"
yarn set version stable
echo "yarn version $(yarn --version)"
yarn config set unsafeHttpWhitelist localhost
yarn config set npmRegistryServer http://localhost:4873
PACKAGE_MANAGER_EXECUTABLE=yarn yarn create amplify --yes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actions should focus on setting up the runner machine. I.e. making sure package manager is installed and in desired version and available in $PATH (this is a candidate for custom action).

But the test scenario itself should be placed in TS files that contain existing e2e tests. I.e. tests and test framework should be changed to accept package manager setting somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean after the GH workflow setup the test environments, and we should run packages/integration-tests/src/test-e2e/create_amplify.test.ts ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and later just all e2e tests when they work.

Copy link
Contributor Author

@0618 0618 Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Should I update in this PR to run the test-e2e/create_amplify.test.ts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes lets do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test-e2e/create_amplify.test.ts takes more effort to modify than I anticipated. Do you think we can get this PR merged first? It would make it smaller to review as well :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine.
remember that on this branch smaller reviews don't void a need for big review at the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to merge this please leave todo comment in workflow that summarizes our discussion here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Done 3de87ad

17 changes: 16 additions & 1 deletion packages/create-amplify/src/get_project_root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { afterEach, describe, it } from 'node:test';
import assert from 'assert';
import fsp from 'fs/promises';
import path from 'path';
import { getProjectRoot } from './get_project_root.js';
import { AmplifyPrompter } from '@aws-amplify/cli-core';
import { getProjectRoot } from './get_project_root.js';

const originalEnv = process.env;

Expand Down Expand Up @@ -68,4 +68,19 @@ void describe('getProjectRoot', () => {
);
assert.equal(projectRoot, path.resolve(userInput));
});

void it('use default options if `yes`', async (ctx) => {
process.env.npm_config_yes = 'false';
process.argv = ['node', 'test.js', '--yes'];
const userInput = 'test';
const fsMkDirSyncMock = ctx.mock.method(fsp, 'mkdir', () => undefined);
ctx.mock.method(fsp, 'stat', () => Promise.reject(new Error()));
ctx.mock.method(AmplifyPrompter, 'input', () => Promise.resolve(userInput));

const projectRoot = await getProjectRoot();

assert.equal(fsMkDirSyncMock.mock.callCount(), 1);
assert.equal(fsMkDirSyncMock.mock.calls[0].arguments[0], process.cwd());
assert.equal(projectRoot, process.cwd());
});
});
9 changes: 8 additions & 1 deletion packages/create-amplify/src/get_project_root.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import fsp from 'fs/promises';
import path from 'path';
import yargs from 'yargs';
import { AmplifyPrompter } from '@aws-amplify/cli-core';
import { logger } from './logger.js';

/**
* Returns the project root directory.
*/
export const getProjectRoot = async () => {
const useDefault = process.env.npm_config_yes === 'true';
const argv = await yargs(process.argv.slice(2)).options({
yes: {
type: 'boolean',
default: false,
},
}).argv;
const useDefault = process.env.npm_config_yes === 'true' || argv.yes === true;
const defaultProjectRoot = '.';
let projectRoot: string = useDefault
? defaultProjectRoot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void describe('NpmPackageManagerController', () => {
await npmPackageManagerController.installDependencies(['testDep'], 'dev');
assert.deepStrictEqual(execaMock.mock.calls[0].arguments, [
'npm',
['install', 'testDep', '--save-dev'],
['install', 'testDep', '-D'],
{ cwd: 'testPath', stdio: 'inherit' },
]);
});
Expand Down
9 changes: 6 additions & 3 deletions packages/create-amplify/src/npm_package_manager_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class NpmPackageManagerController implements PackageManagerController {
private readonly projectRoot: string,
private readonly execa = _execa
) {}
private readonly executableName = 'npm';
private readonly executableName =
process.env.PACKAGE_MANAGER_EXECUTABLE || 'npm'; // TODO: replace `process.env.PACKAGE_MANAGER_EXECUTABLE` with `getPackageManagerName()` once the test infra is ready.

/**
* Installs the given package names as devDependencies
Expand All @@ -24,9 +25,11 @@ export class NpmPackageManagerController implements PackageManagerController {
packageNames: string[],
type: DependencyType
): Promise<void> => {
const args = ['install'].concat(...packageNames);
const args = [this.executableName === 'yarn' ? 'add' : 'install'].concat(
...packageNames
);
if (type === 'dev') {
args.push('--save-dev');
args.push('-D');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is already merged in https://github.com/aws-amplify/samsara-cli/pull/507/files, I'm not sure why it shows up in this PR...

}
await this.execa(this.executableName, args, {
stdio: 'inherit',
Expand Down
26 changes: 19 additions & 7 deletions packages/create-amplify/src/tsconfig_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class TsConfigInitializer {
private readonly existsSync = _existsSync,
private readonly execa = _execa
) {}
private readonly executableName =
process.env.PACKAGE_MANAGER_EXECUTABLE || 'npx'; // TODO: replace `process.env.PACKAGE_MANAGER_EXECUTABLE` with `getPackageManagerName()` once the test infra is ready.

/**
* If tsconfig.json already exists, this is a noop. Otherwise, `npx tsc --init` is executed to create a tsconfig.json file
Expand All @@ -27,7 +29,9 @@ export class TsConfigInitializer {
return;
}
this.logger.log(
'No tsconfig.json file found in the current directory. Running `npx tsc --init`...'
`No tsconfig.json file found in the current directory. Running \`${
this.executableName === 'npm' ? 'npx' : this.executableName
} tsc --init\`...`
);

const packageJson = await this.packageJsonReader.readPackageJson();
Expand All @@ -53,20 +57,28 @@ export class TsConfigInitializer {
}

try {
await this.execa('npx', tscArgs, {
stdio: 'inherit',
cwd: this.projectRoot,
});
await this.execa(
this.executableName === 'npm' ? 'npx' : this.executableName,
tscArgs,
{
stdio: 'inherit',
cwd: this.projectRoot,
}
);
} catch {
throw new Error(
'`npx tsc --init` did not exit successfully. Initialize a valid TypeScript configuration before continuing.'
`\`${
this.executableName === 'npm' ? 'npx' : this.executableName
} tsc --init\` did not exit successfully. Initialize a valid TypeScript configuration before continuing.`
);
}

if (!this.tsConfigJsonExists()) {
// this should only happen if the customer exits out of npx tsc --init before finishing
throw new Error(
'tsconfig.json does not exist after running `npx tsc --init`. Initialize a valid TypeScript configuration before continuing.'
`tsconfig.json does not exist after running \`${
this.executableName === 'npm' ? 'npx' : this.executableName
} tsc --init\`. Initialize a valid TypeScript configuration before continuing.`
);
}
};
Expand Down
Loading