Skip to content

Fix: update version of Ruby to 3.1 #269

Fix: update version of Ruby to 3.1

Fix: update version of Ruby to 3.1 #269

name: Staging Website Builder
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency
concurrency: staging-website-build
# Run this workflow every time a new commit is pushed to any branch apart from the production one (master)
on:
push:
branches-ignore:
- master
- gh-pages
- gh-pages-staging
workflow_dispatch:
# Allow it to be run manually - useful for testing?
jobs:
# Set the job key. The key is displayed as the job name
# when a job name is not provided
website-builder:
# Name the Job
name: Build the website from this repository
# Set the type of machine to run on
runs-on: ubuntu-latest
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: 📂 Checkout code
uses: actions/checkout@v4
- name: 💎 setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Sanitise branch name
shell: bash
id: sanitise-branch-name
run: |
SANITISED_BRANCH_NAME=$(echo -n ${{ github.ref_name }} | tr "/" "_")
echo "sanitised branch name: ${SANITISED_BRANCH_NAME}"
echo "sanitised-branch-name=${SANITISED_BRANCH_NAME}" >> $GITHUB_OUTPUT
# Prepare the website directory
- name: Copy dependencies to Website directory
run: |
echo `pwd`
bash ./build/website/copy-assets.sh
# Make the adjustments needed to refer to this newly build website correctly
sed -i -e 's/https:\/\/www.running-challenges.co.uk/https:\/\/staging.running-challenges.co.uk/' website/_config.yml
sed -i -e 's/Running Challenges/Running Challenges - Staging (${{ steps.sanitise-branch-name.outputs.sanitised-branch-name }})/' website/_config.yml
sed -i -e 's/baseurl: ""/baseurl: "\/${{ steps.sanitise-branch-name.outputs.sanitised-branch-name }}\/"/' website/_config.yml
cat website/_config.yml
shell: bash
# Install some dependencies to try and fix Ruby randomly crashing
# Taken from https://github.com/sass/sassc-ruby/issues/146#issuecomment-771042986
- name: Install some dependencies for Ruby
run: |
set -x \
&& sudo apt update \
&& sudo apt install -y --no-install-recommends \
libffi-dev
shell: bash
- name: 🔨 install dependencies & build site
uses: limjh16/jekyll-action-ts@v2
with:
enable_cache: true
jekyll_src: website
# Then we need to prune any directories that don't match to currently active branches
# Get the latest copy of the repo
# We need to set a token here, otherwise it uses the default one that won't have permission to push
- name: Checkout code
uses: actions/checkout@v4
if: ${{ github.actor != 'dependabot[bot]' }}
with:
repository: fraz3alpha/running-challenges-staging
ref: gh-pages
path: gh-pages-staging
token: ${{ secrets.RUNNING_CHALLENGES_STAGING_GITHUB_API_TOKEN }}
- name: Reconcile branches
id: reconcile-branches
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
git ls-remote --heads | awk '{print $2}' | awk -F 'refs/heads/' '{print $2}' | sort > running-challenges-branches.txt
echo "All branches: $(cat running-challenges-branches.txt)"
find gh-pages-staging -mindepth 1 -maxdepth 1 -type d -printf '%P\n' | sort | grep -v '.git' > gh-pages-branches.txt
echo "Built branches: $(cat gh-pages-branches.txt)"
# Find the lines only in the gh-pages branches file (note files must be sorted for comm to work)
comm -23 gh-pages-branches.txt running-challenges-branches.txt > prune-branches.txt
echo "Built branches to delete: $(cat prune-branches.txt | tr '\n' ' ')"
echo "Contents before"
ls -l gh-pages-staging/
du -sh gh-pages-staging/*
# Delete those directories from the repo
cat prune-branches.txt | xargs -I % --no-run-if-empty -n1 rm -r "gh-pages-staging/%"
# Delete the branch directory in the target
rm -r gh-pages-staging/${{ steps.sanitise-branch-name.outputs.sanitised-branch-name }} || true
# Copy the new built site in
cp -a _site gh-pages-staging/${{ steps.sanitise-branch-name.outputs.sanitised-branch-name }}
# Create an index page of all the built branches
echo "<html><head><title>Available branch builds</title></head><body>" > gh-pages-staging/index.html
comm -12 gh-pages-branches.txt running-challenges-branches.txt | xargs -I % bash -c 'echo "Adding %" && echo "<a href=\"%\">%</a><br>" >> gh-pages-staging/index.html'
echo "</body></html>" >> gh-pages-staging/index.html
cat gh-pages-staging/index.html
echo "Contents after"
ls -l gh-pages-staging/
du -sh gh-pages-staging/*
# Delete the .git directory, and try and get it to forget it was ever a git repo
echo "Deleting .git directory"
rm -fr gh-pages-staging/.git
shell: bash
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
if: ${{ github.actor != 'dependabot[bot]' }}
with:
personal_token: ${{ secrets.RUNNING_CHALLENGES_STAGING_GITHUB_API_TOKEN }}
external_repository: fraz3alpha/running-challenges-staging
publish_branch: gh-pages
publish_dir: gh-pages-staging