From 918e76eae82d68dcfbde34f3104952b9fac6a4db Mon Sep 17 00:00:00 2001 From: Max Golionko Date: Wed, 16 Aug 2023 09:51:30 +0200 Subject: [PATCH 01/34] update test --- .github/workflows/test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 22f948d..717f6c6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,8 +11,8 @@ env: GH_ACCEPT_HEADER: "Accept: application/vnd.github+json" GH_AUTH_HEADER: "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" GH_API_VERSION: "X-GitHub-Api-Version: 2022-11-28" - GH_COMMENT_URL: https://api.github.com/repos/GetTerminus/terraform-pr-commenter/issues/${{ github.event.number }}/comments - TESTING: "false" #set to false when finished testing + GH_COMMENT_URL: https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments + TESTING: "true" #set to false when finished testing jobs: set-outputs: @@ -71,7 +71,7 @@ jobs: if: ${{ env.TESTING == 'true' }} - name: Test if: ${{ env.TESTING == 'true' }} - uses: GetTerminus/terraform-pr-commenter@v3-beta #set to your branch for testing and switch back to v3-beta when done. + uses: k1rk/terraform-pr-commenter@monorepo #set to your branch for testing and switch back to v3-beta when done. with: commenter_type: plan # Should only be setting commenter_input or commenter_plan_path (commenter_plan_path only for plan commenter type) From 07922747d46b259db715c3fb4868673546cf024f Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:05:06 +0200 Subject: [PATCH 02/34] added permissions --- .github/workflows/release-beta.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-beta.yaml b/.github/workflows/release-beta.yaml index a743ff2..9f22b8f 100644 --- a/.github/workflows/release-beta.yaml +++ b/.github/workflows/release-beta.yaml @@ -3,6 +3,9 @@ name: Release Beta on: pull_request: +permissions: + contents: write + jobs: release-beta: runs-on: ubuntu-latest @@ -14,4 +17,4 @@ jobs: tag-name: v3-beta tag-message: The current beta is based on this commit env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c5c07273f7ecd9355e9beaab3310411f3a60c0ac Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:16:50 +0200 Subject: [PATCH 03/34] update permissions --- .github/workflows/test.yaml | 5 +++++ action.yml | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 717f6c6..5f7b6cf 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,6 +3,11 @@ name: Test on: pull_request: +permissions: + contents: write + checks: write + issues: write + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TERRAFORM_VERSION: "1.4.6" diff --git a/action.yml b/action.yml index cd78c6f..7e01684 100644 --- a/action.yml +++ b/action.yml @@ -42,13 +42,13 @@ runs: shell: bash - name: Build commenter docker image (master) if: ${{ inputs.use_beta_version != 'true' }} - run: docker build --build-arg TERRAFORM_VERSION=${{ steps.tf_version.outputs.version }} -t commenter https://github.com/GetTerminus/terraform-pr-commenter.git#v3 + run: docker build --build-arg TERRAFORM_VERSION=${{ steps.tf_version.outputs.version }} -t commenter https://github.com/k1rk/terraform-pr-commenter.git#v3 shell: bash - name: Build commenter docker image (beta) if: ${{ inputs.use_beta_version == 'true' }} # append branch with a pound (#) if developing. e.g., `commenter.git#my-branch` run: | - docker build --build-arg TERRAFORM_VERSION=${{ steps.tf_version.outputs.version }} -t commenter https://github.com/GetTerminus/terraform-pr-commenter.git#v3-beta + docker build --build-arg TERRAFORM_VERSION=${{ steps.tf_version.outputs.version }} -t commenter https://github.com/k1rk/terraform-pr-commenter.git#v3-beta shell: bash - name: Run commenter image (plan) if: ${{ inputs.commenter_type == 'plan' }} From 890ca9a7951d97dc78a11f669e9401172de96906 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:20:39 +0200 Subject: [PATCH 04/34] add PR perms --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5f7b6cf..e22760b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -7,6 +7,7 @@ permissions: contents: write checks: write issues: write + pull-requests: write env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 8d1807eebb60b12ab50fc474e30146689c0c0065 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:22:46 +0200 Subject: [PATCH 05/34] test project parameter --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e22760b..32b3c8f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -85,3 +85,4 @@ jobs: #commenter_plan_path: ./testing/text-files/tf_plan_success_with_outputs.txt commenter_exitcode: 2 use_beta_version: "true" + project: max From c5f65e32950e074152adbb09408611468c1a5141 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:26:55 +0200 Subject: [PATCH 06/34] update project header --- utilities/comment_utility.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 4ef2c9d..0f09307 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -16,7 +16,7 @@ make_and_post_payload() { make_details_with_header() { local header="### $1" if [[ ! -z $PROJECT ]]; then - header="## **$PROJECT** + header="## Project: **$PROJECT** $header" fi local body=$2 @@ -113,7 +113,7 @@ delete_existing_comments() { local last_page if [[ ! -z $PROJECT ]]; then - regex="## **$PROJECT**\n$regex" + regex="## Project: **$PROJECT**\n$regex" fi debug "Type: $type" From 96ae2298119475cb94443ebd10482afee3851efc Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:29:20 +0200 Subject: [PATCH 07/34] update project param for test --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 32b3c8f..9764aaa 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -85,4 +85,4 @@ jobs: #commenter_plan_path: ./testing/text-files/tf_plan_success_with_outputs.txt commenter_exitcode: 2 use_beta_version: "true" - project: max + project: dev-team-1 From c461c3a6aad45147025271364d551a5bee2f95bd Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:46:12 +0200 Subject: [PATCH 08/34] test comment update --- testing/text-files/tf_plan_success_with_outputs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/text-files/tf_plan_success_with_outputs.txt b/testing/text-files/tf_plan_success_with_outputs.txt index 15b5a11..3190869 100644 --- a/testing/text-files/tf_plan_success_with_outputs.txt +++ b/testing/text-files/tf_plan_success_with_outputs.txt @@ -157,7 +157,7 @@ Terraform will perform the following actions: Changes to Outputs: + test_output = [ + [ - + "my-tf-test-bucket-0", + + "my-tf-test-bucket-100", + "my-tf-test-bucket-1", + "my-tf-test-bucket-2", + "my-tf-test-bucket-3", From 3e65a8efc828ce05312515abfbec5b2c8a070cf5 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 13:50:30 +0200 Subject: [PATCH 09/34] modify regex, reduce permissions --- .github/workflows/test.yaml | 2 -- utilities/comment_utility.sh | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9764aaa..3a53fc1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,9 +4,7 @@ on: pull_request: permissions: - contents: write checks: write - issues: write pull-requests: write env: diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 0f09307..9390fa5 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -113,7 +113,7 @@ delete_existing_comments() { local last_page if [[ ! -z $PROJECT ]]; then - regex="## Project: **$PROJECT**\n$regex" + regex="## Project: **$PROJECT**\\n$regex" fi debug "Type: $type" From e5a26a88bf14265d67617014dd63aedd47c9f380 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 14:04:46 +0200 Subject: [PATCH 10/34] added ouput --- action.yml | 3 +++ utilities/comment_utility.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7e01684..ac4cf0d 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: project: description: project name to use in the comment required: false +outputs: + comment_id: # id of the comment + description: 'ID of created comment' runs: using: "composite" steps: diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 9390fa5..24ca879 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -40,7 +40,8 @@ $body } post_comment() { - curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" + comment_id=$(curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" | jq -r ".id") + echo "comment_id=$comment_id" >>$GITHUB_OUTPUT } ### DIFF AND STRING SUBSTITUTION UTILITIES ### From 683001d850b0f92bcfa7eaf475b76692dbe5da47 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 14:36:00 +0200 Subject: [PATCH 11/34] enable multiline mode --- utilities/comment_utility.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 24ca879..0757728 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -122,7 +122,7 @@ delete_existing_comments() { local jq='.[] | select(.body|test ("' jq+=$regex - jq+='")) | .id' + jq+='", "m")) | .id' # gross, but... bash. get_page_count PAGE_COUNT From 407d6ea908864887fbe86b7d188297bd9418775d Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 14:39:16 +0200 Subject: [PATCH 12/34] one more test without project, and echo output --- .github/workflows/test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3a53fc1..38620d6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -83,4 +83,6 @@ jobs: #commenter_plan_path: ./testing/text-files/tf_plan_success_with_outputs.txt commenter_exitcode: 2 use_beta_version: "true" - project: dev-team-1 + # project: dev-team-1 + - name: print output + run: echo "${{ steps.test.outputs.comment_id }}" From 2599cb59b4bca066a00dfae47b01d04ba9684213 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 14:55:49 +0200 Subject: [PATCH 13/34] recert output change --- testing/text-files/tf_plan_success_with_outputs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/text-files/tf_plan_success_with_outputs.txt b/testing/text-files/tf_plan_success_with_outputs.txt index 3190869..15b5a11 100644 --- a/testing/text-files/tf_plan_success_with_outputs.txt +++ b/testing/text-files/tf_plan_success_with_outputs.txt @@ -157,7 +157,7 @@ Terraform will perform the following actions: Changes to Outputs: + test_output = [ + [ - + "my-tf-test-bucket-100", + + "my-tf-test-bucket-0", + "my-tf-test-bucket-1", + "my-tf-test-bucket-2", + "my-tf-test-bucket-3", From 749b154dd9c0fb6854f0bad8944a4fe57e25560e Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 14:56:02 +0200 Subject: [PATCH 14/34] update output --- entrypoint.sh | 21 ++++++++++++++------- utilities/comment_utility.sh | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5f9f530..b7fb2c8 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # shellcheck source=handler/ -for HF in handlers/* ; do source "$HF" ; done +for HF in handlers/*; do source "$HF"; done # shellcheck source=utilities/ -for UF in utilities/* ; do source "$UF" ; done +for UF in utilities/*; do source "$UF"; done if [ -n "${COMMENTER_ECHO+x}" ]; then set -x @@ -14,27 +14,34 @@ fi validate_inputs "$@" parse_args "$@" +local output + if [[ $COMMAND == 'fmt' ]]; then - execute_fmt + execute_fmt >>$output exit 0 fi if [[ $COMMAND == 'init' ]]; then - execute_init + execute_init >>$output exit 0 fi if [[ $COMMAND == 'plan' ]]; then - execute_plan + execute_plan >>$output exit 0 fi if [[ $COMMAND == 'validate' ]]; then - execute_validate + execute_validate >>$output exit 0 fi if [[ $COMMAND == 'tflint' ]]; then - execute_tflint + execute_tflint >>$output exit 0 fi + +if [[ ! -z $output ]]; then + local comment_id="$output | jq -r '.id'" + echo "comment_id=$comment_id" >>$GITHUB_OUTPUT +fi diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 0757728..f3891f5 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -40,8 +40,8 @@ $body } post_comment() { - comment_id=$(curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" | jq -r ".id") - echo "comment_id=$comment_id" >>$GITHUB_OUTPUT + local ouptut=curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" + echo $ouptut } ### DIFF AND STRING SUBSTITUTION UTILITIES ### From 3910f7dd5b8149658592bc83843d010ddee13034 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 14:59:41 +0200 Subject: [PATCH 15/34] fix output --- .github/workflows/test.yaml | 13 ++++++++++++- entrypoint.sh | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 38620d6..f8a1c28 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -83,6 +83,17 @@ jobs: #commenter_plan_path: ./testing/text-files/tf_plan_success_with_outputs.txt commenter_exitcode: 2 use_beta_version: "true" - # project: dev-team-1 + project: dev-team-1 + - name: Test-project-2 + if: ${{ env.TESTING == 'true' }} + uses: k1rk/terraform-pr-commenter@monorepo #set to your branch for testing and switch back to v3-beta when done. + with: + commenter_type: plan + # Should only be setting commenter_input or commenter_plan_path (commenter_plan_path only for plan commenter type) + commenter_input: ${{ needs.set-outputs.outputs.tf_plan_success_with_outputs }} + #commenter_plan_path: ./testing/text-files/tf_plan_success_with_outputs.txt + commenter_exitcode: 2 + use_beta_version: "true" + project: dev-team-2 - name: print output run: echo "${{ steps.test.outputs.comment_id }}" diff --git a/entrypoint.sh b/entrypoint.sh index b7fb2c8..6b8a9ed 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,7 +14,7 @@ fi validate_inputs "$@" parse_args "$@" -local output +output="" if [[ $COMMAND == 'fmt' ]]; then execute_fmt >>$output @@ -42,6 +42,6 @@ if [[ $COMMAND == 'tflint' ]]; then fi if [[ ! -z $output ]]; then - local comment_id="$output | jq -r '.id'" + comment_id="$output | jq -r '.id'" echo "comment_id=$comment_id" >>$GITHUB_OUTPUT fi From 81832cc9b08d2519d8cd0bc23909f432d695350a Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 15:09:54 +0200 Subject: [PATCH 16/34] try output differently --- entrypoint.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6b8a9ed..d73c07f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -17,27 +17,27 @@ parse_args "$@" output="" if [[ $COMMAND == 'fmt' ]]; then - execute_fmt >>$output + output=execute_fmt exit 0 fi if [[ $COMMAND == 'init' ]]; then - execute_init >>$output + output=execute_init exit 0 fi if [[ $COMMAND == 'plan' ]]; then - execute_plan >>$output + output=execute_plan exit 0 fi if [[ $COMMAND == 'validate' ]]; then - execute_validate >>$output + output=execute_validate exit 0 fi if [[ $COMMAND == 'tflint' ]]; then - execute_tflint >>$output + output=execute_tflint exit 0 fi From 3ba8da5979df0c4622cbd9dccd9c689aced79c94 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 15:17:04 +0200 Subject: [PATCH 17/34] drop output for now --- action.yml | 3 --- entrypoint.sh | 17 +++++------------ utilities/comment_utility.sh | 3 +-- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index ac4cf0d..7e01684 100644 --- a/action.yml +++ b/action.yml @@ -28,9 +28,6 @@ inputs: project: description: project name to use in the comment required: false -outputs: - comment_id: # id of the comment - description: 'ID of created comment' runs: using: "composite" steps: diff --git a/entrypoint.sh b/entrypoint.sh index d73c07f..e8c85b9 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -14,34 +14,27 @@ fi validate_inputs "$@" parse_args "$@" -output="" - if [[ $COMMAND == 'fmt' ]]; then - output=execute_fmt + execute_fmt exit 0 fi if [[ $COMMAND == 'init' ]]; then - output=execute_init + execute_init exit 0 fi if [[ $COMMAND == 'plan' ]]; then - output=execute_plan + execute_plan exit 0 fi if [[ $COMMAND == 'validate' ]]; then - output=execute_validate + execute_validate exit 0 fi if [[ $COMMAND == 'tflint' ]]; then - output=execute_tflint + execute_tflint exit 0 fi - -if [[ ! -z $output ]]; then - comment_id="$output | jq -r '.id'" - echo "comment_id=$comment_id" >>$GITHUB_OUTPUT -fi diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index f3891f5..8d182bc 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -40,8 +40,7 @@ $body } post_comment() { - local ouptut=curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" - echo $ouptut + curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" } ### DIFF AND STRING SUBSTITUTION UTILITIES ### From 61f200f139ab4d96d5d98e7e876cdf355b76d84a Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 15:20:07 +0200 Subject: [PATCH 18/34] outputs test --- testing/text-files/tf_plan_success_with_outputs.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/text-files/tf_plan_success_with_outputs.txt b/testing/text-files/tf_plan_success_with_outputs.txt index 15b5a11..8228b85 100644 --- a/testing/text-files/tf_plan_success_with_outputs.txt +++ b/testing/text-files/tf_plan_success_with_outputs.txt @@ -157,9 +157,9 @@ Terraform will perform the following actions: Changes to Outputs: + test_output = [ + [ - + "my-tf-test-bucket-0", + + "my-tf-test-bucket-100", + "my-tf-test-bucket-1", - + "my-tf-test-bucket-2", + + "my-tf-test-bucket-200", + "my-tf-test-bucket-3", + "my-tf-test-bucket-4", ], From 6514579c36669d1b24a9919b99e54457a8c0febf Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Wed, 16 Aug 2023 15:35:24 +0200 Subject: [PATCH 19/34] remove Bold fomratting --- utilities/comment_utility.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 8d182bc..e62df1c 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -16,7 +16,7 @@ make_and_post_payload() { make_details_with_header() { local header="### $1" if [[ ! -z $PROJECT ]]; then - header="## Project: **$PROJECT** + header="## Project: $PROJECT $header" fi local body=$2 @@ -113,7 +113,7 @@ delete_existing_comments() { local last_page if [[ ! -z $PROJECT ]]; then - regex="## Project: **$PROJECT**\\n$regex" + regex="## Project: $PROJECT\\n$regex" fi debug "Type: $type" From 379ba915e3b40aa4bb759049d4a48f40e3489138 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 10:12:06 +0200 Subject: [PATCH 20/34] debug jq --- utilities/comment_utility.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index e62df1c..8c9f1c8 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -121,7 +121,9 @@ delete_existing_comments() { local jq='.[] | select(.body|test ("' jq+=$regex - jq+='", "m")) | .id' + jq+='")) | .id' + + debug "jq: $jq" # gross, but... bash. get_page_count PAGE_COUNT From a81fff343beefa2fb622e7b512714cd9e7ec9660 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 10:25:50 +0200 Subject: [PATCH 21/34] update handlers and cleanup --- handlers/fmt_handler.sh | 12 ++++++------ handlers/init_handler.sh | 10 +++++----- handlers/plan_handler.sh | 16 ++++++++-------- handlers/tflint_handler.sh | 10 +++++----- handlers/validate_handler.sh | 10 +++++----- .../text-files/tf_plan_success_with_outputs.txt | 4 ++-- utilities/comment_utility.sh | 2 -- 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/handlers/fmt_handler.sh b/handlers/fmt_handler.sh index 03401f4..bfda3ed 100644 --- a/handlers/fmt_handler.sh +++ b/handlers/fmt_handler.sh @@ -1,4 +1,4 @@ -execute_fmt () { +execute_fmt() { delete_existing_comments 'fmt' '### Terraform `fmt` Failed' # Exit Code: 0 @@ -16,27 +16,27 @@ execute_fmt () { fi } -fmt_success () { +fmt_success() { info "Terraform fmt completed with no errors. Continuing." } -fmt_fail () { +fmt_fail() { local pr_comment # Exit Code: 1, 2 # 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=$(make_details_with_header "Terraform \`fmt\` Failed" "$INPUT") + pr_comment=$(make_details_with_header "Terraform \`fmt\` Failed ❌" "$INPUT") fi # Exit Code: 3 # Meaning: One or more files are incorrectly formatted. # Actions: Iterate over all files and build diff-based PR comment. if [[ $EXIT_CODE -eq 3 ]]; then - pr_comment=$(make_details_with_header "Terraform \`fmt\` Failed" "$INPUT" "diff") + pr_comment=$(make_details_with_header "Terraform \`fmt\` Failed ❌" "$INPUT" "diff") fi # Add fmt failure comment to PR. make_and_post_payload "fmt failure" "$pr_comment" -} \ No newline at end of file +} diff --git a/handlers/init_handler.sh b/handlers/init_handler.sh index 037b518..39e13ba 100644 --- a/handlers/init_handler.sh +++ b/handlers/init_handler.sh @@ -1,4 +1,4 @@ -execute_init () { +execute_init() { delete_existing_comments "init" '### Terraform `init` Failed' # Exit Code: 0 @@ -16,12 +16,12 @@ execute_init () { fi } -init_success () { +init_success() { info "Terraform init completed with no errors. Continuing." } -init_fail () { - local pr_comment=$(make_details_with_header "Terraform \`init\` Failed" "$INPUT") +init_fail() { + local pr_comment=$(make_details_with_header "Terraform \`init\` Failed ❌" "$INPUT") make_and_post_payload "init failure" "$pr_comment" -} \ No newline at end of file +} diff --git a/handlers/plan_handler.sh b/handlers/plan_handler.sh index 0789724..7aa61fd 100644 --- a/handlers/plan_handler.sh +++ b/handlers/plan_handler.sh @@ -1,4 +1,4 @@ -execute_plan () { +execute_plan() { # shellcheck disable=SC2016 delete_existing_comments 'plan' '### Terraform `plan` .* for Workspace: `'"$WORKSPACE"'`.*' delete_existing_comments 'outputs' '### Changes to outputs for Workspace: `'"$WORKSPACE"'`.*' @@ -18,14 +18,14 @@ execute_plan () { fi } -plan_success () { +plan_success() { post_plan_comments if [[ $POST_PLAN_OUTPUTS == 'true' ]]; then post_outputs_comments fi } -plan_fail () { +plan_fail() { local clean_input local delimiter_start_cmd local delimiter_start_strings=() @@ -39,10 +39,10 @@ plan_fail () { clean_input=$(echo "$INPUT" | perl -pe "${delimiter_start_cmd}") - post_diff_comments "plan" "Terraform \`plan\` Failed for Workspace: \`$WORKSPACE\`" "$clean_input" + post_diff_comments "plan" "Terraform \`plan\` Failed for Workspace: \`$WORKSPACE\` ❌" "$clean_input" } -post_plan_comments () { +post_plan_comments() { local clean_input local delimiter_start_strings=() local delimiter_start_cmd @@ -62,7 +62,7 @@ post_plan_comments () { clean_input=$(echo "$INPUT" | perl -pe "${delimiter_start_cmd}") clean_input=$(echo "$clean_input" | sed -r "${delimiter_end_cmd}") - post_diff_comments "plan" "Terraform \`plan\` Succeeded for Workspace: \`$WORKSPACE\`" "$clean_input" + post_diff_comments "plan" "Terraform \`plan\` Succeeded for Workspace: \`$WORKSPACE\` ✅" "$clean_input" } post_outputs_comments() { @@ -82,5 +82,5 @@ post_outputs_comments() { clean_input=$(echo "$INPUT" | perl -pe "${delimiter_start_cmd}") clean_input=$(echo "$clean_input" | sed -r "${delimiter_end_cmd}") - post_diff_comments "outputs" "Changes to outputs for Workspace: \`$WORKSPACE\`" "$clean_input" -} \ No newline at end of file + post_diff_comments "outputs" "Changes to outputs for Workspace: \`$WORKSPACE\` ⚠️" "$clean_input" +} diff --git a/handlers/tflint_handler.sh b/handlers/tflint_handler.sh index fba8516..2ed411c 100644 --- a/handlers/tflint_handler.sh +++ b/handlers/tflint_handler.sh @@ -1,4 +1,4 @@ -execute_tflint () { +execute_tflint() { # shellcheck disable=SC2016 delete_existing_comments 'tflint' '### Linter `TFLint` .* for Workspace: `'"$WORKSPACE"'`.*' @@ -17,14 +17,14 @@ execute_tflint () { fi } -tflint_success () { - info "TFLint completed with no errors. Continuing." +tflint_success() { + info "TFLint completed with no errors. Continuing." } -tflint_fail () { +tflint_fail() { local pr_comment - pr_comment=$(make_details_with_header "Linter \`TFLint\` Failed for Workspace: \`$WORKSPACE\`" "$INPUT") + pr_comment=$(make_details_with_header "Linter \`TFLint\` Failed for Workspace: \`$WORKSPACE\` ❌" "$INPUT") make_and_post_payload "tflint failure" "$pr_comment" } diff --git a/handlers/validate_handler.sh b/handlers/validate_handler.sh index 4e14f9e..b9e4f3a 100644 --- a/handlers/validate_handler.sh +++ b/handlers/validate_handler.sh @@ -1,4 +1,4 @@ -execute_validate () { +execute_validate() { delete_existing_comments "validate" '### Terraform `validate` Failed' # Exit Code: 0 @@ -16,14 +16,14 @@ execute_validate () { fi } -validate_success () { +validate_success() { info "Terraform validate completed with no errors. Continuing." } -validate_fail () { +validate_fail() { local pr_comment - pr_comment=$(make_details_with_header "Terraform \`validate\` Failed" "$INPUT" "diff") + pr_comment=$(make_details_with_header "Terraform \`validate\` Failed ❌" "$INPUT" "diff") make_and_post_payload "validate failure" "$pr_comment" -} \ No newline at end of file +} diff --git a/testing/text-files/tf_plan_success_with_outputs.txt b/testing/text-files/tf_plan_success_with_outputs.txt index 8228b85..2edd916 100644 --- a/testing/text-files/tf_plan_success_with_outputs.txt +++ b/testing/text-files/tf_plan_success_with_outputs.txt @@ -157,9 +157,9 @@ Terraform will perform the following actions: Changes to Outputs: + test_output = [ + [ - + "my-tf-test-bucket-100", + "my-tf-test-bucket-1", - + "my-tf-test-bucket-200", + + "my-tf-test-bucket-1", + + "my-tf-test-bucket-2", + "my-tf-test-bucket-3", + "my-tf-test-bucket-4", ], diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index 8c9f1c8..e577588 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -123,8 +123,6 @@ delete_existing_comments() { jq+=$regex jq+='")) | .id' - debug "jq: $jq" - # gross, but... bash. get_page_count PAGE_COUNT last_page=$PAGE_COUNT From 6d98b6fbc1eaf93936e15a42ff52213d634478e0 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 10:36:48 +0200 Subject: [PATCH 22/34] add output test again --- .github/workflows/test.yaml | 1 + action.yml | 3 +++ entrypoint.sh | 2 ++ 3 files changed, 6 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f8a1c28..269d4aa 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -75,6 +75,7 @@ jobs: if: ${{ env.TESTING == 'true' }} - name: Test if: ${{ env.TESTING == 'true' }} + id: test uses: k1rk/terraform-pr-commenter@monorepo #set to your branch for testing and switch back to v3-beta when done. with: commenter_type: plan diff --git a/action.yml b/action.yml index 7e01684..423442a 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,9 @@ inputs: project: description: project name to use in the comment required: false +outputs: + comment_id: + description: ID of created comment runs: using: "composite" steps: diff --git a/entrypoint.sh b/entrypoint.sh index e8c85b9..6e977ab 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -38,3 +38,5 @@ if [[ $COMMAND == 'tflint' ]]; then execute_tflint exit 0 fi + +echo "comment_id=max" >>$GITHUB_OUTPUT From bb9e9693f362a2459df235f4d8b37028dc90d1bf Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 10:47:14 +0200 Subject: [PATCH 23/34] define output value --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 423442a..1df0b13 100644 --- a/action.yml +++ b/action.yml @@ -31,6 +31,7 @@ inputs: outputs: comment_id: description: ID of created comment + value: ${{ steps.commenter-plan.outputs.comment_id || steps.commenter.outputs.comment_id }} runs: using: "composite" steps: @@ -55,6 +56,7 @@ runs: shell: bash - name: Run commenter image (plan) if: ${{ inputs.commenter_type == 'plan' }} + id: commenter-plan env: COMMENTER_INPUT: ${{ inputs.commenter_input }} COMMENTER_PLAN_FILE: ${{ inputs.commenter_plan_path }} @@ -78,6 +80,7 @@ runs: shell: bash - name: Run commenter image (non-plan) if: ${{ inputs.commenter_type != 'plan' }} + id: commenter env: COMMENTER_INPUT: ${{ inputs.commenter_input }} GITHUB_EVENT: ${{ toJSON(github.event) }} From 3ce1523ab5e3415b7e06a573c3f06c2066898c44 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 11:22:53 +0200 Subject: [PATCH 24/34] static output --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 1df0b13..8865605 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,7 @@ inputs: outputs: comment_id: description: ID of created comment - value: ${{ steps.commenter-plan.outputs.comment_id || steps.commenter.outputs.comment_id }} + value: "dsa" runs: using: "composite" steps: From b803b74c1173f9202f5f19c30e155b3e0e207303 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 11:41:49 +0200 Subject: [PATCH 25/34] one more test --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 8865605..ea903ff 100644 --- a/action.yml +++ b/action.yml @@ -98,3 +98,6 @@ runs: -e COMMENTER_ECHO \ commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }} shell: bash + - name: "test-output" + run: echo random-number ${{ steps.commenter-plan.outputs.comment_id }} + \ No newline at end of file From 0ce9900377666c6ddd1eb851b7e118a0fa195f26 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 14:33:11 +0200 Subject: [PATCH 26/34] added shell --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ea903ff..c81faf7 100644 --- a/action.yml +++ b/action.yml @@ -100,4 +100,4 @@ runs: shell: bash - name: "test-output" run: echo random-number ${{ steps.commenter-plan.outputs.comment_id }} - \ No newline at end of file + shell: bash From b992cf17b1f6dc571db0e880efe206f23027a8c0 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 14:38:43 +0200 Subject: [PATCH 27/34] look --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index c81faf7..dae367d 100644 --- a/action.yml +++ b/action.yml @@ -98,6 +98,10 @@ runs: -e COMMENTER_ECHO \ commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }} shell: bash + - name: "test-output1" + run: echo $GITHUB_OUTPUT + shell: bash + - name: "test-output" run: echo random-number ${{ steps.commenter-plan.outputs.comment_id }} shell: bash From 9cd4cafd448a1cd7cb6b761b3e21321fd46d760c Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 14:44:40 +0200 Subject: [PATCH 28/34] mount github output stream --- action.yml | 6 ++---- entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index dae367d..1305776 100644 --- a/action.yml +++ b/action.yml @@ -76,6 +76,7 @@ runs: -e COMMENTER_PLAN_FILE \ -e COMMENTER_POST_PLAN_OUTPUTS \ -v "$(pwd)"/:/workspace \ + -v "$GITHUB_OUTPUT":/github-ouput \ commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }} shell: bash - name: Run commenter image (non-plan) @@ -96,12 +97,9 @@ runs: -e COMMENTER_INPUT \ -e COMMENTER_DEBUG \ -e COMMENTER_ECHO \ + -v "$GITHUB_OUTPUT":/github-ouput \ commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }} shell: bash - - name: "test-output1" - run: echo $GITHUB_OUTPUT - shell: bash - - name: "test-output" run: echo random-number ${{ steps.commenter-plan.outputs.comment_id }} shell: bash diff --git a/entrypoint.sh b/entrypoint.sh index 6e977ab..be3052e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,4 +39,4 @@ if [[ $COMMAND == 'tflint' ]]; then exit 0 fi -echo "comment_id=max" >>$GITHUB_OUTPUT +echo "comment_id=max" >>/github-ouput From 1f41e889fb99019e04679092040456617d3022bf Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 14:54:53 +0200 Subject: [PATCH 29/34] try ls --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index be3052e..b3e4901 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,4 +39,7 @@ if [[ $COMMAND == 'tflint' ]]; then exit 0 fi +ls -la / +ls -la /github-ouput + echo "comment_id=max" >>/github-ouput From 2891238a4df6bc0fba5f17bb32eba67ebb919127 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 14:57:44 +0200 Subject: [PATCH 30/34] debug --- entrypoint.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index b3e4901..ef154fc 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,6 +26,10 @@ fi if [[ $COMMAND == 'plan' ]]; then execute_plan + ls -la / + ls -la /github-output + cat /github-ouput + echo "comment_id=max" >>/github-ouput exit 0 fi @@ -38,8 +42,3 @@ if [[ $COMMAND == 'tflint' ]]; then execute_tflint exit 0 fi - -ls -la / -ls -la /github-ouput - -echo "comment_id=max" >>/github-ouput From e1575082afef119b5c13d3dde4020789976e0b4b Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 15:10:50 +0200 Subject: [PATCH 31/34] clean test --- .github/workflows/test.yaml | 8 ++++++++ action.yml | 9 +++++---- entrypoint.sh | 4 ---- utilities/comment_utility.sh | 4 +++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 269d4aa..e74d9ef 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -98,3 +98,11 @@ jobs: project: dev-team-2 - name: print output run: echo "${{ steps.test.outputs.comment_id }}" + - name: Create comment + uses: peter-evans/create-or-update-comment@v3 + with: + body: | + This is a multi-line test comment + - With GitHub **Markdown** :sparkles: + - [link](${{ steps.test.outputs.comment_url }}) + reactions: "+1" diff --git a/action.yml b/action.yml index 1305776..05f0d25 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,11 @@ inputs: outputs: comment_id: description: ID of created comment - value: "dsa" + value: ${{ steps.commenter-plan.outputs.comment_id || steps.commenter.outputs.comment_id }} + comment_url: + description: URL to comment + value: ${{ steps.commenter-plan.outputs.comment_url || steps.commenter.outputs.comment_url }} + runs: using: "composite" steps: @@ -100,6 +104,3 @@ runs: -v "$GITHUB_OUTPUT":/github-ouput \ commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }} shell: bash - - name: "test-output" - run: echo random-number ${{ steps.commenter-plan.outputs.comment_id }} - shell: bash diff --git a/entrypoint.sh b/entrypoint.sh index ef154fc..e8c85b9 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,10 +26,6 @@ fi if [[ $COMMAND == 'plan' ]]; then execute_plan - ls -la / - ls -la /github-output - cat /github-ouput - echo "comment_id=max" >>/github-ouput exit 0 fi diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index e577588..cc09d2b 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -40,7 +40,9 @@ $body } post_comment() { - curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload" + local comment=$(curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload") + echo "comment_id=$(echo $comment | jq '.id')" >>/github-ouput + echo "comment_url=$(echo $comment | jq '.html_url')" >>/github-ouput } ### DIFF AND STRING SUBSTITUTION UTILITIES ### From acbb299bf202badc5926bec2a2fc97d11d97790f Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 15:16:26 +0200 Subject: [PATCH 32/34] added issue number --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e74d9ef..47723a1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -101,6 +101,7 @@ jobs: - name: Create comment uses: peter-evans/create-or-update-comment@v3 with: + issue-number: ${{ github.event.pull_request.number }} body: | This is a multi-line test comment - With GitHub **Markdown** :sparkles: From dc6790756ba7705a729874cafa7313bf9e0d42f4 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 15:20:00 +0200 Subject: [PATCH 33/34] use raw jq --- utilities/comment_utility.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/comment_utility.sh b/utilities/comment_utility.sh index cc09d2b..b688aba 100644 --- a/utilities/comment_utility.sh +++ b/utilities/comment_utility.sh @@ -41,8 +41,8 @@ $body post_comment() { local comment=$(curl -sS -L -X POST -H "$ACCEPT_HEADER" -H "$AUTH_HEADER" -H "$CONTENT_HEADER" "$PR_COMMENTS_URL" -d "$pr_payload") - echo "comment_id=$(echo $comment | jq '.id')" >>/github-ouput - echo "comment_url=$(echo $comment | jq '.html_url')" >>/github-ouput + echo "comment_id=$(echo $comment | jq -r '.id')" >>/github-ouput + echo "comment_url=$(echo $comment | jq -r '.html_url')" >>/github-ouput } ### DIFF AND STRING SUBSTITUTION UTILITIES ### From 5a5b56b9e0841c4cd7b792c63a5b52370c1c5025 Mon Sep 17 00:00:00 2001 From: k1rk <8kirk8@gmail.com> Date: Thu, 17 Aug 2023 15:33:04 +0200 Subject: [PATCH 34/34] updated test and readme --- .github/workflows/test.yaml | 12 +----------- README.md | 9 +++++++++ action.yml | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 47723a1..d9f91fc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -84,7 +84,6 @@ jobs: #commenter_plan_path: ./testing/text-files/tf_plan_success_with_outputs.txt commenter_exitcode: 2 use_beta_version: "true" - project: dev-team-1 - name: Test-project-2 if: ${{ env.TESTING == 'true' }} uses: k1rk/terraform-pr-commenter@monorepo #set to your branch for testing and switch back to v3-beta when done. @@ -96,14 +95,5 @@ jobs: commenter_exitcode: 2 use_beta_version: "true" project: dev-team-2 - - name: print output + - name: test output run: echo "${{ steps.test.outputs.comment_id }}" - - name: Create comment - uses: peter-evans/create-or-update-comment@v3 - with: - issue-number: ${{ github.event.pull_request.number }} - body: | - This is a multi-line test comment - - With GitHub **Markdown** :sparkles: - - [link](${{ steps.test.outputs.comment_url }}) - reactions: "+1" diff --git a/README.md b/README.md index dce799d..04500ee 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ jobs: | `commenter_exitcode` | ___required___ | The exit code from a previous step output. | | `terraform_version` | ___optional___ | The version of terraform from the workflow. Defaults to `1.4.6`. | | `use_beta_version` | ___optional___ | Whether or not to use the beta version of the commenter. | +| `project` | ___optional___ | Project name to use in comments header. usefull for monorepos | ### Environment Variables @@ -122,6 +123,14 @@ jobs: | `HIGHLIGHT_CHANGES` | ___optional___ | Default: `true`. This switches `~` to `!` in `plan` diffs to highlight Terraform changes in orange. Set to `false` to disable. | | `COMMENTER_DEBUG` | ___optional___ | Default: `false`. This switches the commenter into debug mode. | +### Outputs + +| Name | Description | +|---|---| +| `comment_id` | ID of comment created by step. Can be used for further manipulations with comment | +| `comment_url` | URL pointing to comment created by step. Can be used to create a link from summary or to send a notification | + + ## Notes * The commenter requires a pull request to run so the github event must contain a `.pull_request.number`. diff --git a/action.yml b/action.yml index 05f0d25..6c8807e 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,7 @@ outputs: description: ID of created comment value: ${{ steps.commenter-plan.outputs.comment_id || steps.commenter.outputs.comment_id }} comment_url: - description: URL to comment + description: URL to created comment value: ${{ steps.commenter-plan.outputs.comment_url || steps.commenter.outputs.comment_url }} runs: