diff --git a/action.yml b/action.yml index 438f217..5347d4a 100644 --- a/action.yml +++ b/action.yml @@ -36,7 +36,7 @@ runs: steps: - uses: actions/setup-python@v5 with: - python-version: '3.12' + python-version: "3.12" - name: Setup tfenv if: ${{ inputs.terraform_version != 'system' }} @@ -117,6 +117,10 @@ runs: - id: result run: | + echo "$(cat report.md)" >> $GITHUB_STEP_SUMMARY + + venv/bin/python "${{ github.action_path }}/report_postprocess.py" report.md + delimiter="$(openssl rand -hex 8)" echo "result<<$delimiter" >> $GITHUB_OUTPUT @@ -126,8 +130,6 @@ runs: echo "report<<$delimiter" >> $GITHUB_OUTPUT echo "$(cat report.md)" >> $GITHUB_OUTPUT echo "$delimiter" >> $GITHUB_OUTPUT - - echo "$(cat report.md)" >> $GITHUB_STEP_SUMMARY shell: bash - uses: actions/github-script@v7 diff --git a/report_postprocess.py b/report_postprocess.py new file mode 100644 index 0000000..4284911 --- /dev/null +++ b/report_postprocess.py @@ -0,0 +1,39 @@ +import argparse +import os + +parser = argparse.ArgumentParser() +parser.add_argument( + "report", + help="Path to report file in markdown format", + type=argparse.FileType("r+", encoding="UTF-8"), +) + + +def remove_plan(report: str) -> str: + report_lines = [ + f"### ⚠️ _Terraform plan details have been removed from the report to fit within the maximum comment length. Check [workflow summary]({os.environ["GITHUB_SERVER_URL"]}/{os.environ["GITHUB_REPOSITORY"]}/actions/runs/{os.environ["GITHUB_RUN_ID"]}) for the full report._", + "", + "---", + "" + ] + add_line = True + for line in report.splitlines(): + if add_line and line == "
Show Plan": + add_line = False + if add_line: + report_lines.append(line) + if not add_line and line == "
": + add_line = True + return "\n".join(report_lines) + + +if __name__ == "__main__": + args = parser.parse_args() + + report = args.report.read() + if len(report) > 65536: + report = remove_plan(report) + + args.report.seek(0) + args.report.truncate() + args.report.write(report)