From b7cfbb298a415e79685e78ee75957889a2424ece Mon Sep 17 00:00:00 2001 From: sangge <2251250136@qq.com> Date: Wed, 9 Jul 2025 14:15:54 +0800 Subject: [PATCH] feat: Deprecate qiniu. Use S3 capable api --- README.md | 4 ++-- requirements.txt | 2 +- scripts/install_zola.py | 32 ++++++++++++++++++-------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ace72b8..00a830d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # setup-zola This action sets up Zola static site generator in your GitHub Actions workflow. -It supports downloading Zola from any S3-compatible storage service. +It supports downloading Zola from S3-compatible storage services including AWS S3, Cloudflare R2, MinIO, and others. ## Usage @@ -13,7 +13,7 @@ Basic usage: version: "0.19.2" # Optional, defaults to 0.19.2 access_key: ${{ secrets.S3_ACCESS_KEY }} # Required secret_key: ${{ secrets.S3_SECRET_KEY }} # Required - endpoint: "https://your-s3-endpoint.com" # Required + endpoint: "https://your-s3-endpoint.com" # Required (e.g., for R2: https://accountid.r2.cloudflarestorage.com) bucket: ${{ secrets.S3_BUCKET }} # Required ``` diff --git a/requirements.txt b/requirements.txt index eb2df86..6a90e33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ python-dotenv requests -qiniu +boto3 diff --git a/scripts/install_zola.py b/scripts/install_zola.py index 1ac7634..3cf4a21 100644 --- a/scripts/install_zola.py +++ b/scripts/install_zola.py @@ -2,8 +2,8 @@ import os import sys from dotenv import load_dotenv import shutil -import requests -from qiniu import Auth +import boto3 +from botocore.exceptions import ClientError def install_zola(): @@ -11,26 +11,30 @@ def install_zola(): access_key = os.environ["INPUT_ACCESS_KEY"] secret_key = os.environ["INPUT_SECRET_KEY"] endpoint = os.environ["INPUT_ENDPOINT"] - bucket = "omybucket" + bucket = os.environ["INPUT_BUCKET"] zola_filename = "zola-" + version try: - q = Auth(access_key, secret_key) - base_url = "%s/%s" % (endpoint, zola_filename) - private_url = q.private_download_url(base_url, expires=3600) - response = requests.get(private_url) + # Create S3 client for S3-compatible storage + s3_client = boto3.client( + 's3', + aws_access_key_id=access_key, + aws_secret_access_key=secret_key, + endpoint_url=endpoint + ) - if response.status_code == 200: - # 将文件内容保存到本地 - with open(zola_filename, "wb") as f: - f.write(response.content) - print("文件下载成功!") - else: - raise Exception(f"下载失败: {response.status_code}") + # Download file from S3-compatible storage + s3_client.download_file(bucket, zola_filename, zola_filename) + print("文件下载成功!") + # Install zola binary shutil.copy(zola_filename, "/usr/local/bin/zola") os.chmod("/usr/local/bin/zola", 0o755) + print("Zola 安装成功!") + except ClientError as e: + print(f"S3 Error: {str(e)}") + sys.exit(1) except Exception as e: print(f"Error: {str(e)}") sys.exit(1)