11name : Deploy internal
2+
23on :
3- pull_request :
4+ pull_request_target :
45 branches :
56 - main
67 paths :
78 - " **/*.jmd"
89 - " **/Project.toml"
910
11+ permissions :
12+ contents : write
13+
1014jobs :
1115 generate-job-strategy-matrix :
1216 runs-on : ubuntu-latest
1317 outputs :
1418 job-strategy-matrix : ${{ steps.generate.outputs.job-strategy-matrix }}
1519 steps :
16- - name : Checkout
17- uses : actions/checkout@v3
20+ - name : Checkout PR code
21+ uses : actions/checkout@v4
1822 with :
19- fetch-depth : 5
23+ repository : ${{ github.event.pull_request.head.repo.full_name }}
24+ ref : ${{ github.event.pull_request.head.sha }}
25+ fetch-depth : 2
26+ persist-credentials : false
27+
2028 - name : Generate MATRIX
2129 id : generate
2230 run : |
2331 MATRIX=$( (
2432 echo '{ "tutorial": ['
25- git diff --name-only HEAD HEAD~1 | grep -E "(jmd|Project.toml)" | sed 's/Project.toml/index.jmd/g' | uniq | sed -r 's/(.*)/\"\1\"/g' | sed '$!s/$/,/'
33+ git diff --name-only HEAD HEAD~1 \
34+ | grep -E "(jmd|Project.toml)" \
35+ | sed 's/Project.toml/index.jmd/g' \
36+ | uniq \
37+ | sed -r 's/(.*)/\"\1\"/g' \
38+ | sed '$!s/$/,/'
2639 echo ']}'
2740 ) | jq -c .)
28- echo $MATRIX
29- echo $MATRIX | jq .
30- echo "::set-output name=job-strategy-matrix::$MATRIX"
41+
42+ echo "$MATRIX"
43+ echo "$MATRIX" | jq .
44+
45+ # new-style output
46+ echo "job-strategy-matrix=$MATRIX" >> "$GITHUB_OUTPUT"
3147
3248 build-tutorials :
3349 needs : generate-job-strategy-matrix
@@ -36,20 +52,27 @@ jobs:
3652 strategy :
3753 matrix : ${{ fromJSON(needs.generate-job-strategy-matrix.outputs.job-strategy-matrix) }}
3854 steps :
39- - name : Checkout
40- uses : actions/checkout@v3
55+ - name : Checkout PR code
56+ uses : actions/checkout@v4
4157 with :
58+ repository : ${{ github.event.pull_request.head.repo.full_name }}
59+ ref : ${{ github.event.pull_request.head.sha }}
60+ fetch-depth : 1
4261 persist-credentials : false
62+
4363 - name : Install Julia
4464 uses : julia-actions/setup-julia@v1
4565 with :
4666 version : 1
67+
4768 - name : Build tutorial
4869 run : |
4970 bash .github/workflows/build_tutorial.sh ${{ matrix.tutorial }}
71+
5072 - name : Upload artifact
5173 uses : actions/upload-artifact@v4
5274 with :
75+ name : tutorials
5376 path : markdown/*
5477
5578 deploy :
@@ -61,38 +84,55 @@ jobs:
6184 run : |
6285 wget https://github.com/JuliaSmoothOptimizers/JSOTutorials.jl/archive/refs/heads/gh-pages.zip
6386 unzip gh-pages.zip
87+
6488 - name : Download artifact
6589 uses : actions/download-artifact@v4
6690 with :
91+ name : tutorials
6792 path : .
68- - name : list
93+
94+ - name : List files
6995 run : ls -R
96+
7097 - name : Merge gh-pages and updates and update index.md
7198 run : |
72- cp -rf artifact /* JSOTutorials.jl-gh-pages/
99+ cp -rf markdown /* JSOTutorials.jl-gh-pages/
73100 cd JSOTutorials.jl-gh-pages
101+
74102 echo "## JSOTutorials preview page
75103
76104 For the complete list of tutorials, go to <https://jso.dev/tutorials/>.
77105
78106 " > index.md
79- for file in **/*.md; do NAME=$(echo $file | cut -d/ -f 1); TITLE=$(grep "title:" $file | cut -d\" -f2); echo "- [$TITLE]($NAME/)"; done >> index.md
107+
108+ for file in **/*.md; do
109+ NAME=$(echo "$file" | cut -d/ -f 1)
110+ TITLE=$(grep "title:" "$file" | cut -d\" -f2)
111+ echo "- [$TITLE]($NAME/)"
112+ done >> index.md
113+
80114 - name : Deploy to gh-pages
81115 uses : peaceiris/actions-gh-pages@v3
82116 with :
83117 github_token : ${{ secrets.GITHUB_TOKEN }}
84118 publish_dir : ./JSOTutorials.jl-gh-pages
85119 enable_jekyll : true
120+
86121 pr_comment :
87122 needs : [generate-job-strategy-matrix, build-tutorials, deploy]
88123 runs-on : ubuntu-latest
89124 if : ${{ needs.generate-job-strategy-matrix.outputs.job-strategy-matrix != '[]' }}
90125 steps :
91- - name : " Comment PR"
126+ - name : Comment PR
92127 uses : actions/github-script@0.3.0
93- if : github.event_name == 'pull_request' && github.repository == github.event.pull_request.head.repo.full_name # if this is a pull request build AND the pull request is NOT made from a fork
128+ if : github.event_name == 'pull_request_target'
94129 with :
95130 github-token : ${{ secrets.GITHUB_TOKEN }}
96131 script : |
97- const { issue: { number: issue_number }, repo: { owner, repo } } = context;
98- github.issues.createComment({ issue_number, owner, repo, body: 'Once the build has completed, you can preview your PR at this URL: https://jso.dev/JSOTutorials.jl/' });
132+ const { issue: { number: issue_number }, repo: { owner, repo } } = context;
133+ github.issues.createComment({
134+ issue_number,
135+ owner,
136+ repo,
137+ body: 'Once the build has completed, you can preview your PR at this URL: https://jso.dev/JSOTutorials.jl/'
138+ });
0 commit comments