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

"Error: Not Found" if push event's before commit is 0000000000000000000000000000000000000000 #128

Open
douglascayers opened this issue Sep 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@douglascayers
Copy link

douglascayers commented Sep 22, 2022

Scenario

When configured to run on a push event and the GitHub's context.payload.before commit is 0000000000000000000000000000000000000000 (meaning there was no prior commit) then the action fails with error Error: Not Found.

The error is raised by util.js by determineModifiedFiles(..) function when it invokes octokit.rest.repos.compareCommitsWithBasehead(..)

https://github.com/pmd/pmd-github-action/blob/main/lib/util.js#L143

Config File

# .github/workflows/pmd.yml
name: Run PMD

on:
    push:
        branches:
            - my-branch
        paths:
            - my-folder

jobs:
    build:
        name: Run PMD
        runs-on: self-hosted
        steps:
            - name: Checkout repository
              uses: actions/checkout@v3

            - name: Run Apex Rules
              uses: pmd/pmd-github-action@v1
              with:
                  rulesets: rulesets/PMD/apex-rules-github.xml
                  sourcePath: my-folder
                  analyzeModifiedFilesOnly: true
                  createGitHubAnnotations: true

Expected Result

  • PMD to not perform a diff comparison because there is no prior commit.
  • PMD to identify the list of files included in the commit for the given source path.

Example using Git:

$ git diff-tree --no-commit-id --name-only --diff-filter=AM -r <commit>
index.html
my-folder/some-file.java

Example using Octokit

const response = await octokit.rest.repos.getCommit({
    ...context.repo,
    ref: eventData.after,
});
console.log(response);

---

{
  status: 200,
  url: 'https://api.github.com/repos/my-org/my-repo/commits/65a6b28ce342017b77bde00498434386961cdff7',
  headers: {
    ...
  },
  data: {
    sha: '65a6b28ce342017b77bde00498434386961cdff7',
    node_id: 'C_kwDOFndAydoAKDY1YTZiMjhjZTM0MjAxN2I3N2JkZTAwNDk4NDM0Mzg2OTYxY2RmZjc',
    commit: {
      ...
    },
    url: '...',
    html_url: '...',
    comments_url: '...',
    author: {
      ...
    },
    committer: {
      ...
    },
    parents: [ { ... } ],
    stats: { total: 40, additions: 36, deletions: 4 },
    files: [
        {
            sha: '4b38cfc1be0f3290f3340093825b6bbc48fd69b4',
            filename: 'index.html',
            status: 'modified',
            additions: 9,
            deletions: 1,
            changes: 10,
            blob_url: '...',
            raw_url: '...',
            contents_url: '...',
            patch: '...'
        },
        {
            sha: '565abd034c00e10add52d15cfe478f5bee3fe1da',
            filename: 'my-folder/my-file.java',
            status: 'modified',
            additions: 9,
            deletions: 1,
            changes: 10,
            blob_url: '...',
            raw_url: '...',
            contents_url: '...',
            patch: '...'
        }
    ]
  }
}

Actual Result

  • Action fails with the following error
##[debug]finished caching tool
Using PMD 6.49.0 from cached path /home/docker/actions-runner/_work/_tool/pmd/6.49.0/x64
Determining modified files in my-folder...
##[debug]Push on refs/heads/my-branch: 0000000000000000000000000000000000000000...c46068a4fd0827f6c4365d24c02c1bc44707287a
Error: Not Found
##[debug]Node Action run completed with exit code 1

Workaround

  • Push another commit to the branch
@adangel adangel added the bug Something isn't working label Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants