cdk-pipelines-github
cdk-pipelines-github copied to clipboard
Support use of output from synth step as input in later ShellSteps
I would expect this code to work:
const pipeline = new GitHubWorkflow(app, 'Pipeline', {
workflowPath: `${dir}/.github/workflows/deploy.yml`,
synth: new ShellStep('Build', {
installCommands: ['yarn'],
commands: ['yarn build'],
}),
jobSettings: { if: 'check on Synthesize and Publish Assets' },
});
const stage = new Stage(app, 'MyStage', {
env: { account: '111111111111', region: 'us-east-1' },
});
new Stack(stage, 'MyStack');
pipeline.addStageWithGitHubOptions(stage, {
pre: [
new ShellStep('Extra-Shell-Step', {
additionalInputs: {
'cdk.out': pipeline.cloudAssemblyFileSet,
},
commands: ['ls -al cdk.out'],
}),
],
});
The resulting yaml file doesn't work, since the uploaded artifact is named "cdk.out" but the id used as the name from the pipeline.cloudAssemblyFileSet is `"Output":
Build-Build:
name: Synthesize
if: check on Synthesize and Publish Assets
permissions:
contents: read
id-token: none
runs-on: ubuntu-latest
needs: []
env: {}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install
run: yarn
- name: Build
run: yarn build
- name: Upload cdk.out
uses: actions/[email protected]
with:
name: cdk.out # ← here ⚠️
path: cdk.out
And later:
MyStage-Extra-Shell-Step:
name: Extra-Shell-Step
if: check on Synthesize and Publish Assets
permissions:
contents: read
runs-on: ubuntu-latest
needs:
- Build-Build
env: {}
steps:
- uses: actions/download-artifact@v2
with:
name: Output # ← here ⚠️
path: cdk.out
- run: ls -al cdk.out
The name Output is coming from @aws-cdk/pipelines/lib/blueprint/shell-step.ts:
if (props.primaryOutputDirectory) {
this._primaryOutputDirectory = props.primaryOutputDirectory;
const fileSet = new FileSet('Output', this); // ← here ⚠️
this.configurePrimaryOutput(fileSet);
this.outputs.push({ directory: props.primaryOutputDirectory, fileSet });
}
Perhaps I'm wrong, but it appears that by using this.cloudAssemblyFileSet.id instead of CDKOUT_ARTIFACT here and here this would work as expected.
I forgot to add that I already have a PR for this teed up as well, just waiting to hear feedback in case it needs adjusted or maybe there's a bigger plan that I'd be invalidating here.