-
Notifications
You must be signed in to change notification settings - Fork 10
138 lines (118 loc) · 4.07 KB
/
Deploy-internal.yml
File metadata and controls
138 lines (118 loc) · 4.07 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Deploy internal
on:
pull_request_target:
branches:
- main
paths:
- "**/*.jmd"
- "**/Project.toml"
permissions:
contents: write
jobs:
generate-job-strategy-matrix:
runs-on: ubuntu-latest
outputs:
job-strategy-matrix: ${{ steps.generate.outputs.job-strategy-matrix }}
steps:
- name: Checkout PR code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 2
persist-credentials: false
- name: Generate MATRIX
id: generate
run: |
MATRIX=$( (
echo '{ "tutorial": ['
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/$/,/'
echo ']}'
) | jq -c .)
echo "$MATRIX"
echo "$MATRIX" | jq .
# new-style output
echo "job-strategy-matrix=$MATRIX" >> "$GITHUB_OUTPUT"
build-tutorials:
needs: generate-job-strategy-matrix
runs-on: ubuntu-latest
if: ${{ needs.generate-job-strategy-matrix.outputs.job-strategy-matrix != '[]' }}
strategy:
matrix: ${{ fromJSON(needs.generate-job-strategy-matrix.outputs.job-strategy-matrix) }}
steps:
- name: Checkout PR code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 1
persist-credentials: false
- name: Install Julia
uses: julia-actions/setup-julia@v1
with:
version: 1
- name: Build tutorial
run: |
bash .github/workflows/build_tutorial.sh ${{ matrix.tutorial }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: tutorials
path: markdown/*
deploy:
needs: [generate-job-strategy-matrix, build-tutorials]
runs-on: ubuntu-latest
if: ${{ needs.generate-job-strategy-matrix.outputs.job-strategy-matrix != '[]' }}
steps:
- name: Download current gh-pages
run: |
wget https://github.com/JuliaSmoothOptimizers/JSOTutorials.jl/archive/refs/heads/gh-pages.zip
unzip gh-pages.zip
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: tutorials
path: .
- name: List files
run: ls -R
- name: Merge gh-pages and updates and update index.md
run: |
cp -rf markdown/* JSOTutorials.jl-gh-pages/
cd JSOTutorials.jl-gh-pages
echo "## JSOTutorials preview page
For the complete list of tutorials, go to <https://jso.dev/tutorials/>.
" > index.md
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
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./JSOTutorials.jl-gh-pages
enable_jekyll: true
pr_comment:
needs: [generate-job-strategy-matrix, build-tutorials, deploy]
runs-on: ubuntu-latest
if: ${{ needs.generate-job-strategy-matrix.outputs.job-strategy-matrix != '[]' }}
steps:
- name: Comment PR
uses: actions/github-script@0.3.0
if: github.event_name == 'pull_request_target'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
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/'
});