-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (88 loc) · 3.17 KB
/
render-deploy.yaml
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
name: Render to HTML & Deploy
on:
push:
branches:
- main
paths:
- src/G*/**
repository_dispatch:
types: [update-assets]
jobs:
check-changes:
name: Check if Rmd or image files changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Find directories with changed rmd or image files
id: changed-files-dir-names
uses: tj-actions/changed-files@v44
with:
files: |
src/G*/*.{rmd,Rmd,html,css}
src/G*/js/*.js
src/G*/css/*.css
src/G*/img/*.{png,gif}
src/G*/img/*/*.{png,gif}
dir_names: "true"
dir_names_max_depth: 2
dir_names_deleted_files_include_only_deleted_dirs: "true"
output_renamed_files_as_deleted_and_added: "true"
- name: Render modified courses to HTML and move output to docs
env:
WORKFLOW: true
CHANGED_DIRS: ${{ steps.changed-files-dir-names.outputs.all_changed_files }}
run: |
set -e
for folder in ${CHANGED_DIRS}; do
code="${folder#src/}"
./render.sh $code
done
if [ ! -d "docs" ]; then
mkdir docs
fi
cp ./pagesroot/* ./docs/
- name: Add, Commit & Push
env:
CHANGED_DIRS: ${{ steps.changed-files-dir-names.outputs.all_changed_files }}
DELETED_DIRS: ${{ steps.changed-files-dir-names.outputs.deleted_files }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create temporary branch with no history
git checkout --orphan temp-pages
# Unstage files from 'main'
git rm -r --cached .
# Checkout course folder from live 'pages' branch
git checkout remotes/origin/pages -- ./G*
# Remove course folders that were either changed or deleted
# This way we can keep the unchanged folders
# This is done so that we can render only the courses that had
# changes made to them, speeding up the process
for folder in ${CHANGED_DIRS} ${DELETED_DIRS}; do
code="${folder#src/}"
rm -rf $code
done
# We add all courses that were left over
git add G*
# Add docs, which contains the courses
# that were rendered in the previous step
# as well as the favicon and index
git add docs
# Remove everything that wasn't explicitly 'git add'ed
git clean -df
# Move courses and assets to root
mv docs/* .
rm -r docs
# Finally add everything and commit
# Since the temp branch has no history this will
# be the first and only commit
git add .
git commit -m "Automatic: Render docs from ${GITHUB_SHA}"
# Rename the temporary branch and overwrite pages
git branch -M temp-pages pages
# Force push
git push --force origin pages