1

I am getting this error while trying to set a github actions. My goal is to set up a github actions that uses another template for linting and fixing SQL. Here is my github folder.github folder structure The models folder contains a single sql file (with .sql file extention). The content of the sql folder is an sql file testing.sql with the query: select a,b,c, document as doc from table.

The workflow file contains the following yml file:

on:
  pull_request:
jobs:
  test-check:
    name: runner / sqlfluff (github-check)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: yu-iskw/action-sqlfluff@v3
        id: lint-sql
        with:
          github_token: ${{ secrets.github_token }}
          reporter: github-pr-review
          sqlfluff_version: "1.2.0"
          sqlfluff_command: "fix" # Or "lint"
          config: "${{ github.workspace }}/.sqlfluff"
          paths: '${{ github.workspace }}/models'
      - name: 'Show outputs (Optional)'
        shell: bash
        run: |
          echo '${{ steps.lint-sql.outputs.sqlfluff-results }}' | jq -r '.'
          echo '${{ steps.lint-sql.outputs.sqlfluff-results-rdjson }}' | jq -r '.'

The .sqlfluff file contains a default configuration from the following site: sqlfulff.

The workflow run is throwing the following error which I couldn't quite figure out: output error

I don't know what the line 15: GITHUB_PULL_REQUEST_BASE_REF: parameter null or not set means in the error. I would be glad if anyone can help with the error.

G1124E
  • 407
  • 1
  • 10
  • 20

1 Answers1

3

It is a parameter used by yu-iskw/action-sqlfluff action.yml in its entrypoint.sh.

SQL_FILE_PATTERN="${FILE_PATTERN:?}"
SOURCE_REFERENCE="origin/${GITHUB_PULL_REQUEST_BASE_REF:?}"
changed_files=$(git diff --name-only --no-color "$SOURCE_REFERENCE" "HEAD" -- "${SQLFLUFF_PATHS:?}" |
  grep -e "${SQL_FILE_PATTERN:?}" |
  xargs -I% bash -c 'if [[ -f "%" ]] ; then echo "%"; fi' || :)

Set it to the remote branch parameter github_base_ref you want to compare to (main for instance).

In your case:

on:
  pull_request:
jobs:
  test-check:
    name: runner / sqlfluff (github-check)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: yu-iskw/action-sqlfluff@v3
        id: lint-sql
        with:
          github_token: ${{ secrets.github_token }}
          reporter: github-pr-review
          sqlfluff_version: "1.2.0"
          sqlfluff_command: "fix" # Or "lint"
          config: "${{ github.workspace }}/.sqlfluff"
          paths: '${{ github.workspace }}/models'
          github_base_ref: "main"     <========================
      - name: 'Show outputs (Optional)'
        shell: bash
        run: |
          echo '${{ steps.lint-sql.outputs.sqlfluff-results }}' | jq -r '.'
          echo '${{ steps.lint-sql.outputs.sqlfluff-results-rdjson }}' | jq -r '.'

(Do not include the <======... part, only the github_base_ref: "main")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC. I just updated the question to include the action yml file. I am not sure where to include the your answer in the action file. Isn't it set to `main` by default? Do I have to set it as: ``` on: pull_request: branches: - main ``` in the yml file? – G1124E Jul 18 '22 at 04:40
  • @G1124E Add `github_base_ref` set to `main` in your parameters, for testing. – VonC Jul 18 '22 at 04:43
  • I am just learning github actions by following the example in for a project I'm working where I need to create to push sql files . I spent quite some time trying to figure this out. Not quite sure where in my file structure I should set the github_base_ref. I added your answer to the yml file under the `run` however, it failed. I was wondering if you can elaborate on where/how in the yml file I can set gthub_base_ref? – G1124E Jul 18 '22 at 05:23
  • @G1124E I have edited the answer to show how to include that parameter. – VonC Jul 18 '22 at 06:27
  • @G1124E Great! Well done. – VonC Jul 20 '22 at 05:35