Skip to content

Commit

Permalink
feat: allow specifying GitHub workflow bootstrap options
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Ben-Israel committed May 12, 2020
1 parent 92d5b63 commit 55b2f73
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
image: jsii/superchain
steps:
- uses: actions/checkout@v2
- run: yarn install --frozen-lockfile
- run: yarn bootstrap
- run: yarn build
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
image: jsii/superchain
steps:
- uses: actions/checkout@v2
- run: yarn install --frozen-lockfile
- run: yarn bootstrap
- run: yarn build
- name: Upload artifact
uses: actions/upload-artifact@v1
Expand Down
3 changes: 3 additions & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const project = new JsiiProject({
},
bundledDependencies: [ 'yaml' ],
projenDevDependency: false, // because I am projen
workflowOptions: {
bootstrapSteps: [ { run: `yarn bootstrap` } ]
}
});

project.addScripts({
Expand Down
3 changes: 3 additions & 0 deletions lib/common.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const PROJEN_RC = '.projenrc.js';
export const GENERATION_DISCLAIMER = `Generated by projen. To modify, edit ${PROJEN_RC} and run "npx projen".`;

// eslint-disable-next-line @typescript-eslint/no-require-imports
export const PROJEN_VERSION = require('../version.json').version;
30 changes: 24 additions & 6 deletions lib/jsii-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Semver } from './semver';
import { Eslint } from './eslint';
import { GithubWorkflow } from './github-workflow';
import { Project } from './project';
import { PROJEN_VERSION } from './common';

export interface JsiiProjectOptions extends CommonOptions {
/**
Expand Down Expand Up @@ -30,6 +31,11 @@ export interface JsiiProjectOptions extends CommonOptions {
* @default true
*/
readonly eslint?: boolean;

/**
* Options for github workflows.
*/
readonly workflowOptions?: WorkflowOptions;
}

export enum Stability {
Expand Down Expand Up @@ -83,7 +89,7 @@ export class JsiiProject extends NodeProject {
},
});

const releaseWorkflow = new JsiiReleaseWorkflow(this);
const releaseWorkflow = new JsiiReleaseWorkflow(this, options.workflowOptions);

releaseWorkflow.publishToNpm();

Expand Down Expand Up @@ -150,15 +156,27 @@ export class JsiiProject extends NodeProject {
this.npmignore.comment('include .jsii manifest');
this.npmignore.include('.jsii');

new JsiiBuildWorkflow(this);
new JsiiBuildWorkflow(this, options.workflowOptions);
}
}

export interface WorkflowOptions {
/**
* Workflow steps to use in order to bootstrap this repo.
* @default - [ { run: `npx projen${PROJEN_VERSION}` }, { run: 'yarn install --frozen-lockfile' } ]
*/
readonly bootstrapSteps?: any[];
}

const DEFAULT_WORKFLOW_BOOTSTRAP = [
{ run: `npx projen${PROJEN_VERSION}` },
{ run: 'yarn install --frozen-lockfile' },
];

class JsiiReleaseWorkflow extends GithubWorkflow {
private readonly buildJobId = 'build_artifact';

constructor(project: Project) {
constructor(project: Project, options: WorkflowOptions = { }) {
super(project, 'release', { name: 'Release' });

this.on({ push: { branches: [ 'master' ] } });
Expand All @@ -172,7 +190,7 @@ class JsiiReleaseWorkflow extends GithubWorkflow {
},
'steps': [
{ uses: 'actions/checkout@v2' },
{ run: 'yarn install --frozen-lockfile' },
...options.bootstrapSteps ?? DEFAULT_WORKFLOW_BOOTSTRAP,
{ run: 'yarn build' },
{
name: 'Upload artifact',
Expand Down Expand Up @@ -310,7 +328,7 @@ class JsiiReleaseWorkflow extends GithubWorkflow {
}

export class JsiiBuildWorkflow extends GithubWorkflow {
constructor(project: Project) {
constructor(project: Project, options: WorkflowOptions = { }) {
super(project, 'build', { name: 'Build' });

this.on({ pull_request: { } });
Expand All @@ -323,7 +341,7 @@ export class JsiiBuildWorkflow extends GithubWorkflow {
},
steps: [
{ uses: 'actions/checkout@v2' },
{ run: 'yarn install --frozen-lockfile' },
...options.bootstrapSteps ?? DEFAULT_WORKFLOW_BOOTSTRAP,
{ run: 'yarn build' },
],
},
Expand Down
5 changes: 1 addition & 4 deletions lib/node-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { JsonFile } from './json';
import { Semver } from './semver';
import { IgnoreFile } from './ignore-file';
import { License } from './license';
import { GENERATION_DISCLAIMER, PROJEN_RC } from './common';
import { GENERATION_DISCLAIMER, PROJEN_RC, PROJEN_VERSION } from './common';
import { Lazy } from 'constructs';
import { Version } from './version';

// eslint-disable-next-line @typescript-eslint/no-require-imports
const PROJEN_VERSION = require('../version.json').version;

export interface CommonOptions {
readonly bundledDependencies?: string[];
readonly dependencies?: Record<string, Semver>;
Expand Down

0 comments on commit 55b2f73

Please sign in to comment.