pmd / pmd-github-action

GitHub Action for PMD
MIT License
39 stars 25 forks source link

Can't run action on GHES #173

Closed mvcmania closed 1 year ago

mvcmania commented 1 year ago

I have seen the similar problem that was already raised but quite unsure if those are identical so that is why i wanted to report it. Im receiving the error below.

Screenshot 2023-03-15 at 10 17 13

And here is the my action YML. Please advise.

# Unique name for this workflow
name: Pre-Release PR
# Definition when the workflow should run
on:
  workflow_dispatch:
  pull_request:
    types: [opened, edited, synchronize, reopened]
permissions:
  pull-requests: write
jobs:
  pmd-run:
    runs-on: catalyst
    steps:
      # Now we install nodejs in the VM, and specify version 14
      - uses: actions/setup-node@v3
        with:
          node-version: "14"
      # Install java as it is required for the next step
      - uses: actions/setup-java@v3
        with:
          distribution: "temurin"
          java-version: "8"
      # Checkout the source code
      - name: "Checkout source code"
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      # Run PMD scan
      - name: "Run PMD scan"
        uses: pmd/pmd-github-action@v1.3.0
        id: pmd
        with:
          sourcePath: "force-app"
          rulesets: "ruleset.xml"
          analyzeModifiedFilesOnly:
          createGitHubAnnotations: true

      # Check for PMD violations
      - name: "Check for PMD violations"
        if: steps.pmd.outputs.violations != 0
        run: exit 1
mvcmania commented 1 year ago

analyzeModifiedFilesOnly : false

adangel commented 1 year ago

I think the message "Error: Not Found" is the response from github API when determining the latest PMD version.

The action tries to request https://api.github.com/repos/pmd/pmd/releases/latest - which seems to have failed.

We definitely can improve the error message here...

Does this problem persist? Maybe it was just a temporary problem....

mvcmania commented 1 year ago

Hey @adangel thanks for quick response, unfortunately it seems like a persistent but what you have said triggered a point, so im running the github action on enterprise instance where we have self-hosted runners , im suspecting , maybe the endpoint that you mentioned is not reachable under the self-hosted runner. Sounds quite unlikely but , it might be the root cause.

adnansakel commented 1 year ago

Hi @adangel I could curl the url https://api.github.com/repos/pmd/pmd/releases/latest from our self hosted runner. But we get that Not Found error persistently.

adangel commented 1 year ago

Hm... I'm having a suspicion, what's happening here: We use the "hydrated" github client from the actions-toolkit. "hydrated" means, it uses not necessarily api.github.com as baseurl, but your GHES url - and on your github enterprise server, there is no pmd/pmd repository.

I think, we use this url: https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/github/src/internal/utils.ts#L23-L25

In case of GHES, the environment variable GITHUB_API_URL will be set and we don't query api.github.com anymore....

mvcmania commented 1 year ago

Hi @adangel , latest update :) We have mirrored pmd/pmd repo along with releases and tags into our GHES and we were able to pass ther "Error : NOT found" problem, we ended up another problem though which completely different. Im posting here in case you might need to fix the problem Screenshot 2023-03-17 at 16 46 43

mvcmania commented 1 year ago

By the way, i have already tried the fix that you have just created, it is working like a charm. Thank you. All errors are gone!

adangel commented 1 year ago

It seems, the downloaded releases zip file is corrupt. You can try to download manually the URL, that is printed in the debug output (##[debug]Downloading https....) and verify e.g. with zipinfo that this is indeed a PMD releases archive. You can also compare this file with the one on https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.55.0/pmd-bin-6.55.0.zip

The sha256sum of that file should be 1acf96d43cb40d591cacccc1c20a66fc796eaddf69ea61812594447bac7a11d pmd-bin-6.55.0.zip.

Maybe something went wrong when mirroring pmd/pmd?

Anyway, my PR #175 will use api.github.com to access the latest release. If you want, you can try out the fix:

- uses: adangel/pmd-github-action@issue-173
adangel commented 1 year ago

By the way, i have already tried the fix that you have just created, it is working like a charm. Thank you. All errors are gone!

Thanks for testing! :+1: