Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument list is too long #107

Open
Nayana-Nagaraj opened this issue Aug 3, 2023 · 6 comments
Open

Argument list is too long #107

Nayana-Nagaraj opened this issue Aug 3, 2023 · 6 comments

Comments

@Nayana-Nagaraj
Copy link

We are not able to Commnet the PR for more than 262,144 characteristics. We are getting a Argument list is too long error. Requesting you to please let us know if we can increase the limit of the PR characteristics

@shayonj
Copy link

shayonj commented Aug 10, 2023

Running into the same issue. ulimit -s shows the stack size to be 16kb in Github action. Some way to bump the stack size would be nice as a mitigation?

@codebydant
Copy link

I am having the same problem with a terraform plan

image

@sammcj
Copy link

sammcj commented Mar 12, 2024

We're hitting this as well.

@JorritSalverda
Copy link

I use this very nice action to write a terraform plan to a PR comment. But very often the plan is too long and I see this same error. Is there an easy way to trim the length to the maximum allowed by GH?

@codebydant
Copy link

codebydant commented Jul 16, 2024

I use this very nice action to write a terraform plan to a PR comment. But very often the plan is too long and I see this same error. Is there an easy way to trim the length to the maximum allowed by GH?

I have found a solution @JorritSalverda

- name: Terraform - Show Plan in PR
  uses: actions/github-script@v7.0.1
  continue-on-error: true
  if: github.event_name == 'pull_request'
  with:
    script: |
      // Get the existing comments.
      const {data: comments} = await github.rest.issues.listComments({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: context.payload.number,
      })

      // Find any comment already made by the bot that contains 'Plan for ${{ inputs.environment-name }}'
      const botComment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes(`### Plan for ${{ inputs.environment-name }}`))

      // Terraform plan output
      const run_url = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY + '/actions/runs/' + process.env.GITHUB_RUN_ID
      const run_link = '<a href="' + run_url + '">Actions</a>.'
      const fs = require('fs')
      const plan_file = fs.readFileSync('plan.txt', 'utf8')
      const plan = plan_file.length > 65000 ? plan_file.toString().substring(0, 65000) + " ..." : plan_file
      const truncated_message = plan_file.length > 65000 ? "Output is too long and was truncated. You can read full Plan in " + run_link + "<br /><br />" : ""
      const output = `### Plan for ${{ inputs.environment-name }} 😏😏
      #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
      #### Terraform Plan 📖\`${{ steps.plan_step.outcome }}\`

      <details><summary>Show Plan</summary>

      \`\`\`diff
      ${plan}
      \`\`\`

      </details>
      ${truncated_message}

      *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ github.workspace }}\`, Workflow: \`${{ github.workflow }}\`*`;

      if (botComment) {
        console.log('Found existing comment... updating');
        await github.rest.issues.updateComment({
          owner: context.repo.owner,
          repo: context.repo.repo,
          comment_id: botComment.id,
          body: output
        })
      } else {
        console.log('Creating new comment...');
        await github.rest.issues.createComment({
          issue_number: context.issue.number,
          owner: context.repo.owner,
          repo: context.repo.repo,
          body: output
        })
      }

This is an example when the output is greater than the limit:

image

@JorritSalverda
Copy link

Thanks @dtcMLOps,

That actually set me on the path of doing this in the following way while still using this mshick/add-pr-comment action:

      - name: Create Terraform plan
        id: plan
        run: |
          terraform plan -out=tfplan
          terraform show tfplan -no-color > tfplan.txt
      - name: Truncate Terraform plan
        uses: mathiasvr/command-output@v2.0.0
        id: truncate
        with:
          run: |
            maxsize=65000
            actualsize=$(wc -c < tfplan.txt)
            if [ $actualsize -gt $maxsize ]; then
                truncate --size=$maxsize tfplan.txt
                echo -n $'\n\n-- truncated due to max PR comment length, check logs from step: Create Terraform plan --' >> tfplan.txt
            fi

            cat tfplan.txt
      - name: Add PR comment
        uses: mshick/add-pr-comment@v2
        if: ${{ always() }}
        with:
          message: |
            `terraform fmt`: ${{ steps.fmt.outcome }}
            `terraform init`: ${{ steps.init.outcome }}
            `terraform validate`: ${{ steps.validate.outcome }}

            <details open>
            <summary>

            #### Output from `terraform validate`

            </summary>

            ```hcl
            ${{ steps.validate.outputs.stdout }}
            ```

            </details>

            `terraform plan`: ${{ steps.plan.outcome }}

            <details open>
            <summary>

            #### Output from `terraform plan`

            </summary>

            ```hcl
            ${{ steps.truncate.outputs.stdout }}
            ```

            </details>

It also nicely color codes the plan, although not exactly the same as in the output from terraform plan itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants