monthly lcsh check #115
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: monthly lcsh check | |
on: | |
schedule: | |
- cron: '5 9 15 * *' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} | |
ASSIGNEES: charlottekostelic | |
jobs: | |
monthly-run: | |
name: Run monthly LCSH check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -r requirements.txt | |
- name: Get date var | |
run: | | |
echo "DATE=$(date "+%Y-%m-%d")" >> $GITHUB_ENV | |
- name: Create branch, run script | |
run: | | |
git checkout -b monthly_check_$DATE | |
python monthly_lcsh_check.py | |
- name: Commit and push changed files | |
run: | | |
git config user.name "Charlotte Kostelic" | |
git config user.email "[email protected]" | |
git add lcsh.log | |
git add data/* | |
git commit -a -m "LCSH Check $DATE" | |
git push --set-upstream origin monthly_check_$DATE | |
- name: Parse output, create PR and issue text | |
run: | | |
echo "CHANGED=$(grep -Eq "$DATE .+DEBUG" lcsh.log && echo 'true' || echo 'false')" >> $GITHUB_ENV | |
REVISED_LIST=$(grep -E "$DATE .+DEBUG - Revised" lcsh.log | grep -Eo "\[.+]$" || echo 'false') | |
DEPRECATED_LIST=$(grep -E "$DATE .+DEBUG - Deprecated" lcsh.log | grep -Eo "\[.+]$" || echo 'false') | |
{ | |
echo "PR_BODY<<EOF" | |
echo "### Changed:" | |
echo " + lcsh.log updated with data from workflow run on $(date '+%D')" | |
echo "$(grep -Eq "$DATE .+DEBUG" lcsh.log && echo '### Added:' && echo ' + New infile is: data/acc_in.csv' && echo ' + Old infile is: data/acc_in_${{ env.DATE }}' || echo '')" | |
echo EOF | |
} >> $GITHUB_ENV | |
{ | |
echo "ISSUE_BODY<<EOF" | |
echo "$(grep -Eq "$DATE .+DEBUG - Revised" lcsh.log && echo '### Changed:' && echo "$REVISED_LIST" || '$(grep -Eq "$DATE .+DEBUG - Revised" lcsh.log)')" | |
echo "$(grep -Eq "$DATE .+DEBUG - Deprecated" lcsh.log && echo '### Deprecated:' && echo "$DEPRECATED_LIST" || '$(grep -Eq "$DATE .+DEBUG - Deprecated" lcsh.log)')" | |
echo EOF | |
} >> $GITHUB_ENV | |
- name: Create PR | |
run: | | |
echo "${{ env.PR_BODY }}" | |
gh pr create \ | |
--repo ${{ github.repository }} \ | |
--assignee "$ASSIGNEES" \ | |
--title "Monthly LCSH check ($DATE)" \ | |
--body "$PR_BODY" | |
- name: Create Issue | |
if: ${{ env.CHANGED == 'true' }} | |
run: | | |
echo "${{ env.ISSUE_BODY }}" | |
gh issue create \ | |
--title "Changes to ACC LCSH ($DATE)" \ | |
--assignee "$ASSIGNEES" \ | |
--body "$ISSUE_BODY" |