Skip to content

Commit

Permalink
feat(build): allow lockfile mutations (projen#1467)
Browse files Browse the repository at this point in the history
Since we already support build mutations, allow package lockfiles to be updated as well in build workflows.

Resolves projen#1454

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
Elad Ben-Israel authored Jan 3, 2022
1 parent 6b3c138 commit 42a04f7
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml

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

29 changes: 28 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ Name|Description
[javascript.PrettierOverride](#projen-javascript-prettieroverride)|*No description*
[javascript.PrettierSettings](#projen-javascript-prettiersettings)|Options to set in Prettier directly or through overrides.
[javascript.ProjenrcOptions](#projen-javascript-projenrcoptions)|*No description*
[javascript.RenderWorkflowSetupOptions](#projen-javascript-renderworkflowsetupoptions)|Options for `renderInstallSteps()`.
[javascript.TypeScriptCompilerOptions](#projen-javascript-typescriptcompileroptions)|*No description*
[javascript.TypescriptConfigOptions](#projen-javascript-typescriptconfigoptions)|*No description*
[javascript.UpgradeDependenciesOptions](#projen-javascript-upgradedependenciesoptions)|Options for `UpgradeDependencies`.
Expand Down Expand Up @@ -7044,7 +7045,6 @@ Name | Type | Description
**artifactsJavascriptDirectory**🔹 | <code>string</code> | The location of the npm tarball after build (`${artifactsDirectory}/js`).
**bundler**🔹 | <code>[javascript.Bundler](#projen-javascript-bundler)</code> | <span></span>
**entrypoint**⚠️ | <code>string</code> | <span></span>
**installWorkflowSteps**🔹 | <code>Array<[github.workflows.JobStep](#projen-github-workflows-jobstep)></code> | <span></span>
**manifest**⚠️ | <code>any</code> | <span></span>
**package**🔹 | <code>[javascript.NodePackage](#projen-javascript-nodepackage)</code> | API for managing the node package.
**packageManager**⚠️ | <code>[javascript.NodePackageManager](#projen-javascript-nodepackagemanager)</code> | The package manager to use.
Expand Down Expand Up @@ -7230,6 +7230,20 @@ removeScript(name: string): void



#### renderWorkflowSetup(options?)🔹 <a id="projen-javascript-nodeproject-renderworkflowsetup"></a>

Returns the set of workflow steps which should be executed to bootstrap a workflow.

```ts
renderWorkflowSetup(options?: RenderWorkflowSetupOptions): Array<JobStep>
```

* **options** (<code>[javascript.RenderWorkflowSetupOptions](#projen-javascript-renderworkflowsetupoptions)</code>) Options.
* **mutable** (<code>boolean</code>) Should the pacakge lockfile be updated? __*Default*__: false

__Returns__:
* <code>Array<[github.workflows.JobStep](#projen-github-workflows-jobstep)></code>

#### runTaskCommand(task)🔹 <a id="projen-javascript-nodeproject-runtaskcommand"></a>

Returns the shell command to execute in order to run a task.
Expand Down Expand Up @@ -14251,6 +14265,19 @@ Name | Type | Description



## struct RenderWorkflowSetupOptions 🔹 <a id="projen-javascript-renderworkflowsetupoptions"></a>


Options for `renderInstallSteps()`.



Name | Type | Description
-----|------|-------------
**mutable**?🔹 | <code>boolean</code> | Should the pacakge lockfile be updated?<br/>__*Default*__: false



## struct TypeScriptCompilerOptions 🔹 <a id="projen-javascript-typescriptcompileroptions"></a>


Expand Down
32 changes: 28 additions & 4 deletions src/javascript/node-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export class NodeProject extends GitHubProject {
containerImage: options.workflowContainerImage,
gitIdentity: this.workflowGitIdentity,
mutableBuild: options.mutableBuild,
preBuildSteps: this.installWorkflowSteps,
preBuildSteps: this.renderWorkflowSetup({ mutable: true }),
postBuildSteps: options.postBuildSteps,
});

Expand Down Expand Up @@ -590,7 +590,7 @@ export class NodeProject extends GitHubProject {
...options,

releaseWorkflowSetupSteps: [
...this.installWorkflowSteps,
...this.renderWorkflowSetup({ mutable: false }),
...(options.releaseWorkflowSetupSteps ?? []),
],
});
Expand Down Expand Up @@ -830,7 +830,16 @@ export class NodeProject extends GitHubProject {
this.package.addKeywords(...keywords);
}

public get installWorkflowSteps(): JobStep[] {
/**
* Returns the set of workflow steps which should be executed to bootstrap a
* workflow.
*
* @param options Options.
* @returns Job steps
*/
public renderWorkflowSetup(
options: RenderWorkflowSetupOptions = {}
): JobStep[] {
const install = new Array<JobStep>();

// first run the workflow bootstrap steps
Expand All @@ -852,9 +861,13 @@ export class NodeProject extends GitHubProject {
});
}

const mutable = options.mutable ?? false;

install.push({
name: "Install dependencies",
run: this.package.installCommand,
run: mutable
? this.package.installAndUpdateLockfileCommand
: this.package.installCommand,
});

return install;
Expand Down Expand Up @@ -1003,3 +1016,14 @@ export class NodeProject extends GitHubProject {
return this.buildWorkflow?.buildJobIds[0];
}
}

/**
* Options for `renderInstallSteps()`.
*/
export interface RenderWorkflowSetupOptions {
/**
* Should the pacakge lockfile be updated?
* @default false
*/
readonly mutable?: boolean;
}
2 changes: 1 addition & 1 deletion src/javascript/upgrade-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class UpgradeDependencies extends Component {
uses: "actions/checkout@v2",
with: branch ? { ref: branch } : undefined,
},
...this._project.installWorkflowSteps,
...this._project.renderWorkflowSetup({ mutable: false }),
{
name: "Upgrade dependencies",
run: this._project.runTaskCommand(task),
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/integ.test.ts.snap

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

2 changes: 1 addition & 1 deletion test/__snapshots__/node-project.test.ts.snap

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

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion 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.

0 comments on commit 42a04f7

Please sign in to comment.