From 7cdf8b8dfca8e8513fdbc1ed67a701420d8527cb Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Mon, 24 Oct 2022 12:18:35 -0700 Subject: Add a PR workflow --- .github/workflows/pull.yml | 24 ++++++++++++++++++++++++ bin/checkPeople.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/pull.yml create mode 100644 bin/checkPeople.js diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml new file mode 100644 index 0000000..266b8f8 --- /dev/null +++ b/.github/workflows/pull.yml @@ -0,0 +1,24 @@ +name: Check people + +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node: [ 16.x ] + + steps: + - uses: actions/checkout@v2 + - name: Install modules with Node ${{ matrix.node }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - name: Check people + run: node bin/checkPeople.js ${{ github.actor }} diff --git a/bin/checkPeople.js b/bin/checkPeople.js new file mode 100644 index 0000000..60527b9 --- /dev/null +++ b/bin/checkPeople.js @@ -0,0 +1,29 @@ +const fs = require("fs"); + +const PEOPLE_PATH = "./people.json"; + +const [actor] = process.argv.slice(2); + +console.log(`Triggered by ${actor}`); + +if (!fs.existsSync(PEOPLE_PATH)) { + throw "No people file found"; +} + +let people; +try { + people = JSON.parse(fs.readFileSync(PEOPLE_PATH)); +} catch (err) { + throw "Could not read people.json as JSON"; +} + +const person = people.find(person => person.github === actor); +if (!person) { + throw `${actor} isn't in people.json!`; +} + +if (!(person.entries && person.entries.length > 0)) { + throw `${actor} is missing entries!`; +} + +console.log("Checked!"); -- cgit v1.2.3-70-g09d2