Skip to content

Commit ce97c45

Browse files
authored
Merge pull request #2148 from Chessing234/ci/sqlfluff-annotate-permissions
ci: fix SQLFluff annotation permissions for fork PRs
2 parents 3a914fc + d83dbaf commit ce97c45

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎.github/workflows/lint_sqlfluff.yml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
name: SQLFluff
22

3+
# Lints changed mimic-iv/concepts/*.sql on pull requests and posts GitHub
4+
# annotations. Fork PRs skip Annotate — GITHUB_TOKEN cannot create check runs
5+
# from forks (Resource not accessible by integration / 403).
36
on:
47
- pull_request
58

69
jobs:
710
lint-mimic-iv:
811
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
checks: write
915
steps:
1016
- name: checkout
1117
uses: actions/checkout@v7
@@ -35,8 +41,14 @@ jobs:
3541
shell: bash
3642
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
3743
- name: Annotate
44+
# Same-repo PRs only: fork tokens get 403 creating check runs, and
45+
# ignore-unauthorized-error does not treat that as unauthorized.
46+
if: >
47+
steps.get_files_to_lint.outputs.lintees != '' &&
48+
github.event.pull_request.head.repo.full_name == github.repository
3849
uses: yuzutech/annotations-action@v0.6.0
3950
with:
4051
repo-token: "${{ secrets.GITHUB_TOKEN }}"
4152
title: "SQLFluff Lint"
42-
input: "./annotations.json"
53+
input: "./annotations.json"
54+
ignore-unauthorized-error: true
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
# Local mirror of .github/workflows/lint_sqlfluff.yml for changed concept SQL.
3+
set -euo pipefail
4+
BASE_REF="${1:-origin/main}"
5+
files="$(git diff --name-only --diff-filter=AM "${BASE_REF}...HEAD" -- 'mimic-iv/concepts/' \
6+
| grep -E '[.]sql$' || true)"
7+
if [[ -z "${files}" ]]; then
8+
echo "No changed mimic-iv/concepts SQL files versus ${BASE_REF}."
9+
exit 0
10+
fi
11+
# shellcheck disable=SC2086
12+
sqlfluff lint ${files}

‎styleguide.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ For more detail, following the guidelines at: http://www.sqlstyle.guide/
2727
## Python
2828

2929
Following PEP8 guidelines is recommended. Read more here: https://www.python.org/dev/peps/pep-0008/
30+
31+
## SQL style checking
32+
33+
Pull requests that change `mimic-iv/concepts/**/*.sql` are linted by the SQLFluff GitHub Action (`.github/workflows/lint_sqlfluff.yml`). Findings are posted as pull-request annotations when the workflow has permission to write checks.

0 commit comments

Comments
 (0)