-
Notifications
You must be signed in to change notification settings - Fork 65
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
Run show
internally; fix yaml diffs
#30
base: master
Are you sure you want to change the base?
Conversation
Reference main branch
* Fix yaml diffs * Remove branch callout * Cleanup and doc
* Add debug flags * Point at branch * Fix echo check' * Work with failed plans; attempt to cd for doing tf show * Perform init on plan (sigh) * Perform init on plan (sigh) * Fix error handling a bit * Fix case of short plan * Remove branch ref
* Don't regex replace in the context of '+/-' * Point to branch * Try perl? * Not perl. sed -r maybe? * Use perl but install it this time * Remove branch
@robburger can you take a look at this? |
@robburger would be great if this one will be merged |
* Omit drift detection * Cleanup for PR
@robburger please take a look at this |
* Commit testing files to track changes * Refactor plan * Uncomment delete of old comments * Add debug info * Remove testing statement w/curl * Add more debug * Fix loop bug * Add index to comments * Add index to comments * Add outputs comment(s) * Update for outputs * Fix boundary mixup * Code reuse * Refactor everything to functions * Try fixing failed plan * Try plan fail now * Refactor html tags * Remove comments for outputs * Correct commenter input * Fix up commenter plan failure * Remove branch ref (back to master) * Remove temp file
* Fix style syntax * Point at branch * Remove branch ref
Refactored the bash into functions, cleaned up the comment count, and added a "Changes to Outputs" comment with a flag to enable it. Problem: usage gets a little messier if you do have really long diffs. The step that generates the plan is responsible for trimming the output string to avoid passing a too-long variable into bash on the next step. We must continue to propagate the text output from the plan step for the "plan failed" case, but handling that case brings back the "argument too long" problems on the success case. So we bite the bullet and handle it. - name: TF Plan - Run
id: plan
# have to use /bin/bash because GHA runs by default with `set -e` to end execution on any error.
# we want to capture the error instead.
shell: '/bin/bash {0}'
run: |
# a lot going on here. copy the stdout file handle to fd5.
exec 5>&1
# merge stderr into stdout and print it to fd5 (parent shell's stdout); exit with the code from terraform plan
OUTPUT=$(terraform plan -lock=false -input=false -out=tfplan 2>&1 | tee /dev/fd/5; exit ${PIPESTATUS[0]})
# store the exit code here
EXITCODE=$?
# github actions doesn't allow us to set a multiline output so we cat it to the environment
echo "PLAN_OUTPUT<<EOF" >> $GITHUB_ENV
echo "${OUTPUT::65000}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# set exit code for pickup later, and make sure we exit with same code
echo "::set-output name=exit::${EXITCODE}"
exit $EXITCODE
- name: Post TF Plan Comment
if: ${{ always() && github.ref != format('refs/heads/{0}', github.event.repository.default_branch) && inputs.enable_plan_commenter == 'true' }}
uses: GetTerminus/terraform-pr-commenter@master
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
EXPAND_SUMMARY_DETAILS: "false"
TF_WORKSPACE: ${{ inputs.tf_workspace }}
with:
commenter_type: plan
commenter_input: ${{ env.PLAN_OUTPUT }}
commenter_plan_path: tfplan
commenter_exitcode: ${{ steps.plan.outputs.exit }}
terraform_version: ${{ inputs.terraform_version }} |
feat: add versioning to commenter
BREAKING: Switch to version v2
BREAKING CHANGE: Switch to version v2
* Try paginating comments * Fix range * Update action to run from branch (undo before merge) * Update beta release to track v2; add flag to run beta commenter * Fix pagination url * Better logging * Really fix query parameter * Detect rate limiting(ish) * Fix deletes during pagination
@jcogilvie if this is not the right place to report this , pls redirect to the best way for this communication. I am using your forked repo action:
for 1 repo i have 3 envs running in parallel . but for only 1 env i never get plan PR comment . logs for the PR comments that worked:
logs for the PR comments that didn't work :
plan output:
|
Hey there @sunnyoswalcro -- I just enabled issues on the forked repo, if you want to put this over there. |
feat: add test workflow
fix: test workflow
Fixes #27 and #8
It's a little rough around the edges but this fork does three big things:
plan
, it runsterraform show
internally to build its comments; this saves us from the 64k character limitplan
whose output exceeds 64k, it splits the plan comment into as many as are necessary to capture all the output (and, correspondingly, it deletes all matching plan comments now, instead of just the first)-
are known to be diff-removal lines; lines with a non-red-
are known to be text contents; therefore when we find a red one, we temporarily swap it out for an intermediate representation (a literal 😅 in high unicode) before swapping it back at the end in the final diff.It now accepts a terraform version argument (for plan compatibility purposes) and it expects auth to be available on the environment (to an s3 backend; other cloud providers not tested). Further, it assumes that if you have a plan, it is named
tfplan
. I didn't want to mess with the externally-facing API, so I leave it to @robburger to decide how to accept aplan
file name and what to do with the COMMENTER_INPUT env var that I have used to make the command line invocation more legible.I apologize for the commit noise; I forgot to set the merge method to "squash" when I forked/merged a couple PRs on my end.