Adds 2 Rory facts #33
Workflow file for this run
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: sync pets mega-facts | |
on: | |
pull_request: | |
paths: | |
- birds.json | |
- cats.json | |
- dags.json | |
jobs: | |
sync: | |
name: Sync the pets MEGA-FACTS! | |
runs-on: ubuntu-latest | |
steps: | |
# Rather than use a personal access token to interact with the project, we | |
# can use this GitHub App. There's an API for exchanging app credentials | |
# for a short-term token, and we use that API here. | |
- name: get token | |
uses: tibdex/github-app-token@v1 | |
id: app_token | |
with: | |
app_id: ${{ secrets.APP_ID }} | |
installation_id: ${{ secrets.APP_INSTALLATION_ID }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY }} | |
- uses: actions/checkout@v3 | |
with: | |
# Use the branch commit instead of the PR merge commit | |
ref: ${{ github.event.pull_request.head.ref }} | |
# Use an app access token, so that any commits generated by this | |
# job will trigger a rebuild, so the thing can be merged | |
token: ${{ steps.app_token.outputs.token }} | |
- name: smoosh them all together | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require("fs"); | |
fs.writeFileSync( | |
"pets.json", | |
JSON.stringify( | |
["birds.json", "cats.json", "dags.json"] | |
.map((f) => fs.readFileSync(f, { encoding: "utf-8" })) | |
.flatMap((v) => JSON.parse(v)), | |
null, | |
2 | |
), | |
{ encoding: "utf-8" } | |
); | |
# Check if anything has changed. This will exit with 0 if there is nothing | |
# in the diff, or non-zero if anything has changed. | |
- name: checking for changes | |
run: if git diff --exit-code --quiet; then echo "::set-output name=changes::no"; else echo "::set-output name=changes::yes"; fi | |
id: diff | |
# If anything changed, commit it. | |
- name: commit changes | |
if: steps.diff.outputs.changes == 'yes' | |
uses: EndBug/add-and-commit@v9 | |
with: | |
message: synchronize word lists | |
- if: steps.diff.outputs.changes == 'yes' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Hi, @${context.actor}! I've updated the pets **MEGA FACTS** with your changes. Please pull the last commit before pushing any more changes.` | |
}); |