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: Update course data from API | |
on: | |
workflow_dispatch: | |
push: | |
jobs: | |
main: | |
name: Fetch and rebuild autocomplete graph and combos table | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Check out Git repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create or reset the update branch | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git checkout 270-bug-new-courses-missing-from-search-due-to-outdated-autocomplete-graph | |
git branch -D update-course-data || true # Delete branch if it exists locally | |
git checkout -b update-course-data | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install for ts-node | |
run: npm install | |
- name: Add API Key | |
run: echo "REACT_APP_NEBULA_API_KEY=${{ secrets.NEBULA_API_KEY }}" >> .env.local | |
- name: Fetch new data from api | |
run: npm run fetchdata | |
- name: Build autocomplete graph | |
run: npm run buildautocomplete | |
- name: Build combos table | |
run: npm run buildcombos | |
- name: Commit changes | |
run: | | |
git add . | |
git commit -m "Update course data from API" | |
git push -f origin update-course-data | |
- name: Create PR | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { repo, owner } = context.repo; | |
const pulls = await github.rest.pulls.list({ | |
owner: owner, | |
repo: repo, | |
head: context.ref, | |
base: '270-bug-new-courses-missing-from-search-due-to-outdated-autocomplete-graph', | |
state: 'open', | |
}); | |
if (pulls.data.length < 1) { | |
await github.rest.pulls.create({ | |
title: 'Update course data from API', | |
owner: owner, | |
repo: repo, | |
head: context.ref, | |
base: '270-bug-new-courses-missing-from-search-due-to-outdated-autocomplete-graph', | |
body: [ | |
'Fetch and rebuild autocomplete graph and combos table', | |
'', | |
'This PR is auto-generated by', | |
'[actions/github-script](https://github.com/actions/github-script)', | |
].join('\n'), | |
}); | |
} else { | |
const existingPR = pulls.data[0]; | |
await github.rest.issues.createComment({ | |
owner: owner, | |
repo: repo, | |
issue_number: existingPR.number, | |
body: [ | |
`Updated by Job ${context.job}`, | |
].join('\n'), | |
}); | |
} |