Skip to content

Commit

Permalink
fix: aws-amplify#6097 - don't create build folder during dryrun (aws-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Hajdrik authored Dec 11, 2020
1 parent 37d08d9 commit b22e491
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,7 @@ workflows:
- backendManager
- iterative-update
- release
- compute-functions
requires:
- build
- build_pkg_binaries:
Expand Down Expand Up @@ -2260,6 +2261,7 @@ workflows:
branches:
only:
- master
- compute-functions
- iterative-update
requires:
- publish_to_local_registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import { loadProject as readTransformerConfiguration } from './transform-config'
import { loadProject } from 'graphql-transformer-core';
import { AppSyncAuthConfiguration } from '@aws-amplify/graphql-transformer-core';
import { Template } from '@aws-amplify/graphql-transformer-core/lib/config/project-config';
import { AmplifyCLIFeatureFlagAdapter } from '../utils/amplify-cli-feature-flag-adapter';
import { AmplifyCLIFeatureFlagAdapter } from '../utils/amplify-cli-feature-flag-adapter';
import { JSONUtilities } from 'amplify-cli-core';

const API_CATEGORY = 'api';
const STORAGE_CATEGORY = 'storage';
Expand All @@ -32,7 +33,7 @@ const S3_SERVICE_NAME = 'S3';
const TRANSFORM_CONFIG_FILE_NAME = `transform.conf.json`;

function warnOnAuth(context, map) {
const a:boolean = true;
const a: boolean = true;
const unAuthModelTypes = Object.keys(map).filter(type => !map[type].includes('auth') && map[type].includes('model'));
if (unAuthModelTypes.length) {
context.print.warning("\nThe following types do not have '@auth' enabled. Consider using @auth with @model");
Expand Down Expand Up @@ -238,10 +239,17 @@ export async function transformGraphQLSchema(context, options) {
S3DeploymentRootKey: deploymentRootKey,
};

fs.ensureDirSync(buildDir);
// If it is a dry run, don't create the build folder as it could make a follow-up command
// to not to trigger a build, hence a corrupt deployment.
if (!options.dryRun) {
fs.ensureDirSync(buildDir);
}

const project = await loadProject(resourceDir);

const lastDeployedProjectConfig = fs.existsSync(previouslyDeployedBackendDir) ? await loadProject(previouslyDeployedBackendDir): undefined;
const lastDeployedProjectConfig = fs.existsSync(previouslyDeployedBackendDir)
? await loadProject(previouslyDeployedBackendDir)
: undefined;

// Check for common errors
const directiveMap = collectDirectivesByTypeNames(project.schema);
Expand All @@ -258,7 +266,7 @@ export async function transformGraphQLSchema(context, options) {
const buildConfig: ProjectOptions<TransformerFactoryArgs> = {
...options,
buildParameters,
projectDirectory: options.dryrun ? false : resourceDir,
projectDirectory: resourceDir,
transformersFactory: transformerListFactory,
transformersFactoryArgs: [searchableTransformerFlag, storageConfig],
rootStackFileName: 'cloudformation-template.json',
Expand All @@ -273,11 +281,10 @@ export async function transformGraphQLSchema(context, options) {
context.print.success(`\nGraphQL schema compiled successfully.\n\nEdit your schema at ${schemaFilePath} or \
place .graphql files in a directory at ${schemaDirPath}`);

const parametersStr = JSON.stringify(parameters, null, 4);

if (!options.dryRun) {
fs.writeFileSync(parametersFilePath, parametersStr, 'utf8');
JSONUtilities.writeJson(parametersFilePath, parameters);
}

return transformerOutput;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { KeyTransformer } from 'graphql-key-transformer';
import { ProviderName as providerName } from './constants';
import { AmplifyCLIFeatureFlagAdapter } from './utils/amplify-cli-feature-flag-adapter';
import { isAmplifyAdminApp } from './utils/admin-helpers';
import { stateManager } from 'amplify-cli-core';
import { JSONUtilities, stateManager } from 'amplify-cli-core';

import {
collectDirectivesByTypeNames,
Expand Down Expand Up @@ -445,7 +445,12 @@ export async function transformGraphQLSchema(context, options) {
S3DeploymentRootKey: deploymentRootKey,
};

fs.ensureDirSync(buildDir);
// If it is a dry run, don't create the build folder as it could make a follow-up command
// to not to trigger a build, hence a corrupt deployment.
if (!options.dryRun) {
fs.ensureDirSync(buildDir);
}

// Transformer compiler code
// const schemaText = await readProjectSchema(resourceDir);
const project = await readProjectConfiguration(resourceDir);
Expand All @@ -467,7 +472,7 @@ export async function transformGraphQLSchema(context, options) {
const buildConfig = {
...options,
buildParameters,
projectDirectory: options.dryrun ? false : resourceDir,
projectDirectory: resourceDir,
transformersFactory: transformerListFactory,
transformersFactoryArgs: [searchableTransformerFlag, storageConfig],
rootStackFileName: 'cloudformation-template.json',
Expand All @@ -480,11 +485,10 @@ export async function transformGraphQLSchema(context, options) {
context.print.success(`\nGraphQL schema compiled successfully.\n\nEdit your schema at ${schemaFilePath} or \
place .graphql files in a directory at ${schemaDirPath}`);

const jsonString = JSON.stringify(parameters, null, 4);

if (!options.dryRun) {
fs.writeFileSync(parametersFilePath, jsonString, 'utf8');
JSONUtilities.writeJson(parametersFilePath, parameters);
}

return transformerOutput;
}

Expand Down

0 comments on commit b22e491

Please sign in to comment.