Search code examples
githubterraformgithub-actionscicd

Getting `Argument list too long` in GitHub Actions


I am following HashiCorp's learning guide on how to set up GitHub Actions and terraform. All is running great besides the step to update the PR with the Terraform Plan.

I am hitting the following error:


An error occurred trying to start process '/home/runner/runners/2.287.1/externals/node12/bin/node' with working directory '/home/runner/work/ccoe-aws-ou-scp-manage/ccoe-aws-ou-scp-manage'. Argument list too long

The code I am using is:

    - uses: actions/[email protected]
      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 Plan 📖\`${{ steps.plan.outcome }}\`
          <details><summary>Show Plan</summary>
          \`\`\`${process.env.PLAN}\`\`\`
          </details>
          *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
            
          github.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: output
          })

A clear COPY/Paste from the docs: https://learn.hashicorp.com/tutorials/terraform/github-actions

I have tried with actions/github-script version 5 and 6 and still the same problem, But when I copy paste the plan all is great. If I do not use the output variable and use some place holder text for the body all is working great. I can see that the step.plan.outputs.stdout is Ok if I print only that.

I will be happy to share more details if needed.


Solution

  • I also encountered a similar issue. I seem github-script can't give to argument for too long script.

    reference:

    my answer:

          - name: truncate terraform plan result
            run: |
              plan=$(cat <<'EOF'
              ${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
              EOF
              )
              echo "${plan}" | grep -v 'Refreshing state' >> $GITHUB_ENV
              echo "EOF" >> $GITHUB_ENV
    
          - name: create comment from plan result
            uses: actions/[email protected]
            if: github.event_name == 'pull_request'
            with:
              github-token: ${{ secrets.GITHUB_TOKEN }}
              script: |
                const output = `#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
                #### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
                
                <details><summary>Show Plan</summary>
                
                \`\`\`\n
                ${ process.env.PLAN }
                \`\`\`
                
                </details>
                
                *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ inputs.TF_WORK_DIR }}\`, Workflow: \`${{ github.workflow }}\`*`;
    
                github.issues.createComment({
                  issue_number: context.issue.number,
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  body: output
                })```