11
11
12
12
permissions :
13
13
contents : write # Ensure the job has write permissions
14
+ issues : write # Required for API calls to create and delete deploy keys
14
15
15
16
steps :
16
17
- name : Checkout the Linear_Algebra_with_Python repository
@@ -29,11 +30,32 @@ jobs:
29
30
quarto convert "$notebook" -o "converted_chapters/$(basename "$notebook" .ipynb).qmd"
30
31
done
31
32
33
+ - name : Generate SSH Key
34
+ run : |
35
+ ssh-keygen -t rsa -b 4096 -C "actions@github.com" -f /tmp/github_actions -N ""
36
+ echo "::set-output name=ssh-public-key::$(cat /tmp/github_actions.pub)"
37
+
38
+ - name : Add SSH Key to the SSH Agent
39
+ run : |
40
+ eval "$(ssh-agent -s)"
41
+ ssh-add /tmp/github_actions
42
+
43
+ - name : Add Deploy Key to GitHub
44
+ id : add_deploy_key
45
+ run : |
46
+ curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
47
+ -H "Accept: application/vnd.github.v3+json" \
48
+ https://api.github.com/repos/weijie-chen/weijie-chen.github.io/keys \
49
+ -d "{\"title\":\"GitHub Actions Key\",\"key\":\"$(cat /tmp/github_actions.pub)\",\"read_only\":false}" \
50
+ -o deploy_key.json
51
+ echo "::set-output name=deploy-key-id::$(jq -r .id deploy_key.json)"
52
+
32
53
- name : Checkout the weijie-chen.github.io repository
33
54
uses : actions/checkout@v4.1.7
34
55
with :
35
56
repository : weijie-chen/weijie-chen.github.io
36
57
path : book_repo
58
+ ssh-key : /tmp/github_actions # Use the dynamically generated SSH key
37
59
38
60
- name : Copy Converted QMD Files to Book Repository
39
61
run : |
50
72
sed -i '/<section class="table-of-contents">/,/<\/section>/{//!d}' book_repo/linear-algebra-with-python-book/index.html
51
73
sed -i "/<section class=\"table-of-contents\">/a $toc" book_repo/linear-algebra-with-python-book/index.html
52
74
53
- - name : Set up SSH Agent
54
- uses : webfactory/ssh-agent@v0.5.3
55
- with :
56
- ssh-private-key : ${{ secrets.SSH_PRIVATE_KEY }}
57
-
58
75
- name : Commit and Push Changes via SSH
59
76
run : |
60
77
cd book_repo
64
81
git add linear-algebra-with-python-book/index.html
65
82
git commit -m "Updated chapters and Table of Contents"
66
83
git push git@github.com:weijie-chen/weijie-chen.github.io.git main
84
+
85
+ - name : Clean Up - Remove Deploy Key from GitHub
86
+ run : |
87
+ DEPLOY_KEY_ID=$(jq -r .id deploy_key.json)
88
+ curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
89
+ https://api.github.com/repos/weijie-chen/weijie-chen.github.io/keys/$DEPLOY_KEY_ID
0 commit comments