add contributors action

adds GitHub Action to update the list of contributors when a new author pushes a change.
This commit is contained in:
Hugh Rundle 2021-01-31 21:22:24 +11:00
parent f37280f651
commit ac2e9022ca
3 changed files with 58 additions and 0 deletions

31
.github/scripts/contributors.js vendored Normal file
View file

@ -0,0 +1,31 @@
const fs = require('fs')
const cheerio = require('cheerio');
const pretty = require('pretty');
const page = fs.readFileSync('./website/sources/index.html', {encoding: 'utf-8' })
var contributors = fs.readFileSync('./contributors.txt', {encoding: 'utf-8' }).split('\n')
const $ = cheerio.load(page)
var eventJson = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, {encoding: 'utf-8' }));
$('#contributors-list').empty() // remove all names to start clean
for (let name of contributors) {
if (name.length > 0) {
for (let commit of eventJson.commits) {
// we only look for authors, not commiters, so we automatically ignore "actions-user"
if ( !contributors.includes(commit.author.name) ) {
contributors.push(commit.author.name)
}
}
$('#contributors-list').append(`<li>${name}</li>\n`)
}
}
// write out new contributors.html file
let newHtml = pretty($.html(), {ocd: true})
fs.writeFileSync('./website/sources/index.html', newHtml, {encoding: 'utf-8'})
// write out contributors.txt
let newTxt = "";
contributors.map( x => {
if (x) {
newTxt = newTxt.concat(`${x}\n`)
}
})
fs.writeFileSync('./contributors.txt', newTxt, {encoding: 'utf-8'})

23
.github/workflows/add-contributors.yml vendored Normal file
View file

@ -0,0 +1,23 @@
name: Add contributors
on:
push:
branches:
- "master"
- "main"
jobs:
update-contributors:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update text and html files
run: |
npm install cheerio
npm install pretty
node ./.github/scripts/contributors.js
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: update contributors

4
contributors.txt Normal file
View file

@ -0,0 +1,4 @@
Alissa M
Paul Schulz
Gareth Dixon
Andrew Kelly