-
Notifications
You must be signed in to change notification settings - Fork 7
94 lines (81 loc) · 3.14 KB
/
website-build.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
name: Website Build
on:
push:
branches:
- main
jobs:
WebsiteBuild:
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/main-branch/website/Gemfile
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: main
path: main-branch
- name: Checkout gh-pages branch
uses: actions/checkout@v3
with:
ref: gh-pages
path: gh-pages-branch
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Replace placeholder files with original files
run: |
# set source and website directories
export WEBSITE_DIR="${{ github.workspace }}/main-branch/website/_includes/spec_copies"
export SOURCE_DIR="${{ github.workspace }}/main-branch/specifications"
# remove any existing placeholder files
find \
$WEBSITE_DIR \
-type f \
-path "$WEBSITE_DIR/placeholder_*.md" \
| xargs -I% \
rm %
# copy original files to website directory
find \
$SOURCE_DIR \
-type f \
-path "$SOURCE_DIR/*.md" \
-not -path "*/README.md" \
-printf "%f\n" \
| xargs -I% \
cp $SOURCE_DIR/% $WEBSITE_DIR/placeholder_%
# update specifications source base url with current repo and branch
echo "github_specs_base_url: \"https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/specifications\"" \
>> ${{ github.workspace }}/main-branch/website/_config.yml
# default base url is root of domain
echo "baseurl: /" \
>> ${{ github.workspace }}/main-branch/website/_config.yml
- name: Non-production builds use Github Page's default base url (/Power-Systems-Data/)
if: ${{ github.repository != 'carbon-data-specification/Power-Systems-Data' }}
run: |
sed -i \
's|baseurl: \/|baseurl: /Power-Systems-Data/|g' \
${{ github.workspace }}/main-branch/website/_config.yml
- name: Build static website
run: |
cd ${{ github.workspace }}/main-branch/website
bundle exec jekyll build -d ${{ github.workspace }}/gh-pages-branch
- name: Set production domain
if: ${{ github.repository == 'carbon-data-specification/Power-Systems-Data' }}
run: |
echo -n "powersystemsdata.carbondataspec.org" > ${{ github.workspace }}/gh-pages-branch/CNAME
- name: Push static site to gh-pages branch
run: |
cd ${{ github.workspace }}/gh-pages-branch
git config user.name github-actions
git config user.email [email protected]
# only commit and push if there's actually things commit
if [ $(git status --short | wc -l) -ne 0 ]; then
echo "Pushing website changes to gh-pages..."
git add -A
git commit -m "[bot] Github Pages build"
git push
else
echo "No changes on website"
fi