Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add hack/verify-markdown-links.sh script #3405

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGELOG/0.x-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ The following changes have been made since v0.3.0:
GEP added in [#749](https://github.com/kubernetes-sigs/gateway-api/pull/749).
Implemented in [#768](https://github.com/kubernetes-sigs/gateway-api/pull/768).

[GEP-851](https://github.com/kubernetes-sigs/gateway-api/blob/main/geps/gep-851.md)
[GEP-851](https://gateway-api.sigs.k8s.io/geps/gep-820/)
was a follow up on this change that allowed multiple Certificate Refs per
Gateway Listener. This was implemented in
[#852](https://github.com/kubernetes-sigs/gateway-api/pull/852).
Expand All @@ -1553,7 +1553,7 @@ The following changes have been made since v0.3.0:
### Small Changes
* Extension points within match blocks from all Routes have been removed
[#829](https://github.com/kubernetes-sigs/gateway-api/pull/829). Implements
[GEP-820](https://github.com/kubernetes-sigs/gateway-api/blob/main/geps/gep-820.md).
[GEP-820](https://gateway-api.sigs.k8s.io/geps/gep-820/).
These extension points have been removed because they are currently not used,
are poorly understood, and we don't have good use cases for them. We may
consider re-adding them in the future.
Expand Down Expand Up @@ -1700,11 +1700,11 @@ The following changes have been made since v0.4.0-rc1:
### GEP implementations
* Replace `CertificateRef` field with `CertificateRefs` in `GatewayTLSConfig`.
[#852](https://github.com/kubernetes-sigs/gateway-api/pull/852). This implements
[GEP-851](https://github.com/kubernetes-sigs/gateway-api/blob/main/geps/gep-851.md),
[GEP-851](https://gateway-api.sigs.k8s.io/geps/gep-851/),
Allow Multiple Certificate Refs per Gateway Listener.
* Extension points within match blocks from all Routes have been removed
[#829](https://github.com/kubernetes-sigs/gateway-api/pull/829). Implements
[GEP-820](https://github.com/kubernetes-sigs/gateway-api/blob/main/geps/gep-820.md).
[GEP-820](https://gateway-api.sigs.k8s.io/geps/gep-820/).
These extension points have been removed because they are currently not used,
are poorly understood, and we don't have good use cases for them. We may
consider re-adding them in the future.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
golang.org/x/sync v0.10.0
google.golang.org/grpc v1.69.2
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1
google.golang.org/protobuf v1.36.0
google.golang.org/protobuf v1.36.1
k8s.io/api v0.31.3
k8s.io/apiextensions-apiserver v0.31.3
k8s.io/apimachinery v0.31.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
110 changes: 110 additions & 0 deletions hack/verify-markdown-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

log_error() {
echo "ERROR: $*" 1>&2
}

log_info() {
echo "INFO: $*" 1>&2
}

extract_external_links() {
local file_path="$1"
local -n links_array=$2 # Use nameref to pass array by reference

# Check if the file exists and is readable
if [[ -f "$file_path" && -r "$file_path" ]]; then
# Read the content of the file
local content=$(<"$file_path")
# Use grep with a refined regex pattern to extract links
while IFS= read -r link; do
# Trim trailing characters like ']', ')' or '"'
link=$(echo "$link" | sed -E 's/[]")\]]+$//')
links_array+=("$link")
done < <(echo "$content" | grep -oP 'https?://[^\s")\]]+')
else
log_error "File does not exist or is not readable: $file_path"
return 1
fi
}


validate_url() {
local url="$1"
local http_status=$(curl -o /dev/null -s -w "%{http_code}\n" "$url")
local excluded_domains=("foo.ns.service.cluster.local")
excluded_domains+=("redirect.example")
excluded_domains+=("rewrite.example")
excluded_domains+=("elsewhere.example")
# Check if the URL contains any of the excluded domains
for excluded_domain in "${excluded_domains[@]}"; do
if [[ "$url" == *"$excluded_domain"* ]]; then
log_info "Skipping excluded URL: $url"
return 0
fi
done

# Check if the status code indicates success (200-399)
if [[ "$http_status" -ge 200 && "$http_status" -lt 400 || "$http_status" == "000" ]]; then
log_info "Success: $url returned status code $http_status"
return 0
else
log_error "Error: $url returned status code $http_status"
return 1
fi
}

# Check for broken links in markdown files within a specified directory
check_broken_links_in_directory() {
local directory=$1
local exit_code=0

# Find all .md files in the specified directory and its subdirectories
for markdown_file in $(find "$directory" -type f -name "*.md"); do
log_info "Checking $markdown_file for broken links"

declare -a links
extract_external_links "$markdown_file" links

for link in "${links[@]}"; do
validate_url "$link"
result=$?
if [[ $result -eq 1 ]]; then
exit_code=1
fi
done
done

return $exit_code
}

ROOT_DIR=$(dirname "${BASH_SOURCE[0]}")/..

if [[ ! -d "$ROOT_DIR" ]]; then
log_error "The specified directory $ROOT_DIR does not exist"
exit 1
fi

# Check for broken links in markdown files
check_broken_links_in_directory "$ROOT_DIR"
exit_code=$?

exit $exit_code
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mkdocs-redirects==1.2.2
mkdocs-mermaid2-plugin==1.2.1
pandas>=2.0.3
pep562==1.1
Pygments==2.18.0
Pygments==2.19.0
pymdown-extensions==10.12
PyYAML==6.0.2
six==1.17.0
Expand Down
4 changes: 2 additions & 2 deletions site-src/implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@ If you have any suggestions or experience issues with NGINX Gateway Fabric, plea

You can read our [docs][ngrok-k8s-gwapi-docs] for more information. If you have any feature requests or bug reports, please [create an issue][ngrok-issue-new]. You can also reach out for help on [Slack][ngrok-slack]

[ngrok-k8s-operator]:https://github.com/ngrok/kubernetes-ingress-controller
[ngrok-k8s-operator]:https://github.com/ngrok/ngrok-operator
[ngrok]:https://ngrok.com
[ngrok-k8s-gwapi-docs]:https://ngrok.com/docs/k8s/
[ngrok-issue-new]: https://github.com/ngrok/kubernetes-ingress-controller/issues/new
[ngrok-issue-new]: https://github.com/ngrok/ngrok-operator/issues/new/choose
[ngrok-slack]:https://ngrokcommunity.slack.com/channels/general

### STUNner
Expand Down