diff --git a/.github/actions/lint-jsonschema/action.yml b/.github/actions/lint-jsonschema/action.yml index ea6c3eaa..22aa6698 100644 --- a/.github/actions/lint-jsonschema/action.yml +++ b/.github/actions/lint-jsonschema/action.yml @@ -50,63 +50,3 @@ runs: done < <(find "$EXAMPLES_ROOT" -name "*.json") exit $rc - - - name: Verify links - shell: bash - run: | - function warn { - >&2 echo -e "\033[0;33m$@\033[0m" - } - - function err { - >&2 echo -e "\033[0;31m$@\033[0m" - } - - rc=0 - - while read -r file; do - echo "Checking $file" - - pushd "$(dirname "$file")" > /dev/null - - while read -r location; do - echo "Checking location $location" - - if [[ "$location" == http* ]]; then - if ! curl -X OPTIONS --silent --fail "$location" 2>&1 > /dev/null; then - if ! curl --head --silent --fail "$location" 2>&1 > /dev/null; then - if ! curl --silent --fail "$location" 2>&1 > /dev/null; then - # Some URLs are examples or the endpoints helpfully support neither OPTIONS nor HEAD - if [[ "$location" = *example* ]] || \ - [[ "$location" = https://idp-ref.app.ti-dienste.de/auth* ]] || \ - [[ "$location" = https://idp.app.ti-dienste.de/auth* ]] || \ - [[ "$location" = https://idp-ref.app.ti-dienste.de/token* ]] || \ - [[ "$location" = https://idp.app.ti-dienste.de/token* ]] || \ - [[ "$location" = https://idp-ref.app.ti-dienste.de ]]; - then - warn "$file references non-verifiable location $location" - else - err "$file references non-existent location $location" - rc=1 - fi - fi - fi - fi - else - # Strip fragments and prefix absolute paths with repo root - path=${location/\#*/} - if [[ "$path" == /* ]]; then - path=$(git rev-parse --show-toplevel)/$path - fi - - if [[ ! -e "$path" ]]; then - err "$file references non-existent location $location" - rc=1 - fi - fi - done < <(grep -hoE 'link:[^\[]*|image::?[^\[]*|https?://[^\["[:space:]]*' "$(basename "$file")" | grep -v '^image:' | sed -E "s/^link:+//g") - - popd > /dev/null - done < <(find . -type f -name "*.adoc") - - exit $rc diff --git a/.github/actions/lint-links/action.yml b/.github/actions/lint-links/action.yml new file mode 100644 index 00000000..a57b2930 --- /dev/null +++ b/.github/actions/lint-links/action.yml @@ -0,0 +1,64 @@ +name: Lint Links + +runs: + using: "composite" + steps: + - name: Verify links + shell: bash + run: | + function warn { + >&2 echo -e "\033[0;33m$@\033[0m" + } + + function err { + >&2 echo -e "\033[0;31m$@\033[0m" + } + + rc=0 + + while read -r file; do + echo "Checking $file" + + pushd "$(dirname "$file")" > /dev/null + + while read -r location; do + echo "Checking location $location" + + if [[ "$location" == http* ]]; then + if ! curl -X OPTIONS --silent --fail "$location" 2>&1 > /dev/null; then + if ! curl --head --silent --fail "$location" 2>&1 > /dev/null; then + if ! curl --silent --fail "$location" 2>&1 > /dev/null; then + # Some URLs are examples or the endpoints helpfully support neither OPTIONS nor HEAD + if [[ "$location" = *example* ]] || \ + [[ "$location" = https://idp-ref.app.ti-dienste.de/auth* ]] || \ + [[ "$location" = https://idp.app.ti-dienste.de/auth* ]] || \ + [[ "$location" = https://idp-ref.app.ti-dienste.de/token* ]] || \ + [[ "$location" = https://idp.app.ti-dienste.de/token* ]] || \ + [[ "$location" = https://idp-ref.app.ti-dienste.de ]]; + then + warn "$file references non-verifiable location $location" + else + err "$file references non-existent location $location" + rc=1 + fi + fi + fi + fi + else + # Strip fragments and prefix absolute paths with repo root + path=${location/\#*/} + if [[ "$path" == /* ]]; then + path=$(git rev-parse --show-toplevel)/$path + fi + + if [[ ! -e "$path" ]]; then + err "$file references non-existent location $location" + rc=1 + fi + fi + done < <(grep -hoE 'link:[^\[]*|image::?[^\[]*|https?://[^\["[:space:]]*' "$(basename "$file")" | grep -v '^image:' | sed -E "s/^link:+//g") + + popd > /dev/null + done < <(find . -type f -name "*.adoc") + + exit $rc diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5187e729..9cf05214 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,7 +9,7 @@ on: workflow_dispatch: jobs: - asciidoc: + asciidoc-images: runs-on: ubuntu-latest steps: @@ -19,6 +19,16 @@ jobs: - name: Lint uses: gematik/github-image-actions/.github/actions/lint-asciidoc@0.1.0 + asciidoc-links: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Lint + uses: ./.github/actions/lint-links + drawio: runs-on: ubuntu-latest