Update jpig from 0.0.13 to 0.0.14 #356
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: Build, Deploy, and Index site | |
on: | |
push: | |
branches: | |
- 'staging' | |
- 'main' | |
pull_request: | |
branches: | |
- 'staging' | |
- 'main' | |
concurrency: | |
group: ${{ format('{0}-{1}', github.workflow, github.ref) }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: Build the site | |
runs-on: ubuntu-latest | |
steps: | |
- name: Token configuration (PAT available) | |
if: github.ref_name == 'main' || github.ref_name == 'staging' | |
run: | | |
echo "PAT=${{ secrets.IMAGE_BOT_PAT }}" >> $GITHUB_ENV | |
- name: Token configuration (PAT unavailable) | |
if: github.ref_name != 'main' && github.ref_name != 'staging' | |
run: | | |
echo "PAT=${{ github.token }}" >> $GITHUB_ENV | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ env.PAT }} | |
- name: Staging site configuration | |
if: github.ref_name != 'main' | |
run: | | |
echo "XARGS=--drafts" >> $GITHUB_ENV | |
echo 'User-agent: * Disallow: /' > ${{ github.workspace }}/robots.txt | |
sed -i 's_blog.sebsscholarship.org_test.blog.sebsscholarship.org_g' ${{ github.workspace }}/_config.yml | |
- name: Load Gem Cache | |
uses: actions/cache/restore@v4 | |
id: gem-cache | |
with: | |
key: gem-cache-${{ hashFiles('Gemfile.lock') }} | |
path: _vendor/ | |
restore-keys: gem-cache- | |
- name: Build site | |
run: | | |
docker compose run \ | |
-v ${{ github.workspace }}:/srv/jekyll -v ${{ github.workspace }}/_vendor/bundle:/usr/local/bundle -v ${{ github.workspace }}/_vendor/gem:/usr/gem \ | |
jekyll-serve /bin/bash -c \ | |
"chmod 777 /srv/jekyll \ | |
&& chmod 777 /srv/jekyll/assets/images \ | |
&& jekyll build --future ${{ env.XARGS }}" | |
- name: Save Gems to Cache | |
uses: actions/cache/save@v4 | |
if: steps.gem-cache.outputs.cache-hit != 'true' | |
with: | |
key: ${{ steps.gem-cache.outputs.cache-primary-key }} | |
path: _vendor/ | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Built Site | |
path: ${{ github.workspace }}/_site/ | |
- name: GitHub Pages Artifact | |
uses: actions/upload-pages-artifact@v3 | |
if: github.ref_name == 'main' | |
- name: Commit images | |
if: github.ref_name == 'main' || github.ref_name == 'staging' | |
run: | | |
git config core.fileMode false | |
git config --global user.name 'SSF Image Bot' | |
git config --global user.email '[email protected]' | |
git add assets/images/ | |
((git commit -m "bot: Add newly generated images" && git push) || true) | |
deploy-staging: | |
name: Deploy the staging site | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
if: github.ref_name == 'staging' | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: Built Site | |
path: _site/ | |
- name: Install SSH key | |
if: github.ref_name == 'staging' | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Trust SSH key | |
if: github.ref_name == 'staging' | |
run: ssh-keyscan sebsscholarship.org > ~/.ssh/known_hosts | |
- name: Deploy Staging | |
if: github.ref_name == 'staging' | |
run: | | |
scp -r ${{ github.workspace }}/_site/* ${{ secrets.USERNAME }}@sebsscholarship.org:~/staging/ | |
ssh ${{ secrets.USERNAME }}@sebsscholarship.org 'rm -rf ~/test.blog.sebsscholarship.org/* \ | |
&& mv ~/staging/* ~/test.blog.sebsscholarship.org/' | |
deploy-prod: | |
name: Deploy the production site | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
if: github.ref_name == 'main' | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
index: | |
name: Index the site | |
runs-on: ubuntu-latest | |
needs: | |
- deploy-staging | |
- deploy-prod | |
# Only index if deploy completes successfully | |
if: always() && (needs.deploy-staging.result == 'success' || needs.deploy-prod.result == 'success') | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Staging site configuration | |
if: github.ref_name != 'main' | |
run: | | |
echo "XARGS=--drafts" >> $GITHUB_ENV | |
echo 'User-agent: * Disallow: /' > ${{ github.workspace }}/robots.txt | |
sed -i 's_blog.sebsscholarship.org_test.blog.sebsscholarship.org_g' ${{ github.workspace }}/_config.yml | |
- name: Load Gem Cache | |
uses: actions/cache/restore@v4 | |
id: gem-cache | |
with: | |
key: gem-cache-${{ hashFiles('Gemfile.lock') }} | |
path: _vendor/ | |
restore-keys: gem-cache- | |
- name: Index site | |
run: | | |
docker compose run \ | |
-v ${{ github.workspace }}:/srv/jekyll -v ${{ github.workspace }}/_vendor/bundle:/usr/local/bundle -v ${{ github.workspace }}/_vendor/gem:/usr/gem \ | |
jekyll-serve /bin/bash -c \ | |
"chmod 777 /srv/jekyll \ | |
&& chmod 777 /srv/jekyll/assets/images \ | |
&& ALGOLIA_API_KEY='${{ secrets.ALGOLIA_KEY }}' jekyll algolia --future ${{ env.XARGS }}" | |
notify: | |
name: Send job complete notification | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
- deploy-staging | |
- deploy-prod | |
- index | |
# Run if on staging or main | |
if: always() && (github.ref_name == 'staging' || github.ref_name == 'main') | |
steps: | |
- name: Set test environment | |
if: github.ref_name == 'staging' | |
run: | | |
echo "SITE_NAME=test" >> $GITHUB_ENV | |
echo "SITE_ADDR=https://test.blog.sebsscholarship.org" >> $GITHUB_ENV | |
- name: Set main environment | |
if: github.ref_name == 'main' | |
run: | | |
echo "SITE_NAME=main" >> $GITHUB_ENV | |
echo "SITE_ADDR=https://blog.sebsscholarship.org" >> $GITHUB_ENV | |
- name: Notify on success | |
# If the site was successfully built and indexed and deployed if staging | |
if: needs.build.result == 'success' && (needs.deploy-staging.result == 'success' || needs.deploy-prod.result == 'success') && needs.index.result == 'success' | |
uses: appleboy/[email protected] | |
with: | |
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} | |
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} | |
color: "#800000" | |
username: "SSF Blog Status Bot" | |
message: > | |
Updates were successfully pushed to ${{ env.SITE_NAME }} blog: | |
${{ env.SITE_ADDR }} | |
- name: Notify on failure | |
# If the site failed at any point | |
if: needs.build.result == 'failure' || needs.deploy-staging.result == 'failure' || needs.deploy-prod.result == 'failure' || needs.index.result == 'failure' | |
uses: appleboy/[email protected] | |
with: | |
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} | |
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} | |
color: "#800000" | |
username: "SSF Blog Status Bot" | |
message: > | |
Aborting ${{ env.SITE_NAME }} blog deployment due to unexpected error: | |
https://github.com/sebs-scholarship/Blog/actions/runs/${{ github.run_id }} |