Add redirects to new webpage #1482
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
# Github action to build Jekyll site for a pull request preview | |
# We have to checkout and run untrusted code! This is dangerous if done in a privileged context. | |
# That's why this action only has read-permissions. | |
# Commenting on the PR and pushing the result is done in the "commentAndPushPRPreview.yml" action. | |
name: Jekyll PR Preview | |
on: | |
issue_comment: | |
types: [created] | |
permissions: read-all | |
env: | |
SRC_DIR: src | |
PUBLISH_DIR: gh-pages | |
FPM_INDEX: "https://raw.githubusercontent.com/fortran-lang/fpm-registry/HEAD/index.json" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
if: github.event.issue.pull_request && contains(github.event.comment.body,'#build_preview') | |
steps: | |
# Checkout repo into SRC_DIR | |
- name: Checkout pr/${{github.event.issue.number}} | |
uses: actions/checkout@v2 | |
with: | |
path: ${{env.SRC_DIR}} | |
# Checkout PR branch into SRC_DIR | |
- name: Fetch pr/${{github.event.issue.number}} | |
run: | | |
cd ${{env.SRC_DIR}} | |
git fetch origin pull/${{github.event.issue.number}}/head:pr-${{github.event.issue.number}} | |
git checkout pr-${{github.event.issue.number}} | |
# Checkout existing gh-pages branch into PUBLISH_DIR | |
- name: Checkout gh-pages | |
uses: actions/checkout@v2 | |
with: | |
path: ${{env.PUBLISH_DIR}} | |
ref: 'gh-pages' | |
# Install ruby 2.7.x | |
- uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 2.7 | |
# Setup Jekyll in SRC_DIR | |
- name: Setup Jekyll | |
run: | | |
cd ${{env.SRC_DIR}} | |
sudo gem install bundler | |
bundle config path .bundle | |
bundle install | |
# Sets Jekyll output directory using PR id | |
- name: Define output directory | |
run: echo "BUILD_DIR=pr/${{github.event.issue.number}}" >> $GITHUB_ENV | |
# Appends PR-based output directory to Jekyll baseurl variable | |
- name: Update Jekyll site config | |
run: | | |
cd ${{env.SRC_DIR}} | |
grep baseurl _config.yml|grep -v "#" |awk -F : '{print $2}' | xargs > base_url | |
sed -i '/baseurl:/d' _config.yml | |
echo "baseurl: $(cat base_url)/${{env.BUILD_DIR}}" >> _config.yml | |
echo "pull_request: ${{github.event.issue.number}}" >> _config.yml | |
# Download latest fpm-registry index | |
- name: Download fpm-registry index | |
run: | | |
cd ${{env.SRC_DIR}}/_data | |
wget ${{env.FPM_INDEX}} | |
mv index.json fpm_registry_index.json | |
# Run Jekyll build and copy output to PUBLISH_DIR | |
- name: Build Jekyll Site | |
run: | | |
cd ${{env.SRC_DIR}} | |
bundle exec jekyll build --future -d _site/${BUILD_DIR} | |
cp -r _site/* ../${{env.PUBLISH_DIR}}/ | |
touch ../${{env.PUBLISH_DIR}}/.nojekyll | |
- name: Upload jekyll site as artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: jekyllSite | |
path: | | |
${{env.PUBLISH_DIR}}/${{env.BUILD_DIR}} | |
- name: Save PR number and BUILD_DIR | |
run: | | |
mkdir -p ./pr | |
echo ${{env.BUILD_DIR}} > ./pr/BUILD_DIR | |
echo ${{github.event.issue.number}} > ./pr/NR | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: pr | |
path: pr/ | |