Lecture 2 Materials #6
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 Config on New Issue | |
on: | |
issues: | |
types: [opened] | |
jobs: | |
update-config: | |
if: contains(github.event.issue.labels.*.name, 'materials') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python environment | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
- name: Parse issue content | |
id: parse_issue | |
env: | |
ISSUE_BODY: ${{ github.event.issue.body }} | |
run: python parse_issue.py | |
- name: Update _config.yml | |
run: | | |
LEC_NUM=$(echo "${{ env.Lecture_Number }}" | xargs) | |
DEMO=$(echo "${{ env.Demo }}" | xargs) | |
SLIDES=$(echo "${{ env.Slides }}" | xargs) | |
CONFIG_FILE="_config.yml" | |
SLIDE_LINE=" slide${LEC_NUM}: \"Slides\"" | |
DEMO_LINE=" demo${LEC_NUM}: \"Demo\"" | |
if [ "$DEMO" == "None" ]; then | |
DEMO_REPLACEMENT=" demo${LEC_NUM}: \"\"" | |
else | |
DEMO_LINK="https://data8.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdata-8%2Fmaterials-su24&urlpath=tree%2Fmaterials-su24%2Flec%2F${DEMO}%2F${DEMO}.ipynb&branch=main" | |
DEMO_REPLACEMENT=" demo${LEC_NUM}: \"[Demo](${DEMO_LINK})\"" | |
fi | |
SLIDES_REPLACEMENT=" slide${LEC_NUM}: \"[Slides](${SLIDES})\"" | |
sed -i "s|${SLIDE_LINE}|${SLIDES_REPLACEMENT}|g" $CONFIG_FILE | |
sed -i "s|${DEMO_LINE}|${DEMO_REPLACEMENT}|g" $CONFIG_FILE | |
- name: Commit changes | |
run: | | |
git config user.name 'jonathanferrari' | |
git config user.email '[email protected]' | |
git add _config.yml | |
git commit -m "Update _config.yml for lecture ${LEC_NUM}" | |
git push | |
- name: Install GitHub CLI | |
run: sudo apt-get install -y gh | |
- name: Authenticate with GitHub CLI | |
run: echo "${{ secrets.GH_PAT }}" | gh auth login --with-token | |
- name: Close issue with comment | |
env: | |
LEC_NUM: ${{ env.Lecture_Number }} | |
DEMO: ${{ env.Demo }} | |
SLIDES: ${{ env.Slides }} | |
run: | | |
if [ "$DEMO" == "None" ]; then | |
DEMO_TEXT="None" | |
else | |
DEMO_LINK="https://data8.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdata-8%2Fmaterials-su24&urlpath=tree%2Fmaterials-su24%2Flec%2F${DEMO}%2F${DEMO}.ipynb&branch=main" | |
DEMO_TEXT="[Demo](${DEMO_LINK})" | |
fi | |
gh issue comment ${{ github.event.issue.number }} --body "Updated \`_config.yml\` for lecture ${LEC_NUM}: | |
- Slides: [Slides](${SLIDES}) | |
- Demo: $DEMO_TEXT" | |
gh issue close ${{ github.event.issue.number }} |