Merge pull request #96 from AndBerna/abg/update_and_fix_errors #67
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |