network-monitor/.github/workflows/lint.yaml
2021-07-07 14:33:58 +02:00

67 lines
2.2 KiB
YAML

name: Lint
on:
push:
branches:
- master
pull_request:
env:
PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
jobs:
lint:
name: Linting check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Python is required for pip installation of pre-commit
- name: Python setup
id: python
uses: actions/setup-python@v2
with:
python-version: '3.9.5'
# Install pre-commit with pip
- name: Install pre-commit
run: pip install pre-commit
# Cache pre-commit environment
# the key consists relevant factors to allow updating, when pre-commit changes
- name: Pre-commit Environment Caching
uses: actions/cache@v2
with:
path: ${{ env.PRE_COMMIT_HOME }}
key: "precommit-0-${{ runner.os }}-${{ env.PRE_COMMIT_HOME }}-\
${{ steps.python.outputs.python-version }}-\
${{ hashFiles('./.pre-commit-config.yaml') }}"
# Make a user install for pre-commit by using PIP_USER=0
- name: Run pre-commit hooks
run: export PIP_USER=0; pre-commit run --all-files
# Prepare the Pull Request Payload artifact. If this fails, we
# we fail silently using the `continue-on-error` option. It's
# nice if this succeeds, but if it fails for any reason, it
# does not mean that our lint-test checks failed.
- name: Prepare Pull Request Payload artifact
id: prepare-artifact
if: always() && github.event_name == 'pull_request'
continue-on-error: true
run: cat $GITHUB_EVENT_PATH | jq '.pull_request' > pull_request_payload.json
# This only makes sense if the previous step succeeded. To
# get the original outcome of the previous step before the
# `continue-on-error` conclusion is applied, we use the
# `.outcome` value. This step also fails silently.
- name: Upload a Build Artifact
if: always() && steps.prepare-artifact.outcome == 'success'
continue-on-error: true
uses: actions/upload-artifact@v2
with:
name: pull-request-payload
path: pull_request_payload.json