Skip to content

Commit

Permalink
test: use GH workflow for e2e test of create amplify (#636)
Browse files Browse the repository at this point in the history
* feat: setup GH workflow for create amplify

* chore: changeset

* fix: add pkg type for modern yarn

* fix npm install

* feat: test Node v20 and Node v19

* feat: test Node v20 and yarn-stable with Node 19

* feat: exclude yarn-stable

* feat: include node 20 and exclude node 19

* feat: use node 20 for others, use node 19 for yarn-stable

* chore: add TODO to use Node 20
  • Loading branch information
0618 authored Nov 13, 2023
1 parent c1edfdf commit c34a987
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 63 deletions.
7 changes: 7 additions & 0 deletions .changeset/small-readers-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@aws-amplify/integration-tests': patch
'create-amplify': patch
---

- Support yarn, pnpm via env var
- Add e2e test against yarn, pnpm
93 changes: 55 additions & 38 deletions .github/workflows/poc-e2e-flow-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,70 @@ name: 'poc-e2e-flow-test'
on: # TODO: need to change the trigger
push:
branches:
- poc/e2e-test
- poc/e2e-create-amplify

jobs:
create-amplify-project:
install:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node-version: [18]
pkg-manager: [npm, yarn, yarn-stable, pnpm]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout aws-amplify/amplify-cli repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node.js
uses: ./.github/actions/setup_node
- name: Install or Restore Cache
uses: ./.github/actions/install_with_cache
build:
runs-on: ubuntu-latest
needs:
- install
steps:
- name: Checkout aws-amplify/amplify-cli repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node.js
uses: ./.github/actions/setup_node
- name: Build or Restore Build Cache
uses: ./.github/actions/build_with_cache
run_e2e_tests:
strategy:
# will finish running other test matrices even if one fails
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
pkg-manager: [npm, yarn, pnpm]
node-version: [20]
include:
- os: ubuntu-latest
pkg-manager: yarn-stable
node-version: 19 # TODO: use Node 20 once https://github.com/yarnpkg/berry/pull/5961 is released
- os: macos-latest
pkg-manager: yarn-stable
node-version: 19 # TODO: use Node 20 once https://github.com/yarnpkg/berry/pull/5961 is released
- os: windows-latest
pkg-manager: yarn-stable
node-version: 19 # TODO: use Node 20 once https://github.com/yarnpkg/berry/pull/5961 is released
env:
PACKAGE_MANAGER_EXECUTABLE: ${{ matrix.pkg-manager }} # TODO: remove PACKAGE_MANAGER_EXECUTABLE once CLI is able to getPackageManager().
ACKAGE_MANAGER_EXECUTABLE: ${{ matrix.pkg-manager }} # TODO: remove PACKAGE_MANAGER_EXECUTABLE once CLI is able to getPackageManager().
runs-on: ${{ matrix.os }}
timeout-minutes: 60
needs:
- build
permissions:
# these permissions are required for the configure-aws-credentials action to get a JWT from GitHub
id-token: write
contents: read
steps:
- name: Checkout aws-amplify/amplify-cli repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1. TODO: try only fetch .github/workflow
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 #4.0.0
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # version 3.8.1
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:
| # TODO: last step `create amplify` should be replaced by `run e2e`
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'
- name: Restore Build Cache
uses: ./.github/actions/restore_build_cache
- name: Run E2E tests with ${{ matrix.pkg-manager }}
shell: bash
run:
| # TODO: last step `create amplify` should be replaced by `run e2e`
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
run: |
PACKAGE_MANAGER_EXECUTABLE=${{matrix.pkg-manager}} npm run test:dir packages/integration-tests/src/test-e2e/create_amplify.test.ts
20 changes: 16 additions & 4 deletions packages/create-amplify/src/npm_package_manager_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ export class NpmPackageManagerController implements PackageManagerController {
private readonly projectRoot: string,
private readonly execa = _execa
) {}
private readonly executableName =
process.env.PACKAGE_MANAGER_EXECUTABLE || 'npm'; // TODO: replace `process.env.PACKAGE_MANAGER_EXECUTABLE` with `getPackageManagerName()` once the test infra is ready.
private readonly executableName = !process.env.PACKAGE_MANAGER_EXECUTABLE
? 'npm'
: process.env.PACKAGE_MANAGER_EXECUTABLE === 'yarn-stable'
? 'yarn'
: process.env.PACKAGE_MANAGER_EXECUTABLE; // TODO: replace `process.env.PACKAGE_MANAGER_EXECUTABLE` with `getPackageManagerName()` once the test infra is ready.

/**
* Installs the given package names as devDependencies
Expand All @@ -34,9 +37,18 @@ export class NpmPackageManagerController implements PackageManagerController {
}

try {
await executeWithDebugLogger(this.projectRoot, 'npm', args, this.execa);
await executeWithDebugLogger(
this.projectRoot,
this.executableName,
args,
this.execa
);
} catch {
throw new Error(`\`npm ${args.join(' ')}\` did not exit successfully.`);
throw new Error(
`\`${this.executableName} ${args.join(
' '
)}\` did not exit successfully.`
);
}
};
}
7 changes: 5 additions & 2 deletions packages/create-amplify/src/tsconfig_initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ 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.
private readonly executableName = !process.env.PACKAGE_MANAGER_EXECUTABLE
? 'npx'
: process.env.PACKAGE_MANAGER_EXECUTABLE === 'yarn-stable'
? 'yarn'
: process.env.PACKAGE_MANAGER_EXECUTABLE; // 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 Down
Loading

0 comments on commit c34a987

Please sign in to comment.