cdklabs / cdklabs/cdk-pipelines-github

Support use of output from synth step as input in later ShellSteps

Open
#364 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
384
Forks
45
Avg merge
1d 1h
Merged PRs (30d)
4

Description

I would expect this code to work:

```ts
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":

```yaml
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/upload-artifact@v2.1.1
with:
name: cdk.out # ← here ⚠️
path: cdk.out
```

And later:

```yaml
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`](https://github.com/aws/aws-cdk/blob/0f002e2009bbab2e10c08cdf908c5091ba61b754/packages/%40aws-cdk/pipelines/lib/blueprint/shell-step.ts#L186):

```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](https://github.com/cdklabs/cdk-pipelines-github/blob/main/src/pipeline.ts#L743) and [here](https://github.com/cdklabs/cdk-pipelines-github/blob/main/src/pipeline.ts#L765) this would work as expected.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.