Skip to content

Commit

Permalink
Merge pull request #21 from getlarge/20-required-property-url-is-missing
Browse files Browse the repository at this point in the history
fix: required property url is missing
  • Loading branch information
getlarge authored May 2, 2024
2 parents 52695db + ef0f4b5 commit 2c1ec50
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
40 changes: 39 additions & 1 deletion e2e/nx-heroku-e2e/tests/nx-heroku.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,45 @@ describe('nx-heroku e2e', () => {
expect(project.targets?.deploy?.options?.email).toEqual(HEROKU_EMAIL);
}, 120000);

it('should create target and deploy the app successfully', async () => {
it('should create target and deploy an app with simple configuration successfully', async () => {
const { projectName, getProjectConfig, updateProjectConfig } =
await createProject();

projects.push(projectName);
// restore the environment variables to be expanded by the executor
process.env.HEROKU_API_KEY = process.env.HEROKU_API_KEY_PREV;
process.env.HEROKU_EMAIL = process.env.HEROKU_EMAIL_PREV;
// configure the target
await runNxCommandAsync(
`generate @getlarge/nx-heroku:deploy ${projectName} --appNamePrefix=aloes`
);
const project = getProjectConfig();
project.targets!.deploy.options = {
...(project.targets!.deploy.options || {}),
procfile: `web: node dist/apps/${projectName}/main.js`,
buildPacks: ['heroku/nodejs'],
apiKey: HEROKU_API_KEY,
email: HEROKU_EMAIL,
variables: {
// used in postbuild.js
PROJECT_NAME: projectName,
},
useForce: true,
serviceUser: '[email protected]',
debug: true,
};
updateProjectConfig(project);
prepareProjectForDeployment(projectName);
// run the target
const { stderr, stdout } = await runNxCommandAsync(
`deploy ${projectName} --verbose`,
{ silenceError: true }
);
console.warn(stdout, stderr);
expect(stdout).toContain('Deployment successful.');
}, 100000);

it('should create target and deploy the app with complex configuration successfully', async () => {
const { projectName, getProjectConfig, updateProjectConfig } =
await createProject();

Expand Down
16 changes: 13 additions & 3 deletions e2e/nx-heroku-e2e/tests/tools.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
NxJsonConfiguration,
ProjectConfiguration,
logger,
serializeJson,
} from '@nx/devkit';
import {
Expand Down Expand Up @@ -169,9 +170,18 @@ function patchPackageJson() {
}

function commitPackageJson() {
execSync(
`git add package*.json && git commit -m "chore: update package*.json" -n --no-gpg-sign`
);
try {
execSync(
`git add package*.json && git commit -m "chore: update package*.json" -n --no-gpg-sign`
);
} catch (e) {
if (e['stdout']?.toString().includes('no changes added to commit')) {
return;
} else {
logger.error(e);
throw e;
}
}
}

function setPackageJsonForHeroku() {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-heroku/src/executors/common/heroku/drains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function addDrain(options: {
password?: string;
};
}): Promise<'found' | 'created'> {
const { appName, drain = { url: '' } } = options;
const { appName, drain = null } = options;
if (!drain?.url || !isURL(drain.url)) return;
let url: string = drain.url;
if (drain.user && drain.password) {
Expand Down
10 changes: 1 addition & 9 deletions packages/nx-heroku/src/executors/common/heroku/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ export async function addWebhook(options: {
secret?: string;
};
}): Promise<'created' | 'updated' | 'found'> {
const {
appName,
webhook = {
url: '',
include: ['api:build', 'api:release', 'dyno'],
level: 'sync',
secret: '',
},
} = options;
const { appName, webhook = null } = options;
if (!webhook?.url || !isURL(webhook.url)) return;
const { url, level, secret } = webhook;
const include = webhook.include.join(',');
Expand Down
17 changes: 17 additions & 0 deletions packages/nx-heroku/src/executors/deploy/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,21 @@ describe('Deploy Executor', () => {
expect(herokuDeployService.run).toBeCalled();
expect(output.success).toBe(false);
});

it('can run with the minimum required options and return true', async () => {
const opts: DeployExecutorSchema = {
config: ['development'],
org: 'my-org',
buildPacks: [],
apiKey: 'heroku-user-api-key',
email: 'heroku-user-email',
watchDelay: 0,
};
herokuDeployService.run = jest.fn();
//
const output = await executor(opts, context);
//
expect(herokuDeployService.run).toBeCalled();
expect(output.success).toBe(true);
});
});
6 changes: 4 additions & 2 deletions packages/nx-heroku/src/executors/deploy/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
"description": "Webhook secret to override the one autogenerated by Heroku during webhook registration"
}
},
"required": ["url", "include", "level"]
"$comment": "https://github.com/nrwl/nx/issues/23153",
"shouldBeRequired": ["url", "include", "level"]
},
"drain": {
"description": "Log drain to register on Heroku, see https://devcenter.heroku.com/articles/log-drains",
Expand All @@ -163,7 +164,8 @@
"type": "string"
}
},
"required": ["url"]
"$comment": "https://github.com/nrwl/nx/issues/23153",
"shouldBeRequired": ["url"]
},
"branch": {
"description": "The branch that you would like to deploy to Heroku. Defaults to 'HEAD'",
Expand Down

0 comments on commit 2c1ec50

Please sign in to comment.