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: add init prompts for Gen2 #13849

Merged
merged 50 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
592abd1
feat: add warning to init
Jul 9, 2024
d0a26e0
feat: add prompt to init
Jul 10, 2024
365eab4
feat: only prompt on new project
Jul 10, 2024
631a252
feat: add guide to Gen2
Jul 10, 2024
c0c4e3e
refactor: change to use process exit
Jul 10, 2024
5d53a55
Update packages/amplify-cli/src/init-steps/preInitMigrationWarning.ts
0618 Jul 10, 2024
49a9f01
refactor: rename to gen2Recommendation
Jul 10, 2024
0d3a057
refactor: combine gen2Recommendation to preInitSetup
Jul 10, 2024
cadc06f
feat: remove goodbye message
Jul 10, 2024
39f8b34
test: fix init.test
Jul 10, 2024
e4330c3
test: add unit test for preInitSetup
Jul 10, 2024
08e896a
chore: rename to getPreInitSetup
Jul 10, 2024
22cff01
feat: change verbiage
Jul 10, 2024
85cd59a
chore: update unit test
Jul 10, 2024
f12fe7a
feat: add whyContinueWithGen1 to stack metadata
Jul 10, 2024
bad9430
fix: verify verify_versions_match
Jul 11, 2024
ad48c8d
fix: verify verify_versions_match
Jul 11, 2024
2378a19
feat: bump versions
Jul 11, 2024
ad3ab5e
feat: bump versions
Jul 12, 2024
cac0e9d
feat: bump versions
Jul 12, 2024
dfba32e
chore: rename to recommendGen2
Jul 12, 2024
aa1850c
chore: rename to recommendGen2 in test
Jul 12, 2024
fba0211
revert .sh format
Jul 15, 2024
1e8e25b
chore: rename and not export preInitSetup
Jul 15, 2024
3d1bb59
fix: export gen2Recommandation and preInitSetup for test
Jul 15, 2024
c20f939
Merge branch 'dev' into add-init-promps
Aug 5, 2024
7ecde5c
fix: set inital answer for pick
Aug 7, 2024
e67d7cc
Merge branch 'dev' into add-init-promps
Aug 8, 2024
d8fa624
Revert "fix: set inital answer for pick"
Aug 8, 2024
1d671cf
Revert "Revert "fix: set inital answer for pick""
Aug 8, 2024
6fc0979
fix: preInitSetup.test
Aug 8, 2024
71b204c
fix: e2e test by adding isCI
Aug 12, 2024
20157e7
chore: upgrade node-pty
Aug 13, 2024
203d1ca
Merge branch 'dev' into add-init-promps
Aug 14, 2024
66ae2a1
Revert "fix: e2e test by adding isCI"
Aug 14, 2024
d94ed5e
test: add prompt to e2e
Aug 14, 2024
ea7b9de
fix: set default value for whyContinueWithGen1
Aug 14, 2024
faa0859
fix: projectConfig undefined and remove default choice
Aug 17, 2024
c540b9c
fix: preInitSetup.test.ts
Aug 17, 2024
bbeec57
fix: add default choice back
Aug 17, 2024
bb73c4b
fix: remove prompts from migration test
Aug 19, 2024
13b81af
test: move new prompt from v12
Sep 2, 2024
eeb6f71
test: move new prompt from initJSProjectWithProfile
Sep 3, 2024
4e7fd0c
Revert "test: move new prompt from initJSProjectWithProfile"
Sep 3, 2024
57342e6
test: move new prompts from initJSProjectWithProfile
Sep 3, 2024
9d92f56
chore: change recommendGen2
Sep 8, 2024
7548ef8
test: fix preInitSetup unit test
Sep 8, 2024
fc21886
test: add includeGen2RecommendationPrompt
Sep 8, 2024
fd5f0d7
test: add includeGen2RecommendationPrompt to migration-2
Sep 8, 2024
808c795
test: remove prompts from initAndroidProjectWithProfileV12
Sep 8, 2024
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
170 changes: 83 additions & 87 deletions .circleci/local_publish_helpers_codebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ function startLocalRegistry {
(cd && nohup npx ${VERDACCIO_PACKAGE:-$default_verdaccio_package} -c $1 &>$tmp_registry_log &)
# Wait for Verdaccio to boot
attempts=0
until grep -q 'http address' $tmp_registry_log
do
attempts=$((attempts+1))
echo "Waiting for Verdaccio, attempt $attempts"
sleep 1

if (( attempts > 60 )); then
echo "Verdaccio didn't start";
exit 1
fi
until grep -q 'http address' $tmp_registry_log; do
attempts=$((attempts + 1))
echo "Waiting for Verdaccio, attempt $attempts"
sleep 1

if ((attempts > 60)); then
echo "Verdaccio didn't start"
exit 1
fi
done
}

Expand All @@ -32,18 +31,18 @@ function uploadPkgCliCodeBuild {

# validate that version is uploaded in right build
if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ "$PROJECT_NAME" != "Release" ]]; then
echo "Invalid project name $PROJECT_NAME for $version release."
exit 1
fi
if [[ "$PROJECT_NAME" != "Release" ]]; then
echo "Invalid project name $PROJECT_NAME for $version release."
exit 1
fi
elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\. ]]; then
if [[ "$PROJECT_NAME" != "RC" ]]; then
echo "Invalid project name $PROJECT_NAME for $version RC release."
exit 1
fi
if [[ "$PROJECT_NAME" != "RC" ]]; then
echo "Invalid project name $PROJECT_NAME for $version RC release."
exit 1
fi
elif [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+-$ ]]; then
echo "Version $version is missing a tag";
exit 1
echo "Version $version is missing a tag"
exit 1
fi

# It's ok to re-upload binaries for the same build to make this step idempotent
Expand All @@ -58,54 +57,54 @@ function uploadPkgCliCodeBuild {
}

function generatePkgCli {
cd pkg
cd pkg

# install package depedencies
cp ../yarn.lock ./
yarn workspaces focus --production
# install package depedencies
cp ../yarn.lock ./
yarn workspaces focus --production

# Optimize package size
find . \
-name "*.d.ts" -or -name "*.js.map" -or -name "*.d.ts.map" -or \
-iname "readme.md" -or -iname "changelog.md" -or -iname "history.md" \
| xargs rm
# Optimize package size
find . \
-name "*.d.ts" -or -name "*.js.map" -or -name "*.d.ts.map" -or \
-iname "readme.md" -or -iname "changelog.md" -or -iname "history.md" |
xargs rm

# Restore .d.ts files required by @aws-amplify/codegen-ui at runtime
cp ../node_modules/typescript/lib/*.d.ts node_modules/typescript/lib/
# Restore .d.ts files required by @aws-amplify/codegen-ui at runtime
cp ../node_modules/typescript/lib/*.d.ts node_modules/typescript/lib/

# replace DEV binary entry point with production one
cp ../node_modules/@aws-amplify/cli-internal/bin/amplify.production.template node_modules/@aws-amplify/cli-internal/bin/amplify
# replace DEV binary entry point with production one
cp ../node_modules/@aws-amplify/cli-internal/bin/amplify.production.template node_modules/@aws-amplify/cli-internal/bin/amplify

# Transpile code for packaging
npx babel node_modules --extensions '.js,.jsx,.es6,.es,.ts' --copy-files --include-dotfiles -d ../build/node_modules
# Transpile code for packaging
npx babel node_modules --extensions '.js,.jsx,.es6,.es,.ts' --copy-files --include-dotfiles -d ../build/node_modules

# Include third party licenses
cp ../Third_Party_Licenses.txt ../build/node_modules
# Include third party licenses
cp ../Third_Party_Licenses.txt ../build/node_modules

# Build pkg cli
cp package.json ../build/node_modules/package.json
# Build pkg cli
cp package.json ../build/node_modules/package.json

if [[ "$@" =~ 'arm' ]]; then
npx pkg --no-bytecode --public-packages "*" --public -t node18-linux-arm64 ../build/node_modules -o ../out/amplify-pkg-linux-arm64
tar -czvf ../out/amplify-pkg-linux-arm64.tgz ../out/amplify-pkg-linux-arm64
fi
if [[ "$@" =~ 'arm' ]]; then
npx pkg --no-bytecode --public-packages "*" --public -t node18-linux-arm64 ../build/node_modules -o ../out/amplify-pkg-linux-arm64
tar -czvf ../out/amplify-pkg-linux-arm64.tgz ../out/amplify-pkg-linux-arm64
fi

if [[ "$@" =~ 'linux' ]]; then
npx pkg -t node18-linux-x64 ../build/node_modules -o ../out/amplify-pkg-linux-x64
tar -czvf ../out/amplify-pkg-linux-x64.tgz ../out/amplify-pkg-linux-x64
fi
if [[ "$@" =~ 'linux' ]]; then
npx pkg -t node18-linux-x64 ../build/node_modules -o ../out/amplify-pkg-linux-x64
tar -czvf ../out/amplify-pkg-linux-x64.tgz ../out/amplify-pkg-linux-x64
fi

if [[ "$@" =~ 'macos' ]]; then
npx pkg -t node18-macos-x64 ../build/node_modules -o ../out/amplify-pkg-macos-x64
tar -czvf ../out/amplify-pkg-macos-x64.tgz ../out/amplify-pkg-macos-x64
fi
if [[ "$@" =~ 'macos' ]]; then
npx pkg -t node18-macos-x64 ../build/node_modules -o ../out/amplify-pkg-macos-x64
tar -czvf ../out/amplify-pkg-macos-x64.tgz ../out/amplify-pkg-macos-x64
fi

if [[ "$@" =~ 'win' ]]; then
npx pkg -t node18-win-x64 ../build/node_modules -o ../out/amplify-pkg-win-x64.exe
tar -czvf ../out/amplify-pkg-win-x64.tgz ../out/amplify-pkg-win-x64.exe
fi
if [[ "$@" =~ 'win' ]]; then
npx pkg -t node18-win-x64 ../build/node_modules -o ../out/amplify-pkg-win-x64.exe
tar -czvf ../out/amplify-pkg-win-x64.tgz ../out/amplify-pkg-win-x64.exe
fi

cd ..
cd ..
}

function verifyPkgCli {
Expand All @@ -115,28 +114,28 @@ function verifyPkgCli {
wc -c out/*

function verifySinglePkg {
binary_name=$1
compressed_binary_name=$2
binary_threshold_in_bytes=$3

# Compressed binary size is not deterministic enough to have stricter threshold.
# I.e. it depends on how compression algorithm can compress bytecode and there are cases where compressed size
# grows even if uncompressed size drops. We don't have control on bytecode and compression.
# Therefore we check if compression gets past half of original size as sanity check.
compressed_binary_threshold_in_bytes=$((binary_threshold_in_bytes/2))

binary_size=$(wc -c out/$binary_name | awk '{print $1}')
compressed_binary_size=$(wc -c out/$compressed_binary_name | awk '{print $1}')

if (( binary_size > binary_threshold_in_bytes )); then
echo "$binary_name size has grown over $binary_threshold_in_bytes bytes"
exit 1
fi
binary_name=$1
compressed_binary_name=$2
binary_threshold_in_bytes=$3

# Compressed binary size is not deterministic enough to have stricter threshold.
# I.e. it depends on how compression algorithm can compress bytecode and there are cases where compressed size
# grows even if uncompressed size drops. We don't have control on bytecode and compression.
# Therefore we check if compression gets past half of original size as sanity check.
compressed_binary_threshold_in_bytes=$((binary_threshold_in_bytes / 2))

binary_size=$(wc -c out/$binary_name | awk '{print $1}')
compressed_binary_size=$(wc -c out/$compressed_binary_name | awk '{print $1}')

if ((binary_size > binary_threshold_in_bytes)); then
echo "$binary_name size has grown over $binary_threshold_in_bytes bytes"
exit 1
fi

if (( compressed_binary_size > compressed_binary_threshold_in_bytes )); then
echo "$compressed_binary_name size has grown over $compressed_binary_threshold_in_bytes bytes"
exit 1
fi
if ((compressed_binary_size > compressed_binary_threshold_in_bytes)); then
echo "$compressed_binary_name size has grown over $compressed_binary_threshold_in_bytes bytes"
exit 1
fi
}

verifySinglePkg "amplify-pkg-linux-x64" "amplify-pkg-linux-x64.tgz" $((830 * 1024 * 1024))
Expand Down Expand Up @@ -214,12 +213,11 @@ function retry {
n=0
FAILED_TEST_REGEX_FILE="./amplify-e2e-reports/amplify-e2e-failed-test.txt"
rm -f $FAILED_TEST_REGEX_FILE
until [ $n -ge $MAX_ATTEMPTS ]
do
until [ $n -ge $MAX_ATTEMPTS ]; do
echo "Attempting $@ with max retries $MAX_ATTEMPTS"
setAwsAccountCredentials
"$@" && break
n=$[$n+1]
n=$(($n + 1))
awsluja marked this conversation as resolved.
Show resolved Hide resolved
FIRST_RUN=false
echo "Attempt $n completed."
sleep $SLEEP_DURATION
Expand Down Expand Up @@ -261,7 +259,7 @@ function setAwsAccountCredentials {
export AWS_SECRET_ACCESS_KEY_ORIG=$AWS_SECRET_ACCESS_KEY
export AWS_SESSION_TOKEN_ORIG=$AWS_SESSION_TOKEN
# introduce a delay of up to 1 minute to allow for more even spread aws list-accounts calls due to throttling
sleep $[ ( $RANDOM % 60 ) + 1 ]s
sleep $((($RANDOM % 60) + 1))s
if [[ "$OSTYPE" == "msys" ]]; then
# windows provided by circleci has this OSTYPE
useChildAccountCredentials
Expand All @@ -278,7 +276,7 @@ function runE2eTestCb {
_setupCoverage
FAILED_TEST_REGEX_FILE="./amplify-e2e-reports/amplify-e2e-failed-test.txt"

if [ -f $FAILED_TEST_REGEX_FILE ]; then
if [ -f $FAILED_TEST_REGEX_FILE ]; then
# read the content of failed tests
failedTests=$(<$FAILED_TEST_REGEX_FILE)
if [[ ! -z "$DISABLE_COVERAGE" ]]; then
Expand All @@ -300,15 +298,13 @@ function runE2eTestCb {
function _setupCoverage {
_teardownCoverage
echo "Setup Coverage ($E2E_TEST_COVERAGE_DIR)"
if [ ! -d $E2E_TEST_COVERAGE_DIR ]
then
if [ ! -d $E2E_TEST_COVERAGE_DIR ]; then
mkdir -p $E2E_TEST_COVERAGE_DIR
fi
}

function _teardownCoverage {
if [ -d $E2E_TEST_COVERAGE_DIR ]
then
if [ -d $E2E_TEST_COVERAGE_DIR ]; then
echo "Teardown Coverage ($E2E_TEST_COVERAGE_DIR)"
rm -r $E2E_TEST_COVERAGE_DIR
fi
Expand All @@ -323,7 +319,7 @@ function checkPackageVersionsInLocalNpmRegistry {

if [[ $cli_internal_version != $cli_version ]]; then
echo "Versions did not match."
echo "Manual fix: add a proper conventional commit that touches the amplify-cli-npm package to correct its version bump. For example https://github.com/aws-amplify/amplify-cli/commit/6f14792d1db424aa428ec4836fed7d6dd5cccfd0"
echo "Manual fix: add a proper conventional commit that touches the amplify-cli-npm package to correct its version bump. For example https://github.com/aws-amplify/amplify-cli/pull/13759/commits/15dcd96feae925ff26ca51abfb4a0477890af745"
awsluja marked this conversation as resolved.
Show resolved Hide resolved
exit 1
else
echo "Versions matched."
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli-npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export const install = async (): Promise<void> => {
return binary.install();
};

// force version bump to 12.12.0
// force version bump to 12.12.5
awsluja marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions packages/amplify-cli/src/__tests__/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { execSync } from 'child_process';
import { ensureDir, existsSync, readFileSync, readJSON, readdirSync } from 'fs-extra';
import { sync } from 'which';
import { preInitSetup } from '../../init-steps/preInitSetup';
import { getPreInitSetup } from '../../init-steps/preInitSetup';
import { analyzeProject } from '../../init-steps/s0-analyzeProject';
import { initFrontend } from '../../init-steps/s1-initFrontend';
import { scaffoldProjectHeadless } from '../../init-steps/s8-scaffoldHeadless';
Expand Down Expand Up @@ -137,7 +137,9 @@ describe('amplify init:', () => {
},
},
};
await preInitSetup(context as unknown as $TSContext);
const isHeadless = true;
const step = getPreInitSetup(!isHeadless);
await step(context as unknown as $TSContext);
expect(execSync).toBeCalledWith(`git ls-remote ${appUrl}`, { stdio: 'ignore' });
expect(execSync).toBeCalledWith(`git clone ${appUrl} .`, { stdio: 'inherit' });
expect(execSync).toBeCalledWith('yarn install', { stdio: 'inherit' });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { $TSContext } from '@aws-amplify/amplify-cli-core';
import { printer, prompter } from '@aws-amplify/amplify-prompts';
import { getPreInitSetup, preInitSetupBasic, gen2Recommendation } from '../../init-steps/preInitSetup';
import { isNewProject } from '../../init-steps/s0-analyzeProject';

// Mock dependencies
jest.mock('@aws-amplify/amplify-cli-core', () => ({
...(jest.requireActual('@aws-amplify/amplify-cli-core') as {}),
FeatureFlags: {
getBoolean: jest.fn(),
getNumber: jest.fn(),
isInitialized: jest.fn().mockReturnValue(true),
ensureDefaultFeatureFlags: jest.fn(),
},
getPackageManager: jest.fn(),
}));

jest.mock('@aws-amplify/amplify-prompts', () => ({
printer: {
warn: jest.fn(),
},
prompter: {
confirmContinue: jest.fn(),
pick: jest.fn(),
},
}));

jest.mock('../../init-steps/s0-analyzeProject', () => ({
isNewProject: jest.fn(),
}));

describe('preInitSetup', () => {
it('should return preInitSetupBasic when isHeadless is true', () => {
const result = getPreInitSetup(true);
expect(result).toBe(preInitSetupBasic);
});

it('should return a function when isHeadless is false', () => {
const result = getPreInitSetup(false);
expect(typeof result).toBe('function');
});
});

describe('gen2Recommendation', () => {
let context;

beforeEach(() => {
context = { exeInfo: {} } as $TSContext;
});

afterEach(() => {
jest.clearAllMocks();
});

it('should recommend using Gen 2 for new projects', async () => {
const isNewProjectMock = jest.mocked(isNewProject);
isNewProjectMock.mockReturnValue(true);

const confirmContinueMock = jest.mocked(prompter.confirmContinue);
confirmContinueMock.mockResolvedValue(true);

const pickMock = jest.mocked(prompter.pick);
pickMock.mockResolvedValue('I am a current Gen 1 user');

await gen2Recommendation(context);

expect(require('@aws-amplify/amplify-prompts').printer.warn).toHaveBeenCalledWith(
'For new projects, we recommend starting with AWS Amplify Gen 2, our new code-first developer experience. Get started at https://docs.amplify.aws/react/start/quickstart/',
);
expect(confirmContinueMock).toHaveBeenCalledWith('Do you want to continue with Amplify Gen 1?');
expect(pickMock).toHaveBeenCalledWith('Why would you like to use Amplify Gen 1?', expect.any(Array));
expect(context.exeInfo.projectConfig).toEqual({ whyContinueWithGen1: 'I am a current Gen 1 user' });
});

it('should return the context for existing projects', async () => {
const isNewProjectMock = jest.mocked(isNewProject);
isNewProjectMock.mockReturnValue(false);

const result = await gen2Recommendation(context);

expect(result).toEqual(context);
expect(printer.warn).not.toHaveBeenCalled();
expect(prompter.confirmContinue).not.toHaveBeenCalled();
expect(prompter.pick).not.toHaveBeenCalled();
});
});
7 changes: 4 additions & 3 deletions packages/amplify-cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { constructInputParams } from '../amplify-service-helper';
import { Context } from '../domain/context';
import { raisePostEnvAddEvent } from '../execution-manager';
import { postInitSetup } from '../init-steps/postInitSetup';
import { preInitSetup } from '../init-steps/preInitSetup';
import { getPreInitSetup } from '../init-steps/preInitSetup';
import { analyzeProject, analyzeProjectHeadless } from '../init-steps/s0-analyzeProject';
import { initFrontend } from '../init-steps/s1-initFrontend';
import { initProviders } from '../init-steps/s2-initProviders';
Expand All @@ -18,11 +18,12 @@ const constructExeInfo = (context: $TSContext): void => {
};
};

const isHeadless = true;
awsluja marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const runStrategy = (quickstart: boolean) =>
quickstart
? [preInitSetup, analyzeProjectHeadless, scaffoldProjectHeadless, onHeadlessSuccess]
: [preInitSetup, analyzeProject, initFrontend, initProviders, onSuccess, postInitSetup];
? [getPreInitSetup(isHeadless), analyzeProjectHeadless, scaffoldProjectHeadless, onHeadlessSuccess]
: [getPreInitSetup(!isHeadless), analyzeProject, initFrontend, initProviders, onSuccess, postInitSetup];

/**
* entry point for the init command
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,5 @@ export const executeAmplifyCommand = async (context: Context): Promise<void> =>
}
};

// bump version to 12.12.0
// bump version to 12.12.5
//
Loading
Loading