Skip to content

Commit

Permalink
CI自动上传cos
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Oct 25, 2023
1 parent 22e8c8d commit e3e179c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/uploadDeckResourceCos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: uploadDeckResourceCos
on:
workflow_dispatch:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
env:
PACK_NAME: ""
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.11.0
cache: pip
architecture: x64
- name: Run
run: |
cd ./script/
python -m pip install --upgrade pip
python -m pip install -U cos-python-sdk-v5
python uploadDeckResourceCos.py ${{ secrets.EXTIVERSECOSSECRETID }} ${{ secrets.EXTIVERSECOSSECRETKEY }}
69 changes: 69 additions & 0 deletions script/uploadDeckResourceCos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client
from qcloud_cos import CosServiceError
from qcloud_cos import CosClientError
import sys
import logging
import requests as req
import os

g_secret_id = ''
g_secret_key = ''
g_region = 'ap-shanghai'
g_Bucket = 'extiverse-1253866028'

if len(sys.argv) >= 2:
g_secret_id = sys.argv[1]
if len(sys.argv) >= 3:
g_secret_key = sys.argv[2]

def GETHttpFile(url, path):
res = False
send_url = url
headers = {}
try:
msg_res = req.request("GET", send_url, headers = headers)
with open(path, 'wb+') as tmp:
tmp.write(msg_res.content)
if msg_res.status_code in [200, 300]:
res = True
else:
res = False
except:
res = False
return res

def upload(src, dst):
global g_secret_id, g_secret_key, g_region, g_Bucket
secret_id = g_secret_id
secret_key = g_secret_key
region = g_region
token = None
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token)
client = CosS3Client(config)
object_key = dst
with open(src, 'rb') as fp:
response = client.put_object(
Bucket=g_Bucket,
Body=fp,
Key=object_key,
EnableMD5=True,
StorageClass='STANDARD',
ContentType='text/html; charset=utf-8'
)
print(response['ETag'])

logging.basicConfig(level=logging.INFO, stream=sys.stdout)

def file_name(file_dir):
res = []
for root,dirs,files in os.walk(file_dir):
for file in files:
res.append(os.path.join(root.lstrip(file_dir), file))
return res

if __name__ == '__main__':
res = file_name('../deck/')
for res_this in res:
print(res_this)
upload(os.path.join('..', 'deck', res_this), os.path.join('deck', res_this).replace('\\', '/'))

0 comments on commit e3e179c

Please sign in to comment.