-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (64 loc) · 2.71 KB
/
images-cdn.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: Upload Images to Tencent Cloud COS
on:
push:
branches:
- main
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: static/images/**
outputs:
changed: ${{ steps.changed-files.outputs.any_changed }}
files: ${{ steps.changed-files.outputs.all_changed_files }}
upload:
needs: check
if: ${{ needs.check.outputs.changed == 'true' }}
runs-on: ubuntu-latest
env:
SECRET_ID: ${{ secrets.TENCENT_CLOUD_SECRET_ID }}
SECRET_KEY: ${{ secrets.TENCENT_CLOUD_SECRET_KEY }}
COS_BUCKET: ${{ secrets.TENCENT_CLOUD_COS_BUCKET }}
COS_REGION: ${{ secrets.TENCENT_CLOUD_COS_REGION }}
COS_PATH: ${{ secrets.TENCENT_CLOUD_COS_PATH }}
CDN_URL_PREFIX: ${{ vars.TENCENT_CLOUD_CDN_URL_PREFIX }}
CHANGED_FILES: ${{ needs.check.outputs.files }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: pip Cache
uses: actions/cache@v4
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-images-cdn
- name: Install coscmd
run: pip install coscmd
- name: Authenticate With Tencent Cloud COS
run: coscmd config -a $SECRET_ID -s $SECRET_KEY -b $COS_BUCKET -r $COS_REGION
- name: Upload Changed Files to Tencent Cloud COS
run: |
for file in $CHANGED_FILES; do
coscmd upload $file $COS_PATH
done
- name: Install tccli
run: pip install tccli
- name: Authenticate With Tencent Cloud CLI
run: tccli configure set secretId $SECRET_ID secretKey $SECRET_KEY
- name: Split Urls
id: urls
shell: python
run: |
import os, json
filenames = [os.path.basename(path) for path in os.environ["CHANGED_FILES"].split()]
formatted = [f"{os.environ['CDN_URL_PREFIX']}{path}" for path in filenames]
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"json={json.dumps(formatted)}\n")
- name: Purge Tencent Cloud CDN Cache
run: tccli cdn PurgeUrlsCache --Urls "$(echo '${{ steps.urls.outputs.json }}')"