Skip to content

Commit

Permalink
Merge pull request #80 from the-hideout/deploy-output-cleanup
Browse files Browse the repository at this point in the history
Improve deployment output
  • Loading branch information
GrantBirki authored Mar 5, 2024
2 parents 1869e57 + eed819c commit ca330ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
9 changes: 9 additions & 0 deletions .github/deployment_message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Deployment Results {{ ":white_check_mark:" if status === "success" else ":x:" }}

{% if status === "success" %} **{{ actor }}** successfully **{{ "noop" if noop else "branch" }}** deployed branch `{{ ref }}` to **{{ environment }}**{% endif %}
{% if status === "failure" %} **{{ actor }}** your **{{ "noop" if noop else "branch" }}** deployment of `{{ ref }}` failed to deploy to the **{{ environment }}** environment{% endif %}
{% if status === "unknown" %} **{{ actor }}** your **{{ "noop" if noop else "branch" }}** deployment of `{{ ref }}` is in an unknown state when trying to deploy to the **{{ environment }}** environment.{% endif %}

```terraform
<%= results %>
```
40 changes: 20 additions & 20 deletions .github/workflows/branch-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ permissions:
jobs:
branch-deploy:
name: branch-deploy
if: # only run on pull request comments and very specific comment body string as defined in our branch-deploy settings
${{ github.event.issue.pull_request &&
(startsWith(github.event.comment.body, '.deploy') ||
startsWith(github.event.comment.body, '.noop') ||
startsWith(github.event.comment.body, '.lock') ||
startsWith(github.event.comment.body, '.help') ||
startsWith(github.event.comment.body, '.wcid') ||
startsWith(github.event.comment.body, '.unlock')) }}
runs-on: ubuntu-latest
environment: secrets
defaults:
Expand Down Expand Up @@ -54,36 +62,28 @@ jobs:
env:
TF_VAR_CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
id: plan
run: terraform plan -no-color
continue-on-error: true
run: |
set -o pipefail
terraform plan -no-color -compact-warnings | tee terraform-output.txt
- name: Terraform apply
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop != 'true' }}
env:
TF_VAR_CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }}
id: apply
run: terraform apply -no-color -auto-approve
continue-on-error: true

- name: Terraform plan output
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop == 'true' }}
env:
TF_STDOUT: ${{ steps.plan.outputs.stdout }}
run: |
TF_OUTPUT="\`\`\`terraform\n${TF_STDOUT}\n\`\`\`"
echo 'DEPLOY_MESSAGE<<EOF' >> $GITHUB_ENV
echo "$TF_OUTPUT" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
set -o pipefail
terraform apply -no-color -auto-approve -compact-warnings | tee terraform-output.txt
- name: Terraform apply output
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop != 'true' }}
env:
TF_STDOUT: ${{ steps.apply.outputs.stdout }}
run: |
TF_OUTPUT="\`\`\`terraform\n${TF_STDOUT}\n\`\`\`"
echo 'DEPLOY_MESSAGE<<EOF' >> $GITHUB_ENV
echo "$TF_OUTPUT" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: terratrash
if: ${{ steps.branch-deploy.outputs.continue == 'true' }}
uses: GrantBirki/[email protected]
with:
input_file_path: terraform/terraform-output.txt
erb_render_template: ./github/deployment_message.md
erb_render_save_path: ./github/deployment_message.md

- name: Check Terraform plan output
if: ${{ steps.branch-deploy.outputs.continue == 'true' && steps.branch-deploy.outputs.noop == 'true' && steps.plan.outcome == 'failure' }}
Expand Down

0 comments on commit ca330ce

Please sign in to comment.