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

Cannot read property 'head' of undefined #200

Closed
bzmw opened this issue May 13, 2020 · 5 comments · Fixed by #372
Closed

Cannot read property 'head' of undefined #200

bzmw opened this issue May 13, 2020 · 5 comments · Fixed by #372
Labels

Comments

@bzmw
Copy link

bzmw commented May 13, 2020

Describe the bug

During a run of the Github Actions I get the following:

Run stoplightio/[email protected]
  with:
    file_glob: reference/v2/Index.yaml
    repo_token: ***
    event_name: pull_request
/usr/bin/docker run --name c27d31e4036e1dba5842deb4ae1a78b0ffbbb1_d82818 --label c27d31 --workdir /github/workspace --rm -e INPUT_FILE_GLOB -e INPUT_SPECTRAL_RULESET -e INPUT_REPO_TOKEN -e INPUT_EVENT_NAME -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/captains-log/captains-log":"/github/workspace" c27d31:e4036e1dba5842deb4ae1a78b0ffbbb1
(node:1) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'head' of undefined
    at extractSha (/action/dist/octokit.js:37:47)
    at /action/dist/octokit.js:53:34
    at /action/node_modules/fp-ts-contrib/lib/Do.js:31:96
    at Object.chain (/action/node_modules/fp-ts/lib/Either.js:474:57)
    at DoClass.bindL (/action/node_modules/fp-ts-contrib/lib/Do.js:31:43)
    at Object.exports.getRepositoryInfoFromEvent (/action/dist/octokit.js:53:6)
    at /action/dist/index.js:83:243
    at /action/node_modules/fp-ts/lib/EitherT.js:21:159
    at /action/node_modules/fp-ts/lib/Task.js:114:91
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

To Reproduce

main.yml

name: Run Spectral Linter on Pull Requests

on:
  - pull_request

jobs:
  build:
    name: Run Spectral Linter
    runs-on: ubuntu-latest
    steps:
      # Check out the repository
      - uses: actions/checkout@v2

      # Run Spectral
      - uses: stoplightio/[email protected]
        with:
          file_glob: 'reference/v2/Index.yaml'

Additional context
This also results in a 'pass' for the Github 'Check' which is surprising, I would expect an error on the command output to exit with 0 and show this as a failure.
image

@bzmw bzmw added the bug label May 13, 2020
@jonsgold
Copy link

I get the same. Here is my workflow file .github/workflows/main.yml:

name: OpenAPI Linting

on:
  - push
  - pull_request

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    
    # Run Spectral
    - uses: stoplightio/[email protected]
      with:
        file_glob: 'lib/definitions/**/*.json'

The checks also pass for me.

@mladjanm
Copy link

I got this error as well but only when I run action on pull request. When I configure action to execute on push, action performs linting successfully. Here is my workflow file:

on:
  - pull_request
name: Spectral Lint
jobs:
  spectralChecks:
    name: Spectral checks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Spectral checks
        uses: stoplightio/[email protected]
        with:
          file_glob: '*.yaml'

@grische
Copy link

grische commented Aug 3, 2020

This still seems to be happening with v0.6.1 . Here are the offending lines:

const extractSha = (eventName: string, event: any): E.Either<Error, string> => {
switch (eventName) {
case 'pull_request':
return E.right(event.pull_request.head.sha);

I used jq to verify that the event file has the respective element inside the workflow:

$ jq .pull_request.head.sha < ${GITHUB_EVENT_PATH}
"626a9aa05ab0032c6253f56e741752b263464e5e"

The SHA looks correct.

@grische
Copy link

grische commented Aug 12, 2020

@bzmw I found a potential fix. You can test it by using the hotfix branch genesiscloud/spectral-action@fix/pull_request_sha:

      # Run Spectral
      - uses: genesiscloud/spectral-action@fix/pull_request_sha
        with:
          file_glob: 'reference/v2/Index.yaml'

@hamermike
Copy link

This is still an issue.

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