Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new CDN workflow for Basalt #29

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Deploy

on:
push:
branches: [ mega ]
branches:
- mega

env:
BUCKET_PATH: theme/en/basalt
Expand All @@ -12,39 +13,51 @@ jobs:
name: Deploy CSS
runs-on: ubuntu-latest

permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install dependencies
run: npm ci

- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Build
run: ./build.sh

- name: Deploy (GitHub Pages)
uses: JamesIves/github-pages-deploy-action@4.1.4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
branch: gh-pages
folder: dist
path: dist/

- name: Deploy (S3)
uses: emmiegit/s3-sync-action@main
with:
args: --delete
- name: Deploy (GitHub Pages)
uses: actions/deploy-pages@v4
id: deployment

- name: Upload to S3
run: |
export sync_args=( "--delete" "--acl" "public-read" "dist" "s3://${{ vars.AWS_S3_BUCKET }}/${{ env.BUCKET_PATH }}" )
# Manually set content-types for anything aws-cli can't guess correctly
aws s3 sync ${sync_args[@]} --exclude "*" --include "*.css" --content-type "text/css; charset=utf-8"
aws s3 sync ${sync_args[@]} --exclude "*.css"
env:
AWS_S3_BUCKET: ${{ vars.AWS_S3_BUCKET }}
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE_DIR: dist
DEST_DIR: ${{ env.BUCKET_PATH }}
AWS_ENDPOINT_URL: 'https://${{ vars.DIGITALOCEAN_SPACES_REGION }}.digitaloceanspaces.com'
AWS_DEFAULT_REGION: 'us-east-1'

- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
- name: Invalidate Spaces Cache
run: doctl compute cdn flush $DIGITALOCEAN_CDN_ID
env:
DISTRIBUTION: ${{ secrets.CF_DISTRIBUTION }}
PATHS: /${{ env.BUCKET_PATH }}/ /${{ env.BUCKET_PATH }}/*
AWS_REGION: ${{ vars.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DIGITALOCEAN_CDN_ID: ${{ vars.DIGITALOCEAN_CDN_ID }}