-
Notifications
You must be signed in to change notification settings - Fork 10
104 lines (101 loc) · 3.47 KB
/
Deploy-website.yml
File metadata and controls
104 lines (101 loc) · 3.47 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
name: Deploy to website
on:
push:
branches:
- main
paths:
- "**/*.jmd"
- "**/Project.toml"
workflow_dispatch:
jobs:
generate-job-strategy-matrix:
runs-on: ubuntu-latest
outputs:
job-strategy-matrix: ${{ steps.generate.outputs.job-strategy-matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 5
- name: Generate MATRIX
id: generate
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
MATRIX=$( (
echo '{ "tutorial": ['
find . -name "*.jmd" | sed -r 's/.\/(.*)/\"\1\"/g' | sed '$!s/$/,/'
echo ']}'
) | jq -c .)
else
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 .)
fi
echo $MATRIX
echo $MATRIX | jq .
echo "::set-output name=job-strategy-matrix::$MATRIX"
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
uses: actions/checkout@v3
with:
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:
path: parsed/*
deploy:
needs: [generate-job-strategy-matrix, build-tutorials]
runs-on: ubuntu-latest
if: ${{ needs.generate-job-strategy-matrix.outputs.job-strategy-matrix != '[]' }}
env:
PAT: '${{ secrets.JSOTUTORIALS_TOKEN }}'
BRANCH: 'jsotutorials-${{ github.event_name }}-${{ github.sha }}'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
path: .
- name: list
run: ls -R
- name: Clone and commit
run: |
git clone https://abelsiqueira:$PAT@github.com/JuliaSmoothOptimizers/JuliaSmoothOptimizers.github.io
cp -r artifact/* JuliaSmoothOptimizers.github.io/tutorials/
cd JuliaSmoothOptimizers.github.io
git config --global user.email "jsotutorials@no.mail"
git config --global user.name "JSOTutorials bot"
echo $PAT
git checkout -b $BRANCH
git add tutorials
git commit -am ":robot: Tutorials deployment from $GITHUB_SHA"
git push -u origin $BRANCH -f
- name: Create pull request
uses: actions/github-script@v6
with:
github-token: ${{ secrets.JSOTUTORIALS_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
const { BRANCH } = process.env
github.rest.pulls.create({
owner: 'JuliaSmoothOptimizers',
repo: 'JuliaSmoothOptimizers.github.io',
title: 'Updates from JSOTutorials',
body: `Updates from ${BRANCH}`,
head: `${BRANCH}`,
base: 'main'
})