-
Notifications
You must be signed in to change notification settings - Fork 2
79 lines (64 loc) · 2.68 KB
/
update-lecture.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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=$(echo "https://data8.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https://github.com/data-8/materials-su24&urlpath=tree/materials-su24/lec/${DEMO}/${DEMO}.ipynb&branch=main" | sed 's/&/\\&/g')
DEMO_REPLACEMENT=" demo${LEC_NUM}: \"• [Demo](${DEMO_LINK})\""
fi
SLIDES_REPLACEMENT=" slide${LEC_NUM}: \"[Slides](${SLIDES})\""
sed -i "s| slide${LEC_NUM}: \"Slides\"|${SLIDES_REPLACEMENT}|g" $CONFIG_FILE
sed -i "s| demo${LEC_NUM}: \"• Demo\"|${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=$(echo "https://data8.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https://github.com/data-8/materials-su24&urlpath=tree/materials-su24/lec/${DEMO}/${DEMO}.ipynb&branch=main" | sed 's/&/\\&/g')
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 }}