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

fix: build resource when adding new env #9847

Merged
merged 3 commits into from Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/amplify-category-auth/src/index.js
Expand Up @@ -68,10 +68,8 @@ async function add(context, skipNextSteps = false) {
async function transformCategoryStack(context, resource) {
if (resource.service === AmplifySupportedService.COGNITO) {
if (canResourceBeTransformed(resource.resourceName)) {
generateAuthStackTemplate(context, resource.resourceName);
await generateAuthStackTemplate(context, resource.resourceName);
}
} else if (resource.service === 'S3') {
// Not yet implemented
}
}

Expand Down
33 changes: 33 additions & 0 deletions packages/amplify-e2e-core/src/init/initProjectHelper.ts
Expand Up @@ -348,6 +348,39 @@ export function initNewEnvWithProfile(cwd: string, s: { envName: string }): Prom
});
}

export function updatedInitNewEnvWithProfile(cwd: string, s: { envName: string }): Promise<void> {
addCircleCITags(cwd);

return new Promise((resolve, reject) => {
spawn(getCLIPath(), ['init'], {
cwd,
stripColors: true,
env: {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
})
.wait('Do you want to use an existing environment?')
.sendConfirmNo()
.wait('Enter a name for the environment')
.sendLine(s.envName)
.wait('Choose your default editor:')
.sendCarriageReturn()
.wait('Using default provider awscloudformation')
.wait('Select the authentication method you want to use:')
.sendCarriageReturn()
.wait('Please choose the profile you want to use')
.sendCarriageReturn()
.wait(/Try "amplify add api" to create a backend API and then "amplify (push|publish)" to deploy everything/)
.run((err: Error) => {
if (!err) {
resolve();
} else {
reject(err);
}
});
});
}

export function amplifyInitSandbox(cwd: string, settings: {}): Promise<void> {
const s = { ...defaultSettings, ...settings };
let env;
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-e2e-core/src/utils/index.ts
Expand Up @@ -24,6 +24,7 @@ export * from './sleep';
export * from './transformConfig';
export * from './admin-ui';
export * from './hooks';
export * from './transform-current-project-to-git-pulled-project';

// run dotenv config to update env variable
config();
Expand Down
@@ -0,0 +1,26 @@
import { pathManager } from 'amplify-cli-core';
import * as fs from 'fs-extra';
import glob from 'glob';

/**
*
* @param projRoot : string
* deleting files matching .gitignore regex
*/
export const transformCurrentProjectToGitPulledProject = (projRoot: string) => {
const gitIgnoreFilePath = pathManager.getGitIgnoreFilePath(projRoot);
const regexrArray = fs.readFileSync(gitIgnoreFilePath, 'utf-8').split('\n');
regexrArray.forEach(str => {
jhockett marked this conversation as resolved.
Show resolved Hide resolved
const dirPath = glob.sync(str, {
cwd: projRoot,
absolute: true,
});
dirPath.forEach(file => {
if (fs.existsSync(file) && fs.lstatSync(file).isDirectory()) {
fs.removeSync(file);
} else {
fs.unlinkSync(file);
}
});
});
};
@@ -1,5 +1,18 @@
import { category } from '@aws-amplify/amplify-category-auth';
import {
addAuthWithDefault,
amplifyPushAuth,
createNewProjectDir,
deleteProject,
deleteProjectDir,
getBackendAmplifyMeta,
getParameters,
getTeamProviderInfo,
initJSProjectWithProfile,
initNewEnvWithProfile,
transformCurrentProjectToGitPulledProject,
} from 'amplify-e2e-core';
import * as specialCaseInit from '../init-special-cases';
import { createNewProjectDir, getBackendAmplifyMeta, deleteProject, deleteProjectDir } from 'amplify-e2e-core';

describe('amplify init', () => {
let projRoot: string;
Expand All @@ -21,4 +34,29 @@ describe('amplify init', () => {
expect(AuthRoleName).toBeIAMRoleWithArn(AuthRoleArn);
expect(DeploymentBucketName).toBeAS3Bucket(DeploymentBucketName);
});

it('test init on a git pulled project', async () => {
const envName = 'dev';
const resourceName = 'authConsoleTest';
await initJSProjectWithProfile(projRoot, { disableAmplifyAppCreation: false, name: resourceName, envName });
await addAuthWithDefault(projRoot, {});
await amplifyPushAuth(projRoot);
let teamInfo = getTeamProviderInfo(projRoot);
expect(teamInfo).toBeDefined();
let appId = teamInfo[envName].awscloudformation.AmplifyAppId;
let stackName = teamInfo[envName].awscloudformation.StackName;
expect(stackName).toBeDefined();
expect(appId).toBeDefined();
expect(teamInfo[envName].categories.auth).toBeDefined();
/**
* simulate git clone by deleteing files based on .gitignore
*/
transformCurrentProjectToGitPulledProject(projRoot);

// to not crash
expect(await initNewEnvWithProfile(projRoot, { envName })).not.toThrow();

// check parameters.json exists
expect(getParameters(projRoot, category, resourceName)).not.toThrow();
});
});
Expand Up @@ -13,6 +13,8 @@ import { pullHooks } from './utils/hooks-manager';
import { buildOverridesEnabledResources } from './build-override-enabled-resources';

export async function run(context: $TSContext, providerMetadata: $TSMeta) {
await buildOverridesEnabledResources(context);

if (context.exeInfo && context.exeInfo.isNewEnv) {
return context;
}
Expand Down Expand Up @@ -115,6 +117,4 @@ export async function run(context: $TSContext, providerMetadata: $TSMeta) {
if (hasMigratedResources) {
stateManager.setCurrentMeta(undefined, amplifyMeta);
}

await buildOverridesEnabledResources(context);
}