forked from GetTerminus/terraform-pr-commenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
87 lines (87 loc) · 3.35 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: 'OpenTofu and TFLint PR Commenter'
description: 'Adds opinionated comments to a PR from OpenTofu fmt/init/plan/validate/tflint output'
author: 'phoenix-actions'
branding:
icon: 'git-pull-request'
color: 'blue'
inputs:
commenter_type:
description: 'The type of comment. Options: [fmt, init, plan, validate, tflint]'
required: true
commenter_input:
description: 'The comment to post from a previous step output. This must be trimmed to at least 128 KiB. Required for non plan commenter types.'
required: false
commenter_plan_path:
description: 'The tfplan file. Required if commenter input is not set for plan commenter types.'
required: false
commenter_exitcode:
description: 'The exit code from a previous step output'
required: true
tofu_version:
description: 'The version of terraform from the workflow.'
required: false
default: '1.8.0'
use_beta_version:
description: 'Whether to use the beta version of the commenter'
required: false
default: 'false'
runs:
using: "composite"
steps:
- name: Set OpenTofu Version if inputs.terraform_version is Empty # Until https://github.com/actions/runner/issues/924 is fixed
id: tf_version
run: |
if [[ -z ${{ inputs.tofu_version }} ]]; then
echo "version=1.8.0" >> $GITHUB_OUTPUT
else
echo "version=${{ inputs.tofu_version }}" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Build commenter docker image (main)
if: ${{ inputs.use_beta_version != 'true' }}
run: docker build --build-arg TOFU_VERSION=${{ steps.tf_version.outputs.version }} -t commenter https://github.com/phoenix-actions/opentofu-pr-commenter.git#v1
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 TOFU_VERSION=${{ steps.tf_version.outputs.version }} -t commenter https://github.com/phoenix-actions/opentofu-pr-commenter.git#v1-beta
shell: bash
- name: Run commenter image (plan)
if: ${{ inputs.commenter_type == 'plan' }}
env:
COMMENTER_INPUT: ${{ inputs.commenter_input }}
COMMENTER_PLAN_FILE: ${{ inputs.commenter_plan_path }}
GITHUB_EVENT: ${{ toJSON(github.event) }}
run: |
docker run \
-e GITHUB_TOKEN \
-e TF_WORKSPACE \
-e EXPAND_SUMMARY_DETAILS \
-e HIGHLIGHT_CHANGES \
-e GITHUB_EVENT \
-e COMMENTER_INPUT \
-e COMMENTER_DEBUG \
-e COMMENTER_ECHO \
-e COMMENTER_PLAN_FILE \
-e COMMENTER_POST_PLAN_OUTPUTS \
-v "$(pwd)"/:/workspace \
commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }}
shell: bash
- name: Run commenter image (non-plan)
if: ${{ inputs.commenter_type != 'plan' }}
env:
COMMENTER_INPUT: ${{ inputs.commenter_input }}
GITHUB_EVENT: ${{ toJSON(github.event) }}
run: |
docker run \
-e GITHUB_TOKEN \
-e TF_WORKSPACE \
-e EXPAND_SUMMARY_DETAILS \
-e HIGHLIGHT_CHANGES \
-e GITHUB_EVENT \
-e COMMENTER_INPUT \
-e COMMENTER_DEBUG \
-e COMMENTER_ECHO \
commenter ${{ inputs.commenter_type }} ${{ inputs.commenter_exitcode }}
shell: bash