blog post: https://github.com/metanorma/metanorma.org/issues/821 #735
Workflow file for this run
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 | |
on: | |
push: | |
branches: | |
- main | |
- staging | |
pull_request: | |
repository_dispatch: | |
workflow_dispatch: | |
jobs: | |
set_environment: | |
outputs: | |
my_env: ${{ steps.setenv.outputs.my_env }} | |
my_url: ${{ steps.setenv.outputs.my_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- id: setenv | |
run: | | |
if [ "$GITHUB_REF" = "refs/heads/main" ] | |
then | |
echo "::set-output name=my_env::production" | |
echo "::set-output name=my_url::https://www.metanorma.org" | |
elif [ "$GITHUB_REF" = "refs/heads/staging" ] | |
then | |
echo "::set-output name=my_env::staging" | |
echo "::set-output name=my_url::https://staging-www.metanorma.org" | |
fi | |
build: | |
name: Build site | |
runs-on: ubuntu-latest | |
needs: set_environment | |
environment: | |
name: ${{ needs.set_environment.outputs.my_env }} | |
url: ${{ needs.set_environment.outputs.my_url }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: unfor19/install-aws-cli-action@v1 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '14' | |
- uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: '3.1' | |
bundler-cache: true | |
- name: Build site | |
env: | |
JEKYLL_ENV: production | |
run: | | |
make _site | |
zip -r site.zip _site | |
- name: Upload site | |
uses: actions/upload-artifact@v3 | |
with: | |
name: site.zip | |
path: site.zip | |
retention-days: 1 | |
deploy: | |
name: Deploy to ${{ needs.set_environment.outputs.my_env }} | |
needs: | |
- set_environment | |
- build | |
runs-on: ubuntu-latest | |
if: ${{ needs.set_environment.outputs.my_env != '' }} | |
environment: | |
name: ${{ needs.set_environment.outputs.my_env }} | |
url: ${{ needs.set_environment.outputs.my_url }} | |
steps: | |
- name: Download site | |
uses: actions/download-artifact@v4.1.7 | |
with: | |
name: site.zip | |
path: . | |
- name: Unzip | |
run: unzip site.zip | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Deploy to AWS | |
env: | |
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} | |
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} | |
run: | | |
aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.html" --content-type "text/html; charset=utf-8" | |
aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.json" --content-type "text/json; charset=utf-8" | |
aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*.html,*.json" --include "*" | |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" |