v3.1.0 #18
Workflow file for this run
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: Sync Release Assets to CDN | |
| on: | |
| release: | |
| types: [published] | |
| env: | |
| SOURCE_REPO: ${{ github.repository }} | |
| CDN_REPO: "M3351AN/cdn" | |
| CDN_BRANCH: "main" | |
| jobs: | |
| sync-assets: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout Source Repo | |
| uses: actions/checkout@v4 | |
| - name: Get Release Tag | |
| id: get_release_tag | |
| run: echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT | |
| - name: Set Target Paths | |
| id: set_paths | |
| run: | | |
| SOURCE_REPO_NAME="${GITHUB_REPOSITORY#*/}" | |
| echo "source_repo_name=$SOURCE_REPO_NAME" >> $GITHUB_OUTPUT | |
| echo "target_path=$SOURCE_REPO_NAME/${{ steps.get_release_tag.outputs.tag_name }}" >> $GITHUB_OUTPUT | |
| - name: Checkout CDN Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ env.CDN_REPO }} | |
| token: ${{ secrets.CDN_REPO_TOKEN }} | |
| ref: ${{ env.CDN_BRANCH }} | |
| path: cdn-repo | |
| - name: Create Target Directory in CDN | |
| run: | | |
| mkdir -p "cdn-repo/${{ steps.set_paths.outputs.target_path }}" | |
| - name: Download and Copy Release Assets | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 用于API调用,默认可读当前仓库 | |
| run: | | |
| cd "cdn-repo/${{ steps.set_paths.outputs.target_path }}" | |
| echo "Downloading assets for release ${{ github.event.release.tag_name }}" | |
| ASSETS_URL="${{ github.event.release.assets_url }}" | |
| curl -s -H "Authorization: token $GITHUB_TOKEN" $ASSETS_URL | jq -r '.[] | select(.url != null) | .browser_download_url' | xargs -n1 curl -L -O -H "Authorization: token $GITHUB_TOKEN" | |
| - name: Commit and Push to CDN Repo | |
| run: | | |
| cd cdn-repo | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add . | |
| git commit -m "Add assets for ${{ steps.set_paths.outputs.source_repo_name }} release ${{ steps.get_release_tag.outputs.tag_name }}" | |
| git push "https://${{ github.actor }}:${{ secrets.CDN_REPO_TOKEN }}@github.com/${{ env.CDN_REPO }}.git" HEAD:${{ env.CDN_BRANCH }} |