Update syncToR2.yml #12
  
    
      This file contains hidden or 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
    
  
  
    
  | name: 上传至cloudflare R2 | |
| on: | |
| push: | |
| jobs: | |
| upload: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials for Cloudflare R2 | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.CLOUDFLARE_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.CLOUDFLARE_SECRET_ACCESS_KEY }} | |
| - name: Get Branch Name and Set R2 Target Path | |
| id: set_path | |
| run: | | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| echo "R2_TARGET_PATH=${{ secrets.R2_PREFIX_DIR }}/$BRANCH_NAME" >> "$GITHUB_OUTPUT" | |
| echo "R2 target path will be: ${{ secrets.R2_PREFIX_DIR }}/$BRANCH_NAME" | |
| env: | |
| # 如果 R2_PREFIX_DIR 始终为空或您不希望使用它,可以考虑移除此 env 块 | |
| # 或者确保 R2_PREFIX_DIR 在您的 GitHub secrets 中定义为空字符串 | |
| R2_PREFIX_DIR: ${{ secrets.R2_PREFIX_DIR || '' }} # 优先使用 Secret,如果 Secret不存在则默认为空 | |
| - name: Upload to Cloudflare R2 | |
| run: | | |
| aws s3 sync . s3://${{ secrets.R2_BUCKET_NAME }}/${{ steps.set_path.outputs.R2_TARGET_PATH }}/ \ | |
| --endpoint-url=${{ secrets.R2_ENDPOINT_URL }} \ | |
| --delete \ | |
| --exclude ".git/*" \ | |
| --exclude ".github/*" \ | |
| --exclude "awscli-bundle/*" \ | |
| --exclude "awscli-bundle.zip" \ | |
| --exact-timestamps | |
| env: | |
| R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }} | |
| R2_ENDPOINT_URL: ${{ secrets.R2_ENDPOINT_URL }} |