Check links on Academy #566
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- 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@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # 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@c33737706dea87cd7784c687dadc9adf1be59990 # v2.3.2 | |
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 }} |