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 24 forks source link

Error: Command failed: git remote add -f destination https://github.com #84

Open pranayjswl007 opened 5 months ago

pranayjswl007 commented 5 months ago

We are using self hosted runner as github runners are quite expensive

https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners

Getting this error:

Run mitchspano/sfdx-scan-pull-request@v0.1.16
Beginning sfdx-scan-pull-request run...
Validating that this action was invoked from an acceptable context...
Getting difference within the pull request ... { baseRef: 'develop', headRef: 'kobilEOD1' }
error: remote destination already exists.
(node:392[8](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:9)) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
node:internal/errors:857
  const err = new Error(message);
              ^

Error: Command failed: git remote add -f destination https://github.com/gojoko-marketing/sf-system-base-package.git
error: remote destination already exists.

    at checkExecSyncError (node:child_process:861:11)
    at execSync (node:child_process:[9](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:10)32:15)
    at /opt/actions-runner/_work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.16/dist/index.js:1:1520
    at Generator.next (<anonymous>)
    at /opt/actions-runner/_work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.16/dist/index.js:1:[10](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:11)59
    at new Promise (<anonymous>)
    at o (/opt/actions-runner/_work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.16/dist/index.js:1:806)
    at getDiffInPullRequest (/opt/actions-runner/_work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.16/dist/index.js:1:1382)
    at /opt/actions-runner/_work/_actions/mitchspano/sfdx-scan-pull-request/v0.1.16/dist/index.js:1:5660 {
  status: 3,
  signal: null,
  output: [
    null,
    Buffer(0) [Uint8Array] [],
    Buffer(42) [Uint8Array] [
      101, [11](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:12)4, 114, 111, 114,  58,  32, 114,
      101, 109, 111, 116, 101,  32, 100, 101,
      115, 116, 105, 110,  97, 116, 105, 111,
      110,  32,  97, 108, 114, 101,  97, 100,
      [12](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:13)1,  32, 101, 120, 105, 115, 116, 115,
       46,  10
    ]
  ],
  pid: 3935,
  stdout: Buffer(0) [Uint8Array] [],
  stderr: Buffer(42) [Uint8Array] [
    101, 114, 114, 111, 114,  58,  32, 114,
    101, 109, 111, 116, 101,  32, 100, 101,
    115, 116, 105, 110,  97, 116, 105, 111,
    110,  32,  97, 108, 1[14](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:15), 101,  97, 100,
    121,  32, 101, 120, 105, 1[15](https://github.com/gojoko-marketing/sf-system-base-package/actions/runs/9371895209/job/25802195477#step:5:16), 116, 115,
     46,  10
  ]
}

YML file

name: PR Validation for develop

on:
  pull_request:
    branches: [develop]

jobs:
  prvalidate-develop:
    runs-on: [self-hosted]

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Salesforce CLI
        run: npm install @salesforce/cli --global

      - name: Install SFDX CLI and Scanner
        run: sf plugins install @salesforce/sfdx-scanner@latest
      - name: Run SFDX Scanner - Report findings as comments
        uses: mitchspano/sfdx-scan-pull-request@v0.1.16
        with:
          pmdconfig: "pmd/masteruleset.xml"
          report-mode: check-runs
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Authorize Devhub
        run: |
          echo "${{ secrets.SF_JWT_SECRET }}" > server.key
          sf org login jwt --client-id=${{ secrets.SF_CONSUMER_KEY }} --jwt-key-file=server.key --username=${{ vars.SF_DEVHUB_USERNAME }} --set-default-dev-hub

      - name: Create scratch org
        run: sf org create scratch --definition-file config/project-scratch-def.json -a ci_scratch --set-default --duration-days 1 -v ${{vars.SF_DEVHUB_USERNAME}}

      - name: Push source to scratch org
        run: sf project deploy start

      - name: run tests and store it
        run: sf apex run test --code-coverage --result-format json --synchronous --test-level RunLocalTests --wait 10 > tests.json

      - name: Post comment to pull request
        run: |
          commentBody="$(python3 pythonscript/calculateCoverage.py)"
          echo "COMMENT<<EOF" >> "$GITHUB_ENV"
          echo "$commentBody" >> "$GITHUB_ENV"
          echo "EOF" >> "$GITHUB_ENV"

      - uses: actions/github-script@v7
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: process.env.COMMENT
            })

      - name: run tests and store it
        run: |
          coverage=$(jq .result.summary.orgWideCoverage tests.json | grep -Eo "[[:digit:]]+")
          echo "Total code coverage is : $coverage"
          test $coverage -ge 90

      - name: Delete scratch org
        if: always()
        run: "sf org delete scratch -p --target-org ci_scratch"

The YML file works perfectly fine if I use native github runner. So something extra need to be done . Cant seem to figure it out

cfman commented 2 days ago

Solved it by cleaning the workspace with https://github.com/marketplace/actions/cleanup-workspace-on-self-hosted-runner for every workflow in my repo. But think this action can be enhanced by checking if the git remote named destination has been defined first before adding