mitchspano / sfdx-scan-pull-request

Runs sfdx-scanner on a pull request and generates in-line comments with the findings.
Apache License 2.0
73 stars 25 forks source link

ambiguous argument error - unclear why #20

Closed dschach closed 2 years ago

dschach commented 2 years ago

I get the feeling that it doesn't like my PMD rules. Eslint seems to dislike them too, but this is a tool that I'd expect to get it. I don't know what the diffBetweenCurrentAndParentBranch.txt file is - are you able to support incremental vs full scans?

Is it hurting because I have no Apex code and basically no metadata? It's a base project template so I have all the things I like set up the way I like them for new projects.

This is my workflow job:

pmd-spano-scanner:
    runs-on: ubuntu-latest
    needs: format-lint-lwc-tests
    if: ${{ github.actor != 'dependabot[bot]' }}
    steps:
      # Checkout the source code
      - name: 'Checkout source code'
        uses: actions/checkout@v3

      - name: Install SFDX CLI and Scanner
        run: |
          npm install sfdx-cli
          node_modules/sfdx-cli/bin/run plugins:install @salesforce/sfdx-scanner
      - name: Run SFDX Scanner - Report findings as comments
        uses: mitchspano/sfdx-scan-pull-request@v0.1.3
        with:
          pmdconfig: 'pmd/deployRules.xml'
          severity-threshold: 1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Error message:

Run mitchspano/sfdx-scan-pull-request@v0.1.3
  with:
    pmdconfig: pmd/deployRules.xml
    severity-threshold: 1
  env:
    GITHUB_TOKEN: ***

Getting difference within the pull request...
fatal: ambiguous argument 'origin/undefined...origin/undefined': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
node:child_process:8[2](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:2)6
    err = new Error(msg);
          ^

Error: Command failed: git diff origin/undefined...origin/undefined > diffBetweenCurrentAndParentBranch.txt
fatal: ambiguous argument 'origin/undefined...origin/undefined': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at checkExecSyncError (node:child_process:826:11)
    at execSync (node:child_process:900:15)
    at getDiffInPullRequest (/home/runner/work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.[3](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:3)/index.js:78:3)
    at main (/home/runner/work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.3/index.js:280:3)
    at Object.<anonymous> (/home/runner/work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.3/index.js:287:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:1[4](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:4))
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:11[5](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:5)3:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  status: 128,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(21[6](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:6)) [Uint8Array] [
      102,  9[7](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:7), 116,  9[7](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:8), 10[8](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:9),  58,  32,  [9](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:10)7, [10](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:11)9,  98, 105, 103,
      [11](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:12)7, 111, 117, 115,  32,  97, 114, 103, 117, 109, 101, 110,
      116,  32,  39, 111, 114, 105, 103, 105, 110,  47, 117, 110,
      100, 101, 102, 105, 110, 101, 100,  46,  46,  46, 111, 114,
      105, 103, 105, 110,  47, 117, 110, 100, 101, 102, 105, 110,
      101, 100,  39,  58,  32, 117, 110, 107, 110, 111, 119, 110,
       32, 114, 101, 118, 105, 115, 105, 111, 110,  32, 111, 114,
       32, 1[12](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:13),  97, 116, 104,  32, 110, 111, 116,  32, 105, 110,
       32, 116, 104, 101,
      ... 116 more items
    ]
  ],
  pid: 1949,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(216) [Uint8Array] [
    102,  97, 116,  97, 108,  58,  32,  97, 109,  98, 105, 103,
    117, 111, 117, 115,  32,  97, 1[14](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:15), 103, 117, 109, 101, 110,
    116,  32,  39, 111, 114, 105, 103, 105, 110,  47, 117, 110,
    100, 101, 102, 105, 110, 101, 100,  46,  46,  46, 111, 114,
    105, 103, 105, 110,  47, 117, 110, 100, 101, 102, 105, 110,
    101, 100,  39,  58,  32, 117, 110, 107, 110, 111, 119, 110,
     32, 114, 101, 118, 105, 1[15](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:16), 105, 111, 110,  32, 111, 114,
     32, 112,  97, 1[16](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:17), 104,  [32](https://github.com/dschach/BaseSFDXProject/actions/runs/3454017819/jobs/5765037153#step:4:33), 110, 111, 116,  32, 105, 110,
     32, 116, 104, 101,
    ... 116 more items
  ]
}
mitchspano commented 2 years ago

Thanks for raising this issue - do you have a link that you can share to the invocation of the GitHub action?

The diffBetweenCurrentAndParentBranch.txt is a text file which stores the difference between the branch you are trying to pull in and the branch you are trying to pull to. This .js template literal is where we concatenate the branch names into a git diff command to determine which files have changed as part of the pull request and populate that file.

execSync(
  `git diff origin/${this.pullRequest?.base?.ref}...origin/${this.pullRequest?.head?.ref} > ${DIFF_OUTPUT}`
)

source.

The fact that this evaluates to origin/undefined...origin/undefined makes it look like this action was executed outside of the scope of a pull request - hence the failure.

dschach commented 2 years ago

That makes sense. I was running it manually.

Does this need to handle that use case?

On Wed, Nov 16, 2022, 06:03 Mitchell spano @.***> wrote:

Thanks for raising this issue - do you have a link that you can share to the invocation of the GitHub action?

The diffBetweenCurrentAndParentBranch.txt is a text file which stores the difference between the branch you are trying to pull in and the branch you are trying to pull to. This .js template https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals literal is where we concatenate the branch names into a git diff command to determine which files have changed as part of the pull request and populate that file.

execSync( git diff origin/${this.pullRequest?.base?.ref}...origin/${this.pullRequest?.head?.ref} > ${DIFF_OUTPUT})

source https://github.com/mitchspano/sfdx-scan-pull-request/blob/main/index.js#L79 .

The fact that this evaluates to origin/undefined...origin/undefined makes it look like this action was executed outside of the scope of a pull request - hence the failure.

— Reply to this email directly, view it on GitHub https://github.com/mitchspano/sfdx-scan-pull-request/issues/20#issuecomment-1317072896, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE3QMPEIWCO5L4OWF3ZPJTWITSSNANCNFSM6AAAAAAR7KTKDE . You are receiving this because you authored the thread.Message ID: @.***>

mitchspano commented 2 years ago

Given that this action is called sfdx-scan-pull-request, I don't know if it needs to be usable outside of that scope. However, I will modify the action so that there is a clear error message in this scenario.

mitchspano commented 2 years ago

Added an error which is thrown when the action is invoked outside the scope of a pull request.