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

Output to file and comment at the same time. #1412

Open
jamengual opened this issue Sep 26, 2024 · 7 comments
Open

Output to file and comment at the same time. #1412

jamengual opened this issue Sep 26, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@jamengual
Copy link

jamengual commented Sep 26, 2024

Feature Overview

We use the output to file and then pass it to the summary output and other steps happening later, but we need to comment on the PR simultaneously, but since `--output ${{ steps.vars.outputs.summary_file }} disables the PR comment. We had to run the plan twice, which is sometimes really slow.

It would be nice to be able to output to the file and comment to the PR at the same time or even pipe in the plan from a file to then comment on the PR ( although not as nice and requires two command)

reference https://github.com/cloudposse/github-action-atmos-terraform-plan/blob/main/action.yml#L201 ( this one only outputs to file, so I had to duplicate the step to comment to the PR)

Why is the feature needed?

to comment to the PR and output to a file for further processing

note

nothing

@jamengual jamengual added the enhancement New feature or request label Sep 26, 2024
@suzuki-shunsuke
Copy link
Owner

Thank you for your feedback.
We'll consider how to handle this issue.

The workaround is to output the result to a text file.

#!/usr/bin/env bash

set -u

tfcmt plan -- terraform plan 2>&1 | tee result.txt
code=${PIPESTATUS[0]}
tfcmt --output plan.md plan -- bash -c "cat result.txt && exit "$code""

@jamengual
Copy link
Author

that assumes plan.md is an empty file?

@jamengual
Copy link
Author

jamengual commented Oct 23, 2024

we are running currently like this:

tfcmt \
        --config ${{ github.action_path }}/config/summary.yaml \
        -owner "${{ github.repository_owner }}" \
        -repo "${{ github.event.repository.name }}" \
        -var "target:${{ steps.vars.outputs.component_slug }}" \
        -var "component:${{ inputs.component }}" \
        -var "componentPath:${{ steps.vars.outputs.component_path }}" \
        -var "commitSHA:${{ inputs.sha }}" \
        -var "stack:${{ inputs.stack }}" \
        -var "job:${{ github.job }}" \
        -var "logoImage:${{ inputs.branding-logo-image }}" \
        -var "logoUrl:${{ inputs.branding-logo-url }}" \
        -var "infracost_enabled:${{ steps.config.outputs.enable-infracost }}" \
        -var "driftModeEnabled:${{ inputs.drift-detection-mode-enabled }}" \
        --output ${{ steps.vars.outputs.summary_file }} \
        --log-level $([[ "${{ inputs.debug }}" == "true" ]] && echo "DEBUG" || echo "INFO") \
        plan -- \
          atmos terraform plan ${{ inputs.component }} \
          --stack ${{ inputs.stack }} \
          -out="${{ steps.vars.outputs.plan_file }}" \
          -lock=false \
          -input=false \
          -no-color \
        &> ${TERRAFORM_OUTPUT_FILE}

then I added :

tfcmt --output  ${{ steps.vars.outputs.plan_file }} plan -- bash -c "cat ${TERRAFORM_OUTPUT_FILE}"

but no comment is made

The summary shows up just fine, so the output of the plan is not empty

@jamengual
Copy link
Author

I figured it out, and it does work, but it would be much better if this could be implemented.

@jamengual
Copy link
Author

It seems that the -patch option does not work when this is set this way, it keeps adding new comments.

@suzuki-shunsuke
Copy link
Owner

It seems that the -patch option does not work when this is set this way, it keeps adding new comments.

🤔 It's weird. Could you create an issue for this?
I think it's another issue.

@jamengual
Copy link
Author

To be honest, implementing an option, would be soooooo much nicer.

look how this look here:
https://github.com/cloudposse/github-action-atmos-terraform-plan/blob/add-cache-and-azure/action.yml#L249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants