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

Annotations file not found by the action #55

Open
stumelius opened this issue Feb 16, 2022 · 8 comments
Open

Annotations file not found by the action #55

stumelius opened this issue Feb 16, 2022 · 8 comments

Comments

@stumelius
Copy link

I'm getting a Ignoring missing file at 'annotations.json' because 'ignore-missing-file' is true error in my workflow:

- name: Lint SQL
  run: sqlfluff lint --format github-annotation | tee annotations.json || echo "::warning::Linter error ignored!"

- name: Print annotations (for testing purposes)
  run: cat annotations.json

- name: Annotate SQL linting errors
  uses: yuzutech/[email protected]
  with:
    repo-token: "${{ secrets.GITHUB_TOKEN }}"
    title: lint
    input: './annotations.json'

The "Print annotations" step is printing out the annotations but the "Annotate SQL linting errors" step does not find the file. What am I missing here? I have configured the working-directory at the workflow level if that's of any importance here.

@ggrossetie
Copy link
Member

I have configured the working-directory at the workflow level if that's of any importance here.

Might be the reason as we do not use this variable:

const inputContent = await fs.readFile(inputPath, { encoding: 'utf8' })

@ggrossetie
Copy link
Member

Having said that, I expect GitHub Action to execute the annotations-action in the working-directory so fs.readFile('./annotations.json', { encoding: 'utf8' }) should work...

Did you try to explicitly set the working-directory on the task? or use the relative path from the root in input?

@ggrossetie ggrossetie added the ❔ question Further information is requested label Feb 16, 2022
@stumelius
Copy link
Author

Thanks! I just fixed it by including my working directory in the input path.

@stumelius
Copy link
Author

For some reason this action is not run in the working directory or there's some other reason why the working-directory is not applied to it

@ggrossetie
Copy link
Member

For some reason this action is not run in the working directory or there's some other reason why the working-directory is not applied to it

It sounds like a bug/limitation of GitHub Actions.

In my opinion, actions should not have to explicitly set the working directory, so the code seems correct: fs.readFile(inputPath, { encoding: 'utf8' }). Does it work if you explicitly define the working-directory on the step?

- name: Annotate SQL linting errors
  uses: yuzutech/[email protected]
  with:
    repo-token: "${{ secrets.GITHUB_TOKEN }}"
    title: lint
    input: './annotations.json'
  working-directory: 'some/path'

You should open a support ticket at: https://support.github.com/features/actions

@ggrossetie ggrossetie added 🙃 upstream and removed ❔ question Further information is requested labels Feb 16, 2022
@stumelius
Copy link
Author

It looks like jobs with uses don't support the working-directory argument. I got an error from the Github actions validator but didn't find much from quick googling. Just this https://github.community/t/use-working-directory-for-entire-job/16747/4

@orestesgaolin
Copy link

I think that it also doesn't take into account that annotations paths can be nested relative to working directory as well.

Consider following workflow

name: example_app

on:
  pull_request:
    paths:
      - ".github/workflows/example_app.yaml"
      - "example/lib/**"

jobs:
  build:
    defaults:
      run:
        working-directory: ./example

    runs-on: ubuntu-latest

    steps:
      - name: 📚 Git Checkout
        uses: actions/checkout@v3
...
      - name: 🧪 Evaluate
        run: generate_annotations > ./annotations.json

      - name: 🕵️ Debug
        run: cat ./annotations.json

      - name: Annotate
        uses: yuzutech/[email protected]
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          title: "lint"
          ignore-missing-file: false
          input: "./example/annotations.json"

The output can be:

[
    {
        "path": "lib/main_development.dart",
        "start_line": 9,
        "end_line": 9,
        "annotation_level": "notice",
        "message": "My message"
    }
]

So the real path would be example/lib/main_development.dart.

I wonder what is valid and what would be expected by users:

  • the annotations should always be generated with full paths, not relative to a working directory
  • the annotations should be generated with paths relative to working directory, and the annotations-action should take that into account while calling GH apis

@ggrossetie
Copy link
Member

the annotations should always be generated with full paths, not relative to a working directory

I think that's the safer approach.

the annotations should be generated with paths relative to working directory, and the annotations-action should take that into account while calling GH apis

Not sure if the GitHub Action has access to the working-directory configuration...

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

No branches or pull requests

3 participants