Merge pull request #1 from reallygreatads/feat/improved-integration #19
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: Minimize and Publish | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
- name: Install dependencies | |
run: npm install | |
- name: Build project | |
run: npm run build | |
- name: Install AWS CLI | |
run: sudo apt-get install awscli -y | |
- name: Upload /assets/ files to DigitalOcean Space root | |
env: | |
DO_SPACES_KEY: ${{ secrets.DO_SPACES_KEY }} | |
DO_SPACES_SECRET: ${{ secrets.DO_SPACES_SECRET }} | |
SPACE_NAME: cdn.reallygreatads.com | |
SPACE_REGION: sfo3 | |
run: | | |
aws configure set aws_access_key_id $DO_SPACES_KEY | |
aws configure set aws_secret_access_key $DO_SPACES_SECRET | |
aws s3 cp dist/assets/ s3://${SPACE_NAME}/ --recursive --region ${SPACE_REGION} --endpoint https://${SPACE_REGION}.digitaloceanspaces.com --acl public-read | |
- name: Install DigitalOcean CLI | |
run: | | |
curl -sL https://github.com/digitalocean/doctl/releases/download/v1.91.0/doctl-1.91.0-linux-amd64.tar.gz | tar -xzv | |
sudo mv doctl /usr/local/bin | |
- name: Purge Cache for files in root | |
env: | |
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DO_ACCESS_TOKEN }} | |
run: | | |
CDN_ID=$(doctl compute cdn list --no-header --format ID) | |
FILES_TO_PURGE=$(aws s3 ls s3://${SPACE_NAME}/ --recursive | awk '{print $4}') | |
for file in $FILES_TO_PURGE; do | |
doctl compute cdn flush $CDN_ID --files /$file | |
done |