-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7240f36
commit 2f363e0
Showing
1 changed file
with
15 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,30 @@ | ||
name: Sync to OSS | ||
name: Deploy to Aliyun OSS | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: # 允许手动触发工作流 | ||
- main | ||
|
||
jobs: | ||
sync: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install oss2 | ||
run: pip install oss2 | ||
- name: Install OSS CLI | ||
run: | | ||
curl -o ossutil.zip https://gosspublic.alicdn.com/ossutil/1.7.0/ossutil64.zip | ||
unzip ossutil.zip | ||
sudo mv ossutil64 /usr/local/bin/ossutil | ||
chmod 755 /usr/local/bin/ossutil | ||
- name: Sync to OSS | ||
env: | ||
ALIYUN_ACCESS_KEY_ID: ${{ secrets.ALIYUN_ACCESS_KEY_ID }} | ||
ALIYUN_ACCESS_KEY_SECRET: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }} | ||
ALIYUN_OSS_BUCKET: ${{ secrets.ALIYUN_OSS_BUCKET }} | ||
ALIYUN_OSS_ENDPOINT: ${{ secrets.ALIYUN_OSS_ENDPOINT }} | ||
- name: Configure OSS CLI | ||
run: | | ||
python - <<EOF | ||
import oss2 | ||
import os | ||
from pathlib import Path | ||
ossutil config -e ${{ secrets.OSS_REGION }} -i ${{ secrets.ALIYUN_ACCESS_KEY_ID }} -k ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }} | ||
# Initialize OSS client | ||
auth = oss2.Auth(os.getenv('ALIYUN_ACCESS_KEY_ID'), os.getenv('ALIYUN_ACCESS_KEY_SECRET')) | ||
bucket = oss2.Bucket(auth, os.getenv('ALIYUN_OSS_ENDPOINT'), os.getenv('ALIYUN_OSS_BUCKET')) | ||
- name: Sync files to OSS | ||
run: | | ||
ossutil rsync ./ oss://${{ secrets.OSS_BUCKET }}/ --delete | ||
# Sync files | ||
local_path = Path('.') | ||
for file in local_path.rglob('*'): | ||
if file.is_file(): | ||
bucket.put_object_from_file(str(file.relative_to(local_path)), str(file)) | ||
print(f'Synced {file} to OSS') | ||
EOF |