diff --git a/.github/scripts/contributors.js b/.github/scripts/contributors.js new file mode 100644 index 0000000..b79f605 --- /dev/null +++ b/.github/scripts/contributors.js @@ -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(`
  • ${name}
  • \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'}) diff --git a/.github/workflows/add-contributors.yml b/.github/workflows/add-contributors.yml new file mode 100644 index 0000000..85d7ced --- /dev/null +++ b/.github/workflows/add-contributors.yml @@ -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 \ No newline at end of file diff --git a/contributors.txt b/contributors.txt new file mode 100644 index 0000000..b91cd7c --- /dev/null +++ b/contributors.txt @@ -0,0 +1,4 @@ +Alissa M +Paul Schulz +Gareth Dixon +Andrew Kelly \ No newline at end of file