Skip to content

Commit

Permalink
feat: comment on GitHub step summary (#986)
Browse files Browse the repository at this point in the history
Using the GitHub step summary feature, the Pulumi output can be stored on the
GitHub step. This defeats the need to dive into the individual steps and find
the Pulumi output.

The input parameter comment-on-summary has the non-breaking default false. If
true, then the action will add the results of the Pulumi action to the GitHub
step summary.
  • Loading branch information
koozz authored Aug 23, 2023
1 parent 08e7a83 commit 13b88a5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## HEAD (Unreleased)

- feat: comment on GitHub step summary.
([#986](https://github.com/pulumi/actions/pull/986))
- feat: Add Update Plan Functionality
([#994](https://github.com/pulumi/actions/pull/994))

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ The action can be configured with the following arguments:
of the Pulumi action to the PR. Ignored unless `${{ github.event }}` type is
`pull_request`.

- `comment-on-summary` - (optional) If `true`, then the action will add the
results of the Pulumi action to the GitHub step summary.

- `github-token` - (optional) A GitHub token that has access levels to allow the
Action to comment on a PR. Defaults to `${{ github.token }}`

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
comment-on-pr-number:
description: 'Overrides the PR used to comment on'
required: false
comment-on-summary:
description: 'If true, a comment on the GitHub step summary will be created'
required: false
default: 'false'
github-token:
description: 'Github Token'
required: false
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const defaultConfig: Record<string, string> = {
'github-token': 'n/a',
'pulumi-version': '^3',
'comment-on-pr': 'false',
'comment-on-summary': 'false',
upsert: 'false',
remove: 'false',
refresh: 'false',
Expand Down Expand Up @@ -40,6 +41,7 @@ describe('config.ts', () => {
"command": "up",
"commentOnPr": false,
"commentOnPrNumber": undefined,
"commentOnSummary": false,
"configMap": undefined,
"editCommentOnPr": false,
"githubToken": "n/a",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function makeConfig() {
githubToken: getInput('github-token'),
commentOnPr: getBooleanInput('comment-on-pr'),
commentOnPrNumber: getNumberInput('comment-on-pr-number', {}),
commentOnSummary: getBooleanInput('comment-on-summary'),
upsert: getBooleanInput('upsert'),
remove: getBooleanInput('remove'),
refresh: getBooleanInput('refresh'),
Expand Down
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ const runAction = async (config: Config): Promise<void> => {
}
}

if (config.commentOnSummary) {
await core.summary
.addHeading(`Pulumi ${config.stackName} results`)
.addCodeBlock(output, "diff")
.write();
}

if (config.remove && config.command === 'destroy') {
stack.workspace.removeStack(stack.name);
}
Expand Down

0 comments on commit 13b88a5

Please sign in to comment.