This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
Update studies #55
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 studies | |
on: | |
schedule: | |
# Runs at 05:00, only on Monday. (00:00 EST) | |
- cron: 0 5 * * 1 | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
update-studies: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci --legacy-peer-deps | |
- name: Write current date to environment variable | |
run: echo "DATE=$(date +'%Y-%m-%d-%I.%M.%S%p')" >> $GITHUB_ENV | |
- name: Add git user configuration | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
- name: Fetch staging from remote | |
run: | | |
git fetch | |
git switch staging | |
# Must append EOF markers for multiline variables | |
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings | |
- name: Update studies | |
run: | | |
echo "OUTPUT<<EOF" >> $GITHUB_ENV | |
npm run update-studies --silent >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Check for untracked files | |
run: | | |
git add -A | |
if git status | grep -q 'Changes to be committed'; then | |
echo "UPDATED=true" >> $GITHUB_ENV | |
echo "${{ env.OUTPUT }}" > $GITHUB_STEP_SUMMARY | |
else | |
echo "No studies were updated. No changes have been made." > $GITHUB_STEP_SUMMARY | |
fi | |
# Only run the next two steps if there were changes detected by `git status` in the previous step | |
- name: Commit changes and push to new branch | |
if: ${{ env.UPDATED == 'true' }} | |
run: | | |
git commit -m "Updated studies" | |
git checkout -b $(echo "update-studies-${{ env.DATE }}") | |
git push -u origin $(echo "update-studies-${{ env.DATE }}") | |
- name: Create a new pull request | |
if: ${{ env.UPDATED == 'true' }} | |
run: | | |
gh pr create \ | |
--base staging \ | |
--head "update-studies-${{ env.DATE }}" \ | |
--title "Merge update-studies-${{ env.DATE }} into staging" \ | |
--body "## Updated studies :rocket: ${{ env.OUTPUT }}" \ | |
--reviewer mbwatson,Woozl,suejinkim20 \ | |
--label update-studies,autogenerated \ | |
>> $GITHUB_STEP_SUMMARY | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |