Skip to content

Commit

Permalink
feat: remove replace circleci cron with github action
Browse files Browse the repository at this point in the history
this github action should open a PR removing broken links automatically
  • Loading branch information
SgtPooki committed Sep 15, 2022
1 parent 839bd82 commit 15a552a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 36 deletions.
36 changes: 0 additions & 36 deletions .circleci/config.yml

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/broken_link_cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Open a PR to remove broken links on a schedule

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
check-for-broken-links:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 13

- uses: ipfs/aegir/actions/cache-node-modules@master
with:
directories: |
README.md
build: |
npm run build:readme
cache_name: readme

- name: Set up Ruby 3.1.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2

- name: Install and run awesome_bot
run: |
gem install awesome_bot
awesome_bot --allow 429 --allow-redirect --allow-dupe --allow-ssl -w ipfs.io README.md || echo
- name: Remove broken links
run: |
node scripts/remove-broken-links.js
- uses: stefanzweifel/git-auto-commit-action@49620cd3ed21ee620a48530e81dba0d139c9cb80
with:
# Optional. Commit message for the created commit.
# Defaults to "Apply automatic changes"
commit_message: "chore: Remove broken links"

# Optional. Local and remote branch name where commit is going to be pushed
# to. Defaults to the current branch.
# You might need to set `create_branch: true` if the branch does not exist.
branch: remove-broken-links-${{ github.run_id }}

commit_options: '--no-verify --signoff'

# Optional glob pattern of files which should be added to the commit
# Defaults to all (.)
# See the `pathspec`-documentation for git
# - https://git-scm.com/docs/git-add#Documentation/git-add.txt-ltpathspecgt82308203
# - https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
file_pattern: data/*
repository: .
add_options: '-A'
push_options: '--force'
skip_dirty_check: true
skip_fetch: true
skip_checkout: true
disable_globbing: true
create_branch: true

- name: pull-request
uses: repo-sync/pull-request@65785d95a5a466e46a9d0708933a3bd51bbf9dde
with:
source_branch: "remove-broken-links-${{ github.run_id }}"
destination_branch: "master"
pr_title: "chore: Remove broken links"
pr_body: "Automated PR created by .github/workflows/broken_link_cron.yml"
pr_label: "kind/maintenance"
pr_draft: false
pr_allow_empty: false
github_token: ${{ secrets.GITHUB_TOKEN }}
28 changes: 28 additions & 0 deletions scripts/remove-broken-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* This file assumes that awesome_bot has already been ran.
*/
const markdownTable = require('../ab-results-README.md-markdown-table.json')
const fs = require('fs').promises
const { join } = require('path')

const dir = join(__dirname, '../data')

if (markdownTable.error) {
const brokenLinks = require('../ab-results-README.md-filtered.json').map((resultsData) => resultsData.link);
(async () => {
const files = (await fs.readdir(dir)).map(file => join(dir, file))

for await (const filePath of files) {
let fileContents = await fs.readFile(filePath, 'utf8')
brokenLinks.forEach((brokenLink) => {
console.log('Searching for "' + brokenLink + '" in ' + filePath)
const regex = new RegExp(brokenLink, 'g')
if (fileContents.match(regex)) {
fileContents = fileContents.replace(regex, '')
console.log('Removed "' + brokenLink + '" from ' + filePath)
}
})
await fs.writeFile(filePath, fileContents, 'utf8')
}
})()
}

0 comments on commit 15a552a

Please sign in to comment.