Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility for an optional PR comment comment #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "docker" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hashicorp/terraform:1.0.6
FROM hashicorp/terraform:1.5.7

LABEL repository="https://github.com/robburger/terraform-pr-commenter" \
homepage="https://github.com/robburger/terraform-pr-commenter" \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This action can only be run after a Terraform `fmt`, `init`, `plan` or `validate
| `commenter_type` | _required_ | The type of comment. Options: [`fmt`, `init`, `plan`, `validate`] |
| `commenter_input` | _required_ | The comment to post from a previous step output. |
| `commenter_exitcode` | _required_ | The exit code from a previous step output. |
| `commenter_comment` | _optional_ | An optional comment to add to the end of the headline. |

### Environment Variables

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ inputs:
commenter_exitcode:
description: 'The exit code from a previous step output'
required: true
commenter_comment:
description: 'An optional comment to add to the headline.'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.commenter_type }}
- ${{ inputs.commenter_input }}
- ${{ inputs.commenter_exitcode }}
- ${{ inputs.commenter_comment }}
17 changes: 10 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if [[ ! "$1" =~ ^(fmt|init|plan|validate)$ ]]; then
exit 1
fi

comment="$4"

##################
# Shared Variables
##################
Expand Down Expand Up @@ -82,7 +84,7 @@ if [[ $COMMAND == 'fmt' ]]; then
# Meaning: 1 = Malformed Terraform CLI command. 2 = Terraform parse error.
# Actions: Build PR comment.
if [[ $EXIT_CODE -eq 1 || $EXIT_CODE -eq 2 ]]; then
PR_COMMENT="### Terraform \`fmt\` Failed
PR_COMMENT="### Terraform \`fmt\` Failed $comment
<details$DETAILS_STATE><summary>Show Output</summary>

\`\`\`
Expand All @@ -107,7 +109,7 @@ $THIS_FILE_DIFF
</details>"
done

PR_COMMENT="### Terraform \`fmt\` Failed
PR_COMMENT="### Terraform \`fmt\` Failed $comment
$ALL_FILES_DIFF"
fi

Expand Down Expand Up @@ -147,7 +149,7 @@ if [[ $COMMAND == 'init' ]]; then
# Meaning: Terraform initialize failed or malformed Terraform CLI command.
# Actions: Build PR comment.
if [[ $EXIT_CODE -eq 1 ]]; then
PR_COMMENT="### Terraform \`init\` Failed
PR_COMMENT="### Terraform \`init\` Failed $comment
<details$DETAILS_STATE><summary>Show Output</summary>

\`\`\`
Expand All @@ -170,7 +172,8 @@ fi
if [[ $COMMAND == 'plan' ]]; then
# Look for an existing plan PR comment and delete
echo -e "\033[34;1mINFO:\033[0m Looking for an existing plan PR comment."
PR_COMMENT_ID=$(curl -sS -H "$AUTH_HEADER" -H "$ACCEPT_HEADER" -L "$PR_COMMENTS_URL" | jq '.[] | select(.body|test ("### Terraform `plan` .* for Workspace: `'"$WORKSPACE"'`")) | .id')
PR_COMMENT_ID=$(curl -sS -H "$AUTH_HEADER" -H "$ACCEPT_HEADER" -L "$PR_COMMENTS_URL" |
jq '.[] | select(.body|test ("### Terraform `plan` .* for Workspace: `'"$WORKSPACE"'` '"$comment"'")) | .id')
if [ "$PR_COMMENT_ID" ]; then
echo -e "\033[34;1mINFO:\033[0m Found existing plan PR comment: $PR_COMMENT_ID. Deleting."
PR_COMMENT_URL="$PR_COMMENT_URI/$PR_COMMENT_ID"
Expand All @@ -190,7 +193,7 @@ if [[ $COMMAND == 'plan' ]]; then
if [[ $COLOURISE == 'true' ]]; then
CLEAN_PLAN=$(echo "$CLEAN_PLAN" | sed -r 's/^~/!/g') # Replace ~ with ! to colourise the diff in GitHub comments
fi
PR_COMMENT="### Terraform \`plan\` Succeeded for Workspace: \`$WORKSPACE\`
PR_COMMENT="### Terraform \`plan\` Succeeded for Workspace: \`$WORKSPACE\` $comment
<details$DETAILS_STATE><summary>Show Output</summary>

\`\`\`diff
Expand All @@ -203,7 +206,7 @@ $CLEAN_PLAN
# Meaning: Terraform plan failed.
# Actions: Build PR comment.
if [[ $EXIT_CODE -eq 1 ]]; then
PR_COMMENT="### Terraform \`plan\` Failed for Workspace: \`$WORKSPACE\`
PR_COMMENT="### Terraform \`plan\` Failed for Workspace: \`$WORKSPACE\` $comment
<details$DETAILS_STATE><summary>Show Output</summary>

\`\`\`
Expand Down Expand Up @@ -248,7 +251,7 @@ if [[ $COMMAND == 'validate' ]]; then
# Meaning: Terraform validate failed or malformed Terraform CLI command.
# Actions: Build PR comment.
if [[ $EXIT_CODE -eq 1 ]]; then
PR_COMMENT="### Terraform \`validate\` Failed
PR_COMMENT="### Terraform \`validate\` Failed $comment
<details$DETAILS_STATE><summary>Show Output</summary>

\`\`\`
Expand Down