Mirror GitHub Releases #7
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: Mirror GitHub Releases | |
| on: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - ".github/workflows/mirror-sync.yml" | |
| - ".bun-version" | |
| - "bun.lock" | |
| - "mirror.config.json" | |
| - "package.json" | |
| - "src/**" | |
| - "tsconfig.json" | |
| schedule: | |
| - cron: "0 17 * * 0" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: mirror-sync | |
| cancel-in-progress: false | |
| jobs: | |
| plan: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has_tasks: ${{ steps.plan.outputs.has_tasks }} | |
| task_count: ${{ steps.plan.outputs.task_count }} | |
| tasks_json: ${{ steps.plan.outputs.tasks_json }} | |
| steps: | |
| - name: Checkout master | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Set up Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Plan mirror tasks | |
| id: plan | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: | | |
| bun run src/cli.ts plan \ | |
| --config mirror.config.json \ | |
| --mode "${{ github.event_name }}" \ | |
| --github-output "$GITHUB_OUTPUT" | |
| sync: | |
| runs-on: ubuntu-latest | |
| needs: plan | |
| if: needs.plan.outputs.has_tasks == 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(needs.plan.outputs.tasks_json) }} | |
| steps: | |
| - name: Checkout master | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Set up Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Download release assets | |
| id: download | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| GITHUB_TOKEN: ${{ github.token }} | |
| run: | | |
| bun run src/cli.ts download \ | |
| --owner "${{ matrix.owner }}" \ | |
| --repo "${{ matrix.repo }}" \ | |
| --tag "${{ matrix.tag }}" \ | |
| --output-root ".mirror-work/assets" \ | |
| --github-output "$GITHUB_OUTPUT" | |
| - name: Upload to SiFli COS | |
| uses: OpenSiFli/SiFliMirrorSync@v1 | |
| with: | |
| secret_id: ${{ secrets.COS_DOWNLOAD_SECRET_ID }} | |
| secret_key: ${{ secrets.COS_DOWNLOAD_SECRET_KEY }} | |
| region: ${{ secrets.COS_DOWNLOAD_REGION }} | |
| bucket: ${{ secrets.COS_DOWNLOAD_BUCKET }} | |
| prefix: ${{ steps.download.outputs.prefix }} | |
| artifacts: . | |
| delete_remote: true | |
| flush_url: ${{ matrix.flushUrl || '' }} | |
| working_directory: ${{ steps.download.outputs.download_directory }} | |
| global: true | |
| commit-state: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - plan | |
| - sync | |
| if: needs.plan.outputs.has_tasks == 'true' && needs.sync.result == 'success' | |
| steps: | |
| - name: Checkout master | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| fetch-depth: 0 | |
| - name: Set up Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| - name: Rebase on latest master | |
| run: git pull --rebase origin master | |
| - name: Apply synced tags to config | |
| id: apply-state | |
| env: | |
| TASKS_JSON: ${{ needs.plan.outputs.tasks_json }} | |
| run: | | |
| bun run src/cli.ts apply-state \ | |
| --config mirror.config.json \ | |
| --tasks-json "$TASKS_JSON" \ | |
| --write \ | |
| --github-output "$GITHUB_OUTPUT" | |
| - name: Commit updated config | |
| if: steps.apply-state.outputs.config_changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add mirror.config.json | |
| git commit -m "chore: update mirrored release tags [skip ci]" | |
| git push origin HEAD:master |