-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (51 loc) · 1.83 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
with:
node-version: '20'
- name: Install dependencies
run: npm install uglify-js -g
- name: Verify script.js exists
run: ls -la script.js
- name: Minimize JavaScript
run: uglifyjs script.js -o script.min.js
- name: Verify script.min.js created
run: ls -la script.min.js
- name: Install AWS CLI
run: sudo apt-get install awscli -y
- name: Upload to DigitalOcean Spaces
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 script.min.js s3://${SPACE_NAME}/ --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: List CDN Endpoints
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DO_ACCESS_TOKEN }}
id: list-cdn
run: |
doctl compute cdn list
- name: Purge Cache
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DO_ACCESS_TOKEN }}
run: |
CDN_ID=$(doctl compute cdn list --no-header --format ID)
doctl compute cdn flush $CDN_ID --files /script.min.js