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(javascript): allow users to run post-upgrade tasks #1476

Merged
merged 3 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -7555,6 +7555,7 @@ new javascript.UpgradeDependencies(project: NodeProject, options?: UpgradeDepend
Name | Type | Description
-----|------|-------------
**ignoresProjen**🔹 | <code>boolean</code> | Whether or not projen is also upgraded in this workflow,.
**postUpgradeTask**🔹 | <code>[Task](#projen-task)</code> | A task run after the upgrade task.
**workflows**🔹 | <code>Array<[github.GithubWorkflow](#projen-github-githubworkflow)></code> | The workflows that execute the upgrades.
**containerOptions**?🔹 | <code>[github.workflows.ContainerOptions](#projen-github-workflows-containeroptions)</code> | Container definitions for the upgrade workflow.<br/>__*Optional*__

Expand Down
1 change: 1 addition & 0 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/javascript/upgrade-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export class UpgradeDependencies extends Component {
*/
public containerOptions?: ContainerOptions;

/**
* A task run after the upgrade task.
*/
public readonly postUpgradeTask: Task;

private readonly gitIdentity: GitIdentity;
private readonly postBuildSteps: JobStep[];

Expand All @@ -122,6 +127,12 @@ export class UpgradeDependencies extends Component {
this.containerOptions = options.workflowOptions?.container;

project.addDevDeps("npm-check-updates@^12");

this.postUpgradeTask =
project.tasks.tryFind("post-upgrade") ??
project.tasks.addTask("post-upgrade", {
description: "Runs after upgrading dependencies",
});
misterjoshua marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -197,6 +208,8 @@ export class UpgradeDependencies extends Component {
// run "projen" to give projen a chance to update dependencies (it will also run "yarn install")
task.exec(this._project.projenCommand);

task.spawn(this.postUpgradeTask);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test? I think we just want to validate that is there is some way to run things after the upgrade task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've added a unit test that checks that the upgrade task spawns post-upgrade as its last step. In the test, I didn't add anything to the post-upgrade task, but I can if you feel it's necessary.


return task;
}

Expand Down
41 changes: 41 additions & 0 deletions test/__snapshots__/integ.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/node-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,18 @@ describe("workflowRunsOn", () => {
});
});

test("post-upgrade workflow", () => {
// GIVEN
const project = new TestNodeProject();

// THEN
const snapshot = synthSnapshot(project);
const tasks = snapshot[Tasks.MANIFEST_FILE].tasks;
expect(tasks.upgrade.steps[tasks.upgrade.steps.length - 1]).toStrictEqual({
spawn: "post-upgrade",
});
});

class TestNodeProject extends NodeProject {
constructor(options: Partial<NodeProjectOptions> = {}) {
super({
Expand Down
11 changes: 11 additions & 0 deletions test/web/__snapshots__/nextjs-project.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/web/__snapshots__/nextjs-ts-project.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/web/__snapshots__/react-project.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/web/__snapshots__/react-ts-project.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.