Last active
September 30, 2020 22:46
-
-
Save woodburndesigns/8733d4d93eab4a62ad2a31ad2e493486 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
websiteURL: | |
description: "The website you'd like to crawl for broken links" | |
slack-channel: | |
default: "prog-relay-testing" | |
triggers: | |
- name: scheduled trigger | |
source: | |
type: schedule | |
schedule: '0 16 * * *' # This runs in UTC so adding 7 hours for better timing in PST | |
steps: | |
- name: link-checker | |
image: projectnebula/core | |
input: | |
- "#!/bin/bash" | |
- apk add --update nodejs npm jq | |
- npm install -g linkinator | |
- URL="$(ni get -p '{.websiteURL}')" | |
- echo "${URL}" | |
- LINKS_ARRAY="$(linkinator "${URL}" --recurse --format JSON)" | |
- BAD_LINKS=$( jq '[.links[] | select(.status == 404) | .url]' <<<"${LINKS_ARRAY}" ) | |
- LINKS_COUNT=$( jq 'length' <<<"${BAD_LINKS}" ) | |
- echo "Bad links found ${LINKS_COUNT}" | |
- if [ "$LINKS_COUNT" -eq 0 ] | |
- then | |
- MESSAGE="There are no broken links" | |
- else | |
- LINKS_STR=$(jq -r 'join(", ")' <<<"${BAD_LINKS}") | |
- MESSAGE="The broken links are ${LINKS_STR}" | |
- fi | |
- ni output set --key broken-links --value "${MESSAGE}" | |
spec: | |
websiteURL: !Parameter websiteURL | |
- name: slack-message | |
dependsOn: link-checker | |
image: relaysh/slack-step-message-send | |
spec: | |
channel: !Parameter slack-channel | |
message: !Fn.concat ["The link checker for ", !Parameter websiteURL, " has completed successfully. ", !Output [link-checker, broken-links]] | |
connection: !Connection [slack, slack-connection] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment