Search code examples
githubshgithub-actions

Permission denied error in github actions


I have written a github action to retrieve the changed sql files and lint those changed files using sqlfluff.

Here is my github action code:

name: files_lint

on:
  - pull_request

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: Install Python
        uses: "actions/setup-python@v2"
        with:
          python-version: "3.7"
      - name: install sqlfluff
        run: "pip install sqlfluff"

      - name: Get changed .sql files
        id: linting
        run: some code to get the changed files

      - name: Linting files started
        id: sql_linting
        if: steps.linting.outputs.lintees != ''
        shell: bash -l {0}
        run: ${{ steps.linting.outputs.lintees }} > sqlfluff fix --force

But when I run ${{ steps.linting.outputs.lintees }} > sqlfluff fix --force on the changed sql files in the above github action, I'm getting an error

/home/runner/work/_temp/a41i1c89a4.sh: line 1: test.sql: Permission denied
Error: Process completed with exit code 126.

Solution

  • You can’t redirect files like this:

    
    run: ${{ steps.linting.outputs.lintees }} > sqlfluff fix --force
    

    This is attempting to write the output of whatever that command is - but I’d guess it’s a list of files rather than a command?

    You should pass as parameters (assuming it’s a list of files):

    
    run: sqlfluff fix --force ${{ steps.linting.outputs.lintees }}
    

    Also I presume you’re going to do something with it afterwards? If not the fixed files will not do anything. If you just want to check the files sqlfluff lint would be better than sqlfluff fix (and catches more issues as sqlfluff fix only looks at rules it can fix).