Skip to content

Commit

Permalink
add Custom Deployment Messages section
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed May 3, 2022
1 parent f73e2a7 commit e47e1e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ jobs:
# Do some fake "noop" deployment logic here
- name: fake noop deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop == 'true' }}
run: |
echo "DEPLOY_MESSAGE=noop changes:\n\`\`\`python\ndef test()\n\tprint('test')\`\`\`" >> $GITHUB_ENV
echo "I am doing a fake noop deploy"
run: echo "I am doing a fake noop deploy"

# Do some fake "regular" deployment logic here
- name: fake regular deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop != 'true' }}
run: |
echo "DEPLOY_MESSAGE=hello" >> $GITHUB_ENV
echo "I am doing a fake regular deploy"
run: echo "I am doing a fake regular deploy"
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,49 @@ As seen above, we have two steps. One for a noop deploy, and one for a regular d
| comment_id | The comment id which triggered this deployment |
| continue | The string "true" if the deployment should continue, otherwise empty - Use this to conditionally control if your deployment should proceed or not |

## Custom Deployment Messages ✏️

> This is useful to display to the user the status of your deployment. For example, you could display the results of a `terraform apply` in the deployment comment

You can use the GitHub Actions environment to export custom deployment messages from your workflow to be referenced in the post run workflow for the `branch-deploy` Action that comments results back to your PR

Simply set the environment variable `DEPLOY_MESSAGE` to the message you want to be displayed in the post run workflow

Bash Example:

```bash
echo "DEPLOY_MESSAGE=<message>" >> $GITHUB_ENV
```

Actions Workflow Example:

```yaml
# Do some fake "noop" deployment logic here
- name: fake noop deploy
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop == 'true' }}
run: |
echo "DEPLOY_MESSAGE=I would have **updated** 1 server" >> $GITHUB_ENV
echo "I am doing a fake noop deploy"
```

### Additional Custom Message Examples 📚

Adding newlines to your message:

```bash
echo "DEPLOY_MESSAGE=NOOP Result:\nI would have **updated** 1 server" >> $GITHUB_ENV
```

Adding a code block to your message:

```bash
echo "DEPLOY_MESSAGE=\`\`\`yaml\nname: value\n\`\`\`" >> $GITHUB_ENV
```

### How does this work? 🤔

To add custom messages to our final deployment message we need to use the GitHub Actions environment. This is so that we can dynamically pass data into the post action workflow that leaves a comment on our PR. The post action workflow will look to see if this environment variable is set (`DEPLOY_MESSAGE`). If the variable is set, it adds to to the PR comment. Otherwise, it will use a simple comment body that doesn't include the custom message.

## Testing Locally 🔨

> This is a not fully supported
Expand Down

0 comments on commit e47e1e0

Please sign in to comment.