From d2fd5893e0c651e7ff210327d3a95639c5bfb263 Mon Sep 17 00:00:00 2001 From: richelbilderbeek Date: Tue, 7 Jan 2025 13:36:01 +0100 Subject: [PATCH] Check for broken links --- .github/workflows/check-links.yaml | 39 ++++++++++++++++++++++++ .github/workflows/valid_json_schema.json | 6 ++++ mlc_config.json | 3 ++ 3 files changed, 48 insertions(+) create mode 100644 .github/workflows/check-links.yaml create mode 100644 .github/workflows/valid_json_schema.json create mode 100644 mlc_config.json diff --git a/.github/workflows/check-links.yaml b/.github/workflows/check-links.yaml new file mode 100644 index 00000000..ac8c271e --- /dev/null +++ b/.github/workflows/check-links.yaml @@ -0,0 +1,39 @@ +# Check that all links are valid, i.e. not broken +name: Check links + +on: + push: + pull_request: + +jobs: + check-links: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + # The link checker will only work if mlc_config.json is a valid JSON + - name: Validate JSON + uses: docker://orrosenblatt/validate-json-action:latest + env: + INPUT_SCHEMA: .github/workflows/valid_json_schema.json + INPUT_JSONS: mlc_config.json + + # These are status code that cannot be ignored. + # + # If there is a valid external link that fails, + # add it to mlc_config.json + - name: External links must be checked, do not allow '0' in the 'aliveStatusCodes' of mlc_config.json + run: if [[ $(grep --regexp "[^0-9]0[^0-9]" mlc_config.json | wc --lines) == "1" ]]; then echo "FOUND"; exit 42; fi + + - name: Internal links must checked, do not allow '400' in the 'aliveStatusCodes' of mlc_config.json + run: if [[ $(grep --regexp "[^0-9]400[^0-9]" mlc_config.json | wc --lines) == "1" ]]; then echo "FOUND"; exit 42; fi + + + - uses: gaurav-nelson/github-action-markdown-link-check@v1 + with: + config-file: 'mlc_config.json' + use-quiet-mode: 'yes' + use-verbose-mode: 'no' + diff --git a/.github/workflows/valid_json_schema.json b/.github/workflows/valid_json_schema.json new file mode 100644 index 00000000..c8216b87 --- /dev/null +++ b/.github/workflows/valid_json_schema.json @@ -0,0 +1,6 @@ +{ + "properties": { + "foo": { "type": "string" }, + "bar": { "type": "number" } + } +} diff --git a/mlc_config.json b/mlc_config.json new file mode 100644 index 00000000..a763ed74 --- /dev/null +++ b/mlc_config.json @@ -0,0 +1,3 @@ +{ + "aliveStatusCodes": [200, 403, 418, 500, 503] +}