check-links #61
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: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 0 * * 1' | |
permissions: | |
issues: write | |
jobs: | |
check-links: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Prepare Yarn | |
uses: ./.github/actions/prepare/ | |
- name: Build CLI | |
run: yarn build:cli | |
- name: Check Links | |
id: check-links | |
# Run link checker and save outputs to files. https://stackoverflow.com/a/692407 | |
run: | | |
yarn lint:links > >(tee -a stdout.txt) 2> >(tee -a stderr.txt >&2) | |
- name: Create issue | |
uses: actions/[email protected] | |
if: always() && steps.check-links.outcome == 'failure' | |
with: | |
script: | | |
const title: 'Fix broken links'; | |
const previousIssues = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
creator: context.actor, | |
}); | |
const previousIssueExists = previousIssues.some((issue) => { | |
issue.title === title; | |
}) | |
if !previousIssueExists { | |
const fs = require('fs'); | |
const input = fs.readFileSync('stderr.txt'); | |
const data = JSON.parse(input); | |
const urls = data.map(item => item.url); | |
const output = urls.map(url => `- [ ] ${url}`).join('\n'); | |
await github.rest.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title, | |
body: `The following links are possibly broken:\n${output}`, | |
}); | |
} |