Bump webfactory/ssh-agent from 0.8.0 to 0.9.0 (#193) #249
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: Lint, Build, Deploy, and Index site | |
on: | |
push: | |
branches: | |
- 'staging' | |
- 'main' | |
pull_request: | |
branches: | |
- 'staging' | |
- 'main' | |
concurrency: | |
group: ${{ format('{0}-{1}', github.job, github.ref) }} | |
cancel-in-progress: true | |
jobs: | |
lint: | |
name: Lint the source | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Lint Code Base | |
uses: docker://ghcr.io/github/super-linter:slim-v4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
VALIDATE_YAML: true | |
VALIDATE_XML: true | |
VALIDATE_BASH: true | |
VALIDATE_PHP: true | |
VALIDATE_JAVASCRIPT_STANDARD: true | |
VALIDATE_CSS: true | |
build: | |
name: Build the site | |
runs-on: ubuntu-latest | |
needs: | |
- lint | |
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_sebsscholarship.org_test.sebsscholarship.org_g' ${{ github.workspace }}/_config.yml | |
- name: Install Composer dependencies | |
run: | | |
docker run --rm \ | |
-v ${{ github.workspace }}:/app \ | |
composer:2 install -n | |
- name: Build site | |
run: | | |
docker run -v ${{ github.workspace }}:/srv/jekyll jekyll/builder:4.2.2 /bin/bash -c \ | |
"bundle install && chmod 777 /srv/jekyll && bundle exec jekyll build --future ${{ env.XARGS }}" | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Built Site | |
path: ${{ github.workspace }}/_site/ | |
deploy: | |
name: Deploy the site | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
# Only deploy if on the staging or main branch | |
if: github.ref_name == 'staging' || github.ref_name == 'main' | |
steps: | |
- name: Set test environment | |
if: github.ref_name == 'staging' | |
run: | | |
echo "SITE_USER=${{ secrets.TEST_SSH_USER }}" >> $GITHUB_ENV | |
echo "SITE_KEY<<EOF" >> $GITHUB_ENV | |
echo "${{ secrets.TEST_SSH_KEY }}" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
echo "SITE_DIR=test.sebsscholarship.org" >> $GITHUB_ENV | |
- name: Set main environment | |
if: github.ref_name == 'main' | |
run: | | |
echo "SITE_USER=${{ secrets.PROD_SSH_USER }}" >> $GITHUB_ENV | |
echo "SITE_KEY<<EOF" >> $GITHUB_ENV | |
echo "${{ secrets.PROD_SSH_KEY }}" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
echo "SITE_DIR=sebsscholarship.org" >> $GITHUB_ENV | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: Built Site | |
path: _site/ | |
- name: Install SSH key | |
uses: webfactory/ssh-agent@v0.9.0 | |
with: | |
ssh-private-key: ${{ env.SITE_KEY }} | |
- name: Trust SSH key | |
run: ssh-keyscan sebsscholarship.org > ~/.ssh/known_hosts | |
- name: Deploy | |
run: | | |
scp -r ${{ github.workspace }}/_site/* ${{ env.SITE_USER }}@sebsscholarship.org:~/staging/ | |
ssh ${{ env.SITE_USER }}@sebsscholarship.org 'rm -rf ~/${{ env.SITE_DIR }}/* \ | |
&& mv ~/staging/* ~/${{ env.SITE_DIR }}/' | |
notify: | |
name: Send job complete notification | |
runs-on: ubuntu-latest | |
needs: | |
- lint | |
- build | |
- deploy | |
# 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.sebsscholarship.org" >> $GITHUB_ENV | |
- name: Set main environment | |
if: github.ref_name == 'main' | |
run: | | |
echo "SITE_NAME=main" >> $GITHUB_ENV | |
echo "SITE_ADDR=https://sebsscholarship.org" >> $GITHUB_ENV | |
- name: Notify on success | |
# If the site was successfully built and indexed | |
if: needs.lint.result == 'success' && needs.build.result == 'success' && needs.deploy.result == 'success' | |
uses: appleboy/discord-action@v1.0.0 | |
with: | |
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} | |
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} | |
color: "#800000" | |
username: "SSF Website Status Bot" | |
message: > | |
Updates were successfully pushed to ${{ env.SITE_NAME }} site: | |
${{ env.SITE_ADDR }} | |
- name: Notify on failure | |
# If the site failed at any point | |
if: needs.lint.result == 'failure' || needs.build.result == 'failure' || needs.deploy.result == 'failure' | |
uses: appleboy/discord-action@v1.0.0 | |
with: | |
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }} | |
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }} | |
color: "#800000" | |
username: "SSF Website Status Bot" | |
message: > | |
Aborting ${{ env.SITE_NAME }} site deployment due to unexpected error: | |
https://github.com/sebs-scholarship/Website/actions/runs/${{ github.run_id }} |