Add a new fact #42
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: issue created | |
on: | |
issues: | |
types: [edited, opened] | |
jobs: | |
add_fact: | |
name: add a new fact if appropriate | |
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: | |
token: ${{ steps.app_token.outputs.token }} | |
ref: main | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: npm | |
- name: install dependencies | |
run: npm install --production | |
- name: update files with new fact | |
run: node addFact.js | |
working-directory: ./.github/workflows | |
- name: check 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: change branches | |
if: steps.diff.outputs.changes == 'yes' | |
run: git checkout -b add-fact/${{ github.event.issue.number }} | |
- name: commit changes | |
if: steps.diff.outputs.changes == 'yes' | |
uses: EndBug/add-and-commit@v9 | |
with: | |
message: "adding fact; closes #${{ github.event.issue.number }}" | |
# Force push because if this issue has been edited, then there's | |
# already a branch with this name, but it refers to the prior edit so | |
# we'll just... throw it away. | |
push: "origin add-fact/${{ github.event.issue.number }} --force" | |
- name: open pull request | |
if: steps.diff.outputs.changes == 'yes' | |
env: | |
GH_TOKEN: ${{ steps.app_token.outputs.token }} | |
run: | | |
NUM=${{ github.event.issue.number }} | |
BRANCH="add-fact/${{ github.event.issue.number }}" | |
gh pr create \ | |
--title "Adding fact for #$NUM" \ | |
--body "This fact is being added automatically from the contents of #$NUM. Closes #$NUM." | |
gh pr merge $BRANCH --auto --squash |