@@ -118,6 +118,7 @@ jobs:
118
118
role-to-assume : ${{ env.CONFIGURE_AWS_ROLE }}
119
119
120
120
- name : Add PR label
121
+ if : (!contains(join(github.event.pull_request.labels.*.name), format('terraform:{0}', matrix.in['terraform'])))
121
122
uses : actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
122
123
with :
123
124
script : |
@@ -149,6 +150,7 @@ jobs:
149
150
echo TF_CLI_CHDIR=$(echo ${{ matrix.in['chdir'] != '' && format('-chdir={0}{1}', env.CONFIGURE_TF_CHDIR_PREFIX, matrix.in['chdir']) || env.CONFIGURE_TF_CHDIR_PREFIX != '' && format('-chdir={0}', env.CONFIGURE_TF_CHDIR_PREFIX) || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
150
151
echo TF_CLI_PATH=$(echo ${{ matrix.in['chdir'] != '' && format('{0}{1}', env.CONFIGURE_TF_CHDIR_PREFIX, matrix.in['chdir']) || env.CONFIGURE_TF_CHDIR_PREFIX != '' && format('{0}', env.CONFIGURE_TF_CHDIR_PREFIX) || '' }}) >> $GITHUB_ENV
151
152
echo TF_CLI_TFPLAN=$(echo ${{ format('{0} {1} {2} {3} {4} {5} {6} {7} tfplan', github.event.number || github.event.issue.number, matrix.in['backend-config'], matrix.in['chdir'], matrix.in['destroy'], matrix.in['replace'], matrix.in['target'], matrix.in['var-file'], matrix.in['workspace']) }} | sed 's/[[:space:][:punct:]]/-/g') >> $GITHUB_ENV
153
+ echo TF_CLI_VAR_FILE=$(echo ${{ matrix.in['var-file'] != '' && matrix.in['terraform'] == 'plan' && format('-var-file={0}', matrix.in['var-file']) || matrix.in['var-file'] != '' && matrix.in['terraform'] == 'apply' && matrix.in['auto-approve'] != '' && format('-var-file={0}', matrix.in['var-file']) || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
152
154
# Commands
153
155
echo TF_CLI_LOCK_ID=$(echo ${{ matrix.in['lock-id'] }} | sed 's/ /\\ /g') >> $GITHUB_ENV
154
156
echo TF_CLI_WORKSPACE=$(echo ${{ matrix.in['workspace'] }} | sed 's/ /\\ /g') >> $GITHUB_ENV
@@ -166,7 +168,6 @@ jobs:
166
168
echo TF_CLI_REFRESH=$(echo ${{ matrix.in['refresh'] != '' && format('-refresh={0}', matrix.in['refresh']) || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
167
169
echo TF_CLI_REPLACE=$(echo ${{ matrix.in['replace'] != '' && format('-replace={0}', matrix.in['replace']) || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
168
170
echo TF_CLI_TARGET=$(echo ${{ matrix.in['target'] != '' && format('-target={0}', matrix.in['target']) || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
169
- echo TF_CLI_VAR_FILE=$(echo ${{ matrix.in['var-file'] != '' && format('-var-file={0}', matrix.in['var-file']) || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
170
171
# Boolean
171
172
echo TF_CLI_COMPACT_WARNINGS=$(echo ${{ matrix.in['compact-warnings'] != '' && '-compact-warnings' || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
172
173
echo TF_CLI_DESTROY=$(echo ${{ matrix.in['destroy'] != '' && '-destroy' || '' }} | sed 's/ /\\ /g') >> $GITHUB_ENV
@@ -237,20 +238,31 @@ jobs:
237
238
terraform_output : ${{ steps.terraform_apply.outputs.stderr || steps.terraform_apply.outputs.stdout || steps.terraform_plan.outputs.stderr || steps.terraform_plan.outputs.stdout || steps.terraform_force_unlock.outputs.stderr || steps.terraform_force_unlock.outputs.stdout || steps.terraform_workspace.outputs.stderr || steps.terraform_workspace.outputs.stdout || steps.terraform_init.outputs.stderr || steps.terraform_init.outputs.stdout }}
238
239
with :
239
240
script : |
240
- // Store only the first 64800 characters of the terraform output due to GitHub comment's character limit of 65536.
241
- const terraform_output = process.env.terraform_output.substring(0, 64800);
241
+ // From the terraform output, remove any lines which are related to reading or refreshing state, and then
242
+ // store only the first 64800 characters of the output due to GitHub comment's character limit of 65536.
243
+ const terraform_output = process.env.terraform_output
244
+ .split("\n")
245
+ .filter(
246
+ (line) =>
247
+ !(
248
+ line.includes(": Reading...") ||
249
+ line.includes(": Read complete after") ||
250
+ line.includes(": Refreshing state...")
251
+ )
252
+ )
253
+ .join("\n")
254
+ .substring(0, 64800);
242
255
243
256
// Display the terraform output change summary as the collapsible content's title.
244
- const comment_summary =
245
- terraform_output
246
- .split("\n")
247
- .find(
248
- (line) =>
249
- line.startsWith("Apply") ||
250
- line.startsWith("Plan") ||
251
- line.startsWith("Error") ||
252
- line.startsWith("No changes")
253
- ) || "Terraform output.";
257
+ const comment_summary = terraform_output
258
+ .split("\n")
259
+ .find(
260
+ (line) =>
261
+ line.startsWith("Plan") ||
262
+ line.startsWith("Apply") ||
263
+ line.startsWith("Error") ||
264
+ line.startsWith("No changes")
265
+ ) || "Terraform output.";
254
266
255
267
// Display the terraform command authorship before the terraform output as the collapsible content's body.
256
268
// Include the TFPLAN name in the hidden footer as a unique identifier for comment updates.
@@ -260,7 +272,9 @@ jobs:
260
272
261
273
###### ${{ github.workflow }} by @${{ github.actor }} via [${{ github.event_name }}](${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}) at ${{ github.event.pull_request.updated_at || github.event.comment.updated_at }}.</summary>
262
274
263
- \`\`\`hcl${terraform_output}\`\`\`
275
+ \`\`\`hcl
276
+ ${terraform_output}
277
+ \`\`\`
264
278
</details>
265
279
<!-- ${process.env.TF_CLI_TFPLAN} -->`;
266
280
0 commit comments