Merge pull request #654 from harvard-lil/clare-centuryscaleedits #921
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: Tests | |
on: [push, pull_request] | |
jobs: | |
test: | |
runs-on: ubuntu-20.04 | |
# don't run on pushes to forks | |
if: github.event_name == 'pull_request' || github.repository == 'harvard-lil/website-static' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
path: bundle | |
key: ${{ runner.os }}-gems-${{ hashFiles('app/Gemfile.lock') }} | |
restore-keys: | | |
${{ runner.os }}-gems- | |
- name: Info | |
run: | | |
docker compose --version | |
docker version | |
npm --version | |
- name: Setup | |
run: | | |
npm install vnu-jar | |
sudo mkdir -m 777 build | |
ls bundle || sudo mkdir -m 777 bundle | |
sudo mkdir -m 777 app/.jekyll-cache | |
docker compose run jekyll npm install | |
- name: Test | |
run: | | |
bash ./scripts/run-tests.sh | |
- name: Deploy to prod | |
if: github.event_name == 'push' && github.ref == 'refs/heads/develop' | |
env: | |
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} | |
DEPLOY_URL: ${{ secrets.DEPLOY_URL }} | |
DEPLOY_HEADER: ${{ secrets.DEPLOY_HEADER }} | |
LIVE_SITE: ${{ secrets.LIVE_SITE }} | |
run: | | |
set -x | |
CSS_BUST=$(find build/assets/css build/*.config.js -type f -exec bash -c 'if [[ `diff {} <(curl -s "https://$LIVE_SITE/$(echo "{}" | cut -c 7-)")` ]]; then echo "bust ({})"; fi' \;) | |
if [[ $CSS_BUST ]] ; then | |
COUNTER=`grep css-cache-buster app/_layouts/default.html | sed -r 's/.*css-cache-buster=([0-9]+).*/\1/'` | |
let NEWCOUNTER=$COUNTER+1 | |
perl -pi -e "s/css-cache-buster=$COUNTER/css-cache-buster=$NEWCOUNTER/" app/_layouts/default.html | |
perl -pi -e "s/css-cache-buster=$COUNTER/css-cache-buster=$NEWCOUNTER/" app/_includes/custom-css.html | |
git config user.email "[email protected]" | |
git config user.name "GitHub Actions" | |
git add app/_layouts/default.html app/_includes/custom-css.html | |
git commit -m 'Increment CSS cache-buster [skip ci]' | |
git push origin develop || exit 1 | |
fi | |
JS_BUST=$(find build/assets/javascripts -type f -exec bash -c 'if [[ `diff {} <(curl -s "https://$LIVE_SITE/$(echo "{}" | cut -c 7-)")` ]]; then echo "bust ({})"; fi' \;) | |
if [[ $JS_BUST ]] ; then | |
COUNTER=`grep js-cache-buster app/_layouts/default.html | sed -r 's/.*js-cache-buster=([0-9]+).*/\1/'` | |
let NEWCOUNTER=$COUNTER+1 | |
perl -pi -e "s/js-cache-buster=$COUNTER/js-cache-buster=$NEWCOUNTER/" app/_layouts/default.html | |
perl -pi -e "s/js-cache-buster=$COUNTER/js-cache-buster=$NEWCOUNTER/" app/_includes/custom_scripts.html | |
git config user.email "[email protected]" | |
git config user.name "GitHub Actions" | |
git add app/_layouts/default.html app/_includes/custom-scripts.html | |
git commit -m 'Increment JS cache-buster [skip ci]' | |
git push origin develop || exit 1 | |
fi | |
export DEPLOY_CONTENT='{"GITHUB_RUN_NUMBER":"'$GITHUB_RUN_NUMBER'","GITHUB_SHA":"'$GITHUB_SHA'","GITHUB_REF":"'$GITHUB_REF'","GITHUB_REPOSITORY":"'$GITHUB_REPOSITORY'","GITHUB_ACTOR":"'$GITHUB_ACTOR'"}' ; | |
export DEPLOY_SIG="sha1=`echo -n "$DEPLOY_CONTENT" | openssl sha1 -hmac $DEPLOY_KEY | sed 's/^.* //'`" ; | |
curl -X POST "$DEPLOY_URL" --data "$DEPLOY_CONTENT" -H "Content-Type: application/json" -H "$DEPLOY_HEADER: $DEPLOY_SIG" ; |