Last active 1752049019

通过Python,在Github Action中实现EO站点缓存刷新

action.yml Raw
1
2 refresh:
3 needs: deploy # 仅在 deploy 成功后执行
4 runs-on: ubuntu-latest
5 steps:
6 - uses: actions/checkout@v4
7 - uses: szenius/set-timezone@v1.0 # 设置执行环境的时区
8 with:
9 timezoneLinux: "Asia/Shanghai"
10 - name: Set up Python 3.12
11 uses: actions/setup-python@v5
12 with:
13 python-version: "3.12"
14 - name: Run refresh script
15 env:
16 # DOGECLOUD_ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
17 # DOGECLOUD_SECRET_KEY: ${{ secrets.SECRET_KEY }}
18 TENCENTCLOUD_SECRET_ID: ${{ secrets.TENCENTCLOUD_SECRET_ID }}
19 TENCENTCLOUD_SECRET_KEY: ${{ secrets.TENCENTCLOUD_SECRET_KEY }}
20 run: |
21 # pip install requests
22 # python .github/scripts/refresh-dogecloud.py
23 pip install tencentcloud-sdk-python
24 python .github/scripts/refresh-eo.py
25
26
refresh-eo.py Raw
1import os
2import json
3from tencentcloud.common import credential
4from tencentcloud.teo.v20220901 import teo_client, models
5from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
6
7try:
8 cred = credential.Credential(
9 os.getenv("TENCENTCLOUD_SECRET_ID"),
10 os.getenv("TENCENTCLOUD_SECRET_KEY")
11 )
12 client = teo_client.TeoClient(cred, "")
13
14 req = models.CreatePurgeTaskRequest()
15 req.from_json_string(json.dumps({
16 "ZoneId": "zone-*************",
17 "Type": "purge_prefix",
18 "Targets": [
19 "https://blog.liushen.fun/"
20 ]
21 }))
22
23 resp = client.CreatePurgeTask(req)
24 print(resp.to_json_string(indent=2))
25
26except TencentCloudSDKException as err:
27 print("刷新失败:", err)
28