mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 18:42:30 +03:00
a7dbe95666
So far we've only used `hlint` to lint the OSS code. This moves some things around to lint the Pro code as well. Note that the CI action only runs `hlint` on Haskell files that are _changed_ by a PR, relative to its merge-base (usually `main`). As a reminder, you can use the `ignore-server-hlint-checks` label to prevent this from blocking a merge. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3383 GitOrigin-RevId: d5779c63d780f526a1d58ae4107f0d5262a23ec1
43 lines
2.0 KiB
YAML
43 lines
2.0 KiB
YAML
name: server lint
|
|
on:
|
|
label:
|
|
pull_request:
|
|
paths:
|
|
- 'server/**'
|
|
|
|
jobs:
|
|
hlint:
|
|
runs-on: ubuntu-20.04
|
|
if: "!contains(github.event.pull_request.labels.*.name, 'ignore-server-hlint-checks') && github.event.label.name != 'ignore-server-hlint-checks'"
|
|
env:
|
|
working-directory: .
|
|
HLINT_BASE_URL: https://dl.haskellworks.io/binaries/hlint
|
|
HLINT_VERSION: 3.1.6
|
|
HLINT_ARCH: x86_64
|
|
HLINT_OS: linux
|
|
HLINT_URL: $HLINT_BASE_URL/hlint-${HLINT_VERSION}-${HLINT_ARCH}-${HLINT_OS}.tar.gz
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Download hlint
|
|
working-directory: ${{env.working-directory}}
|
|
run: |
|
|
echo "Downloading from ${{env.HLINT_URL}}"
|
|
curl "${{env.HLINT_URL}}" -o "./hlint-${{env.HLINT_VERSION}}-${{env.HLINT_ARCH}}-${{env.HLINT_OS}}.tar.gz"
|
|
tar -zxvf "./hlint-${{env.HLINT_VERSION}}-${{env.HLINT_ARCH}}-${{env.HLINT_OS}}.tar.gz" -C "."
|
|
|
|
- name: Run hlint
|
|
shell: bash
|
|
run: |
|
|
CHANGED_HS_FILES=$(git diff --name-only origin/${{github.base_ref}}...${{github.sha}} -- "${{env.working-directory}}/server/*.hs" | xargs -i -d '\n' sh -c 'ls -d {} 2>/dev/null || true')
|
|
echo "$CHANGED_HS_FILES"
|
|
JQ_SCRIPT='.[] | "::" + (if (.severity=="Warning" or .severity=="Error") then "error" else "warning" end) + " file=\(.file),line=\(.startLine),col=\(.startColumn)::\(.severity):" + " \(.hint)%0AFound:%0A \(.from | gsub("\n";"%0A "))%0A" + try ("Perhaps:%0A " + (.to | gsub("\n";"%0A ")) + "%0A") catch "" + try (if .note | length > 0 then "Note:%0A " + (.note | join("\n") | gsub("\n";"%0A ")) else "" end) catch ""'
|
|
if [[ "$CHANGED_HS_FILES" ]]
|
|
then
|
|
OUT=$(mktemp)
|
|
echo "$CHANGED_HS_FILES" | xargs ${{env.working-directory}}/hlint --no-exit-code --json --hint=${{env.working-directory}}/.hlint.yaml | jq -r "$JQ_SCRIPT" | tee $OUT
|
|
test -z "$(grep -E '^::error' $OUT)"
|
|
fi
|