From d679f8983fefdb885bc2d015d42baac8f4c5648d Mon Sep 17 00:00:00 2001 From: lzt404 <2596933790@qq.com> Date: Wed, 5 Aug 2026 17:15:40 +0800 Subject: [PATCH] ci(release): isolate GitCode mirroring workflow --- .github/workflows/gitcode-mirror.yml | 84 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 14 +---- 2 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/gitcode-mirror.yml diff --git a/.github/workflows/gitcode-mirror.yml b/.github/workflows/gitcode-mirror.yml new file mode 100644 index 0000000..a7cc1c5 --- /dev/null +++ b/.github/workflows/gitcode-mirror.yml @@ -0,0 +1,84 @@ +name: Mirror GitHub release to GitCode + +run-name: >- + GitCode mirror ${{ inputs.release_tag || github.event.workflow_run.display_title }} + +on: + workflow_run: + workflows: + - Build portable releases + types: + - completed + workflow_dispatch: + inputs: + release_tag: + description: Existing GitHub release tag to mirror + required: true + type: string + +permissions: + contents: read + +concurrency: + group: gitcode-mirror-${{ inputs.release_tag || github.event.workflow_run.id }} + cancel-in-progress: false + +jobs: + mirror: + name: Mirror release assets + if: >- + vars.GITCODE_REPOSITORY != '' + && ( + github.event_name == 'workflow_dispatch' + || github.event.workflow_run.conclusion == 'success' + ) + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: + - uses: actions/checkout@v7 + - name: Resolve release tag + id: release + shell: bash + env: + INPUT_RELEASE_TAG: ${{ inputs.release_tag }} + RUN_TITLE: ${{ github.event.workflow_run.display_title }} + run: | + set -euo pipefail + + release_tag="$INPUT_RELEASE_TAG" + if [ -z "$release_tag" ]; then + case "$RUN_TITLE" in + "Portable release "*) release_tag="${RUN_TITLE#Portable release }" ;; + *) echo "Cannot resolve a release tag from workflow title: $RUN_TITLE" >&2; exit 1 ;; + esac + fi + case "$release_tag" in + v*) ;; + *) release_tag="v$release_tag" ;; + esac + if ! node scripts/app-version.mjs "${release_tag#v}" >/dev/null 2>&1; then + if [ -n "$INPUT_RELEASE_TAG" ]; then + echo "Invalid release tag: $release_tag" >&2 + exit 1 + fi + echo "Skipping GitCode mirror because the completed run did not publish a release" + echo "should_mirror=false" >> "$GITHUB_OUTPUT" + exit 0 + fi + echo "tag=$release_tag" >> "$GITHUB_OUTPUT" + echo "should_mirror=true" >> "$GITHUB_OUTPUT" + - name: Download GitHub release assets + if: steps.release.outputs.should_mirror == 'true' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: gh release download "${{ steps.release.outputs.tag }}" --dir artifacts + - name: Publish GitCode mirror + if: steps.release.outputs.should_mirror == 'true' + env: + ARTIFACT_DIRECTORY: artifacts + GITCODE_ACCESS_TOKEN: ${{ secrets.GITCODE_ACCESS_TOKEN }} + GITCODE_REPOSITORY: ${{ vars.GITCODE_REPOSITORY }} + GITCODE_TARGET_COMMITISH: ${{ vars.GITCODE_TARGET_COMMITISH || 'main' }} + RELEASE_TAG: ${{ steps.release.outputs.tag }} + run: node scripts/publish-gitcode-release.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index accc965..f6b4e4b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -391,7 +391,7 @@ jobs: if-no-files-found: error retention-days: 14 publish: - name: Publish releases + name: Publish GitHub release if: >- (github.event_name == 'release' && github.event.release.prerelease == true) || startsWith(github.ref, 'refs/tags/') @@ -400,7 +400,7 @@ jobs: - version - build runs-on: ubuntu-24.04 - timeout-minutes: 30 + timeout-minutes: 15 steps: - uses: actions/checkout@v7 with: @@ -461,13 +461,3 @@ jobs: else gh release create "$RELEASE_TAG" "${release_args[@]}" artifacts/* fi - - name: Publish GitCode mirror - if: ${{ vars.GITCODE_REPOSITORY != '' }} - env: - ARTIFACT_DIRECTORY: artifacts - GITCODE_ACCESS_TOKEN: ${{ secrets.GITCODE_ACCESS_TOKEN }} - GITCODE_REPOSITORY: ${{ vars.GITCODE_REPOSITORY }} - GITCODE_TARGET_COMMITISH: ${{ vars.GITCODE_TARGET_COMMITISH || 'main' }} - PRERELEASE: ${{ github.event_name == 'release' && github.event.release.prerelease || inputs.prerelease }} - RELEASE_TAG: ${{ needs.version.outputs.tag }} - run: node scripts/publish-gitcode-release.mjs