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

Check functions catalog site for breakage on repo changes. #250

Merged
merged 22 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "kpt-dev"
}
}
42 changes: 42 additions & 0 deletions .github/workflows/checkSite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2021 Google LLC
#
# 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.

name: CheckSite
on:
pull_request:
paths:
- "functions/**"
- "examples/**"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v2
with:
repository: etefera/href-checker
ref: docsify
path: href-checker
- uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install Site Checker
run: yarn install
working-directory: href-checker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Run Site Checker
run: make site-check
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ site-generate: ## Collect function branches and generate a catalog of their exam
rm -rf ./examples/*/
# GO111MODULE=on go get -v github.com/GoogleContainerTools/kpt@next
(cd scripts/generate_catalog/ && go run . ../.. ../../examples)

site-run: ## Run the site locally.
make site-generate
./scripts/run-site.sh

site-check: ## Test site for broken catalog links.
make site-run
./scripts/check-site.sh
9 changes: 9 additions & 0 deletions examples/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM nginx:1.18.0-alpine
COPY . /usr/share/nginx/html
COPY site_check.conf /etc/nginx/conf.d/configfile.template

ENV PORT 80
ENV HOST 0.0.0.0
EXPOSE 80
RUN sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf"
CMD ["nginx", "-g", "daemon off;"]
7 changes: 7 additions & 0 deletions examples/sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- TODO: Generate this in a build step before deploying. -->
- [Installation](https://kpt.dev/installation/)
- [Book](https://kpt.dev/book/)
- [Reference](https://kpt.dev/reference/)
- [Functions Catalog](/)
- [FAQ](https://kpt.dev/faq/)
- [Contact](https://kpt.dev/contact/)
21 changes: 21 additions & 0 deletions examples/site_check.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
server {
listen $PORT;
server_name localhost;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';

location ~* README.md$ {
root /usr/share/nginx/html;
try_files $uri =404;
}

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}

location ~* sidebar.md$ {
root /usr/share/nginx/html;
index sidebar.md;
}
}
17 changes: 17 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"hosting": {
"site": "kpt-functions-catalog",
"public": "examples",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"href-checker": "etefera/href-checker"
}
}
27 changes: 27 additions & 0 deletions scripts/check-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# 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 pipefail

npm i
cd examples || exit
echo "Starting check."
# Find all potential entrypoint READMEs
# Convert them to valid URLs
# Check each link for Docsify 404s
find . -name README.md -printf "%P\n" | grep -v node_modules | sed "s/README.md//" \
| sed "s/^/http:\/\/localhost:3001\//" \
| xargs -I {} -n1 sh -c "! (npx href-checker {} --bad-content=\"404 - Not found\" --silent --no-off-site -c=15 | grep .) || exit 255"
echo "Success."
4 changes: 2 additions & 2 deletions scripts/generate_catalog/generate_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func copyExamples(b string, funcName string, funcDest string, versionDest string
}

// Copy examples for the function's version to a temporary directory.
tempDir, err := os.MkdirTemp("", "examples")
tempDir, err := ioutil.TempDir("", "examples")
if err != nil {
return err
}
Expand All @@ -202,7 +202,7 @@ func copyExamples(b string, funcName string, funcDest string, versionDest string

func copyReadme(b string, funcName string, relativeFuncPath string, versionDest string) error {
// Copy README for the function's version to the example directory.
tempDir, err := os.MkdirTemp("", "functions")
tempDir, err := ioutil.TempDir("", "functions")
if err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions scripts/run-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright 2019 Google LLC
#
# 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 read/execute permissions for newly created site files in macOS or Linux.
setfacl -Rd -m o::rx examples/ 2> /dev/null || chmod -R +a "everyone allow read,execute,file_inherit,directory_inherit" examples/
# Set read/execute permissions for existing site files.
chmod -R o+rx examples/
# Terminate running kpt-function-catalog docker containers and rebuild.
docker stop "$(docker ps -q --filter ancestor=kpt-function-catalog:latest)" || docker build examples/ -t kpt-function-catalog:latest
# Mount the site directory as the default content for the docker container.
docker run -v "$(pwd)"/examples:/usr/share/nginx/html -p 3001:80 -d kpt-function-catalog:latest
echo "Serving docs at http://127.0.0.1:3001"