Check links on Academy #20
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
name: Check links on Academy | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
push: | |
branches: | |
- "jamon-chainlink" | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./tools/chainlink | |
jobs: | |
check-links: | |
runs-on: ubuntu-latest | |
if: github.repository == 'chainguard-dev/edu' | |
permissions: | |
issues: write # opens issues when bad links are found | |
steps: | |
- name: 'Github Actions Runner' | |
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | |
with: | |
egress-policy: audit | |
- name: 'Checkout default branch to $GITHUB_WORKSPACE dir' | |
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 | |
- name: Install jq | |
run: | | |
sudo apt update | |
sudo apt install -y jq | |
- name: Install yq | |
run: | | |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 | |
sudo chmod +x /usr/local/bin/yq | |
- name: Set up Go | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # actions/setup-go@v4 | |
with: | |
go-version: '^1.20.0' | |
- name: Run chainlink | |
run: go run . -contentDir ../../content -hostname edu.chainguard.dev -method GET -checkAll | |
- name: Find unchecked links | |
run: | | |
jq -r '.unchecked []?| {"url":.rawurl, "files":(.files |keys)}' results.json |\ | |
jq -s |\ | |
yq -P > unchecked.json | |
- name: Find 404 links | |
run: | | |
jq '.checked []?| select(.status == 404) | {"url":.rawurl, "files":(.files |keys)}' results.json |\ | |
jq -s |\ | |
yq -P > checked.json | |
- name: Create issue body | |
run: | | |
printf '## Unchecked URLs:\n```\n' > issue-body.txt | |
cat unchecked.json >> issue-body.txt | |
printf '```\n\n## 404 URLs\n```\n' >> issue-body.txt | |
cat checked.json >> issue-body.txt | |
printf '```\n\n' >> issue-body.txt | |
printf '## Notes\nAdd any of the unchecked or 404 URLs to `ignore.json` as required' >> issue-body.txt | |
- name: Create/Update GitHub Issue | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
existing=$(gh issue list --json number,title |\ | |
jq -r '.[] | select(.title == "[chainlink] check links on edu.chainguard.dev") | .number') | |
if [ -z "${existing}" ]; then | |
gh issue create \ | |
--title "[chainlink] check links on edu.chainguard.dev" \ | |
--assignee jamonation \ | |
--label automated \ | |
--body-file issue-body.txt | |
else | |
gh issue edit $existing --body-file issue-body.txt | |
fi | |
- name: Post failure notice to Slack | |
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 # v2.3.0 | |
if: ${{ failure() }} | |
env: | |
SLACK_ICON: http://github.com/chainguard-dev.png?size=48 | |
SLACK_USERNAME: guardian | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_CHANNEL: 'alerts-edu' | |
SLACK_COLOR: '#8E1600' | |
MSG_MINIMAL: 'true' | |
SLACK_TITLE: 'Check Links failed - ${{ github.repository }}' | |
SLACK_MESSAGE: | | |
For detailed logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} |