hashicorp / setup-terraform

Sets up Terraform CLI in your GitHub Actions workflow.
https://developer.hashicorp.com/terraform/tutorials/automation/github-actions
Mozilla Public License 2.0
1.34k stars 235 forks source link

Escape backticks in stdout and stderr #401

Open manabusakai opened 4 months ago

manabusakai commented 4 months ago

I'm using the workflow in the README.

Show Workflow ```yaml defaults: run: working-directory: ${{ env.tf_actions_working_dir }} permissions: pull-requests: write steps: - uses: actions/checkout@v4 - uses: hashicorp/setup-terraform@v3 - name: Terraform fmt id: fmt run: terraform fmt -check continue-on-error: true - name: Terraform Init id: init run: terraform init - name: Terraform Validate id: validate run: terraform validate -no-color - name: Terraform Plan id: plan run: terraform plan -no-color continue-on-error: true - uses: actions/github-script@v6 if: github.event_name == 'pull_request' env: PLAN: "terraform\n${{ steps.plan.outputs.stdout }}" with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\` #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
Validation Output \`\`\`\n ${{ steps.validate.outputs.stdout }} \`\`\`
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
Show Plan \`\`\`\n ${process.env.PLAN} \`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`; github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: output }) ```

CI failed when upgrading the AWS provider.

SyntaxError: Unexpected identifier 'compute_environments_order'
    at new AsyncFunction (<anonymous>)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35424:16)
    at main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35522:26)
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:35497:1
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:35553:3
    at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:35556:12)
    at Module._compile (node:internal/modules/cjs/loader:1241:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
    at Module.load (node:internal/modules/cjs/loader:1091:32)
    at Module._load (node:internal/modules/cjs/loader:938:12)
Error: Unhandled error: SyntaxError: Unexpected identifier 'compute_environments_order'

The cause was that backticks were used in the stdout of warnings. Backticks must be escaped.

Warning: Attribute Deprecated

  with aws_batch_job_queue.example,
  on batch_job_queue.tf line 5, in resource "aws_batch_job_queue" "example":
   5:   compute_environments = [aws_batch_compute_environment.example.arn]

This parameter will be replaced by `compute_environments_order`.

(and 3 more similar warnings elsewhere)