-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_html_on_md_push.yml
75 lines (68 loc) · 2.4 KB
/
generate_html_on_md_push.yml
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
name: Generate Workshop HTML from Markdown
on: [push]
jobs:
generate-html:
runs-on: ubuntu-latest
steps:
- name: Check files in commit
run: |
MDFILES=$(
curl --silent https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }} |
jq --raw-output --compact-output --join-output '.files[] | select(.filename | match(".*(?<!README)\\.md")) | {filename, status}');
if [[ -n $MDFILES ]];
then
echo "::set-env name=MDFILES::$MDFILES";
[[ -n $(echo $MDFILES | jq --raw-output 'select(.status == "removed").filename') ]] && echo "::set-env name=REMOVE::1";
[[ -n $(echo $MDFILES | jq --raw-output 'select(.status != "removed").filename') ]] && echo "::set-env name=GENERATE::1";
fi;
exit 0;
- name: Checkout Workshops Repo
if: env.MDFILES
uses: actions/checkout@v2
with:
path: workshops
- name: Remove HTML for deleted markdown files
if: env.REMOVE
run: |
cd workshops;
for i in $(echo $MDFILES | jq --raw-output 'select(.status == "removed").filename');
do
HTML_FILE="${i%%.md}.html"
if [ -e "$HTML_FILE" ];
then
echo "Removing $HTML_FILE";
git rm "$HTML_FILE";
fi;
done;
- name: Checkout HTML generator
if: env.GENERATE
uses: actions/checkout@v2
with:
repository: sul-cidr/workshop-html-generator
path: html-generator
- name: Install dependencies
if: env.GENERATE
run: |
cd html-generator;
python3 -m pip install --upgrade pip;
pip3 install setuptools;
pip3 install -r requirements.txt;
- name: Generate HTML
if: env.GENERATE
run: |
cd workshops;
for i in $(echo $MDFILES | jq --raw-output 'select(.status != "removed").filename');
do
HTML_FILE="${i%%.md}.html"
echo "Generating $HTML_FILE";
python3 ../html-generator/gen_html.py -t ../html-generator/template.html "$i" > "$HTML_FILE";
git add "$HTML_FILE";
done;
- name: Commit HTML
if: env.MDFILES
run: |
cd workshops;
git config --global user.name "${{ github.actor }}";
git config --global user.email "${{ github.actor }}@users.noreply.github.com";
git commit -am "Auto-generated HTML";
git push;