2020-10-16 14:55:18 +03:00
|
|
|
name: server lint
|
|
|
|
on:
|
2020-12-07 15:09:39 +03:00
|
|
|
label:
|
2020-10-16 14:55:18 +03:00
|
|
|
pull_request:
|
|
|
|
paths:
|
2022-07-22 15:22:35 +03:00
|
|
|
- "server/**"
|
2020-10-16 14:55:18 +03:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
hlint:
|
|
|
|
runs-on: ubuntu-20.04
|
2020-12-07 15:09:39 +03:00
|
|
|
if: "!contains(github.event.pull_request.labels.*.name, 'ignore-server-hlint-checks') && github.event.label.name != 'ignore-server-hlint-checks'"
|
2020-10-16 14:55:18 +03:00
|
|
|
env:
|
2022-01-18 07:05:12 +03:00
|
|
|
working-directory: .
|
2022-07-22 15:22:35 +03:00
|
|
|
HLINT_BASE_URL: https://github.com/ndmitchell/hlint/releases/download
|
2020-10-16 14:55:18 +03:00
|
|
|
HLINT_ARCH: x86_64
|
|
|
|
HLINT_OS: linux
|
2022-07-22 15:22:35 +03:00
|
|
|
|
2020-10-16 14:55:18 +03:00
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
|
|
|
|
|
|
|
- name: Download hlint
|
|
|
|
run: |
|
2022-07-22 15:22:35 +03:00
|
|
|
HLINT_VERSION="$(jq -r '.hlint' ./server/VERSIONS.json)"
|
|
|
|
HLINT_URL="${{env.HLINT_BASE_URL}}/v${HLINT_VERSION}/hlint-${HLINT_VERSION}-${{env.HLINT_ARCH}}-${{env.HLINT_OS}}.tar.gz"
|
|
|
|
echo "Downloading from ${HLINT_URL}"
|
|
|
|
curl --fail --location --output "./hlint.tar.gz" "${HLINT_URL}"
|
|
|
|
tar xvf \
|
|
|
|
hlint.tar.gz \
|
|
|
|
--directory='.' \
|
|
|
|
--strip-components=1 \
|
|
|
|
"hlint-${HLINT_VERSION}/hlint"
|
2020-10-16 14:55:18 +03:00
|
|
|
|
|
|
|
- name: Run hlint
|
|
|
|
shell: bash
|
2020-10-28 18:41:04 +03:00
|
|
|
run: |
|
2022-07-22 15:22:35 +03:00
|
|
|
CHANGED_HS_FILES=$(git diff --name-only origin/${{github.base_ref}}...${{github.sha}} -- "./*.hs" | xargs -i -d '\n' sh -c 'ls -d {} 2>/dev/null || true')
|
2020-10-28 18:41:04 +03:00
|
|
|
echo "$CHANGED_HS_FILES"
|
2021-05-05 00:51:57 +03:00
|
|
|
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 ""'
|
2020-10-28 18:41:04 +03:00
|
|
|
if [[ "$CHANGED_HS_FILES" ]]
|
|
|
|
then
|
2021-01-20 20:49:58 +03:00
|
|
|
OUT=$(mktemp)
|
2022-07-22 15:22:35 +03:00
|
|
|
echo "$CHANGED_HS_FILES" | xargs ${{env.working-directory}}/hlint --no-exit-code --json --hint=./.hlint.yaml | jq -r "$JQ_SCRIPT" | tee $OUT
|
2021-01-20 20:49:58 +03:00
|
|
|
test -z "$(grep -E '^::error' $OUT)"
|
2020-10-28 18:41:04 +03:00
|
|
|
fi
|