name: 发布正式版本 on: push: tags: - 'v*.*.*' permissions: contents: write packages: write concurrency: group: release-${{ github.ref }} cancel-in-progress: false jobs: prepare: name: 校验正式版本 runs-on: ubuntu-24.04 outputs: app_version: ${{ steps.version.outputs.app_version }} steps: - name: 检出完整 Git 历史 uses: actions/checkout@v6 with: fetch-depth: 0 - name: 校验标签、来源与版本顺序 id: version shell: bash run: | set -Eeuo pipefail if [[ ! "$GITHUB_REF_NAME" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then echo "正式版本标签必须符合 v1.2.3 格式:$GITHUB_REF_NAME" >&2 exit 1 fi git fetch origin main --no-tags if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then echo "正式版本标签必须指向 main 已包含的提交。" >&2 exit 1 fi newest_tag="$(git tag --list | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)" if [ "$newest_tag" != "$GITHUB_REF_NAME" ]; then echo "拒绝用旧版本 $GITHUB_REF_NAME 覆盖 latest;当前最高版本是 $newest_tag。" >&2 exit 1 fi echo "app_version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" desktop: name: 构建桌面端安装包 needs: prepare uses: ./.github/workflows/desktop-cd.yml with: app_version: ${{ needs.prepare.outputs.app_version }} secrets: inherit docker: name: 构建 Docker 镜像 needs: prepare uses: ./.github/workflows/docker-publish.yml with: app_version: ${{ needs.prepare.outputs.app_version }} secrets: inherit publish: name: 审批并发布正式版本 needs: - prepare - desktop - docker runs-on: ubuntu-24.04 environment: name: production-release steps: - name: 下载全部构建产物 uses: actions/download-artifact@v8 with: pattern: ydisks-* path: dist/artifacts merge-multiple: true - name: 校验桌面产物并生成校验和 shell: bash env: APP_VERSION: ${{ needs.prepare.outputs.app_version }} run: | set -Eeuo pipefail mkdir -p dist/release dist/digests find dist/artifacts -maxdepth 1 -type f -name '*.tar.gz' -exec cp {} dist/release/ \; find dist/artifacts -maxdepth 1 -type f -name '*.exe' -exec cp {} dist/release/ \; find dist/artifacts -maxdepth 1 -type f -name '*.pkg' -exec cp {} dist/release/ \; find dist/artifacts -maxdepth 1 -type f -regex '.*/[0-9a-f]\{64\}' -exec cp {} dist/digests/ \; test -f "dist/release/ydisks-xianyu-helper-linux-amd64-$APP_VERSION.tar.gz" test -f "dist/release/ydisks-xianyu-helper-linux-arm64-$APP_VERSION.tar.gz" test -f "dist/release/Ydisks-Xianyu-Helper-Setup.exe" test -f "dist/release/Ydisks-Xianyu-Helper-$APP_VERSION-arm64.pkg" test -f "dist/release/Ydisks-Xianyu-Helper-$APP_VERSION-amd64.pkg" test "$(find dist/release -maxdepth 1 -type f | wc -l)" -eq 5 test "$(find dist/digests -maxdepth 1 -type f | wc -l)" -eq 2 (cd dist/release && sha256sum * > SHA256SUMS) - name: 配置 Docker Buildx uses: docker/setup-buildx-action@v4 - name: 登录 GitHub Container Registry uses: docker/login-action@v4 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: 发布正式 Docker manifest shell: bash env: APP_VERSION: ${{ needs.prepare.outputs.app_version }} run: | set -Eeuo pipefail image_name="ghcr.io/${GITHUB_REPOSITORY,,}" minor_version="${APP_VERSION%.*}" digest_args=() while IFS= read -r digest_file; do digest_args+=("$image_name@sha256:$(basename "$digest_file")") done < <(find dist/digests -maxdepth 1 -type f -print | sort) docker buildx imagetools create \ --tag "$image_name:$GITHUB_REF_NAME" \ --tag "$image_name:$APP_VERSION" \ --tag "$image_name:$minor_version" \ --tag "$image_name:latest" \ --tag "$image_name:sha-$GITHUB_SHA" \ "${digest_args[@]}" docker buildx imagetools inspect "$image_name:$GITHUB_REF_NAME" docker buildx imagetools inspect "$image_name:latest" - name: 创建或更新 GitHub Release shell: bash env: GH_TOKEN: ${{ github.token }} APP_VERSION: ${{ needs.prepare.outputs.app_version }} run: | set -Eeuo pipefail mapfile -t release_files < <(find dist/release -maxdepth 1 -type f -print | sort) if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then gh release upload "$GITHUB_REF_NAME" "${release_files[@]}" --clobber else gh release create "$GITHUB_REF_NAME" "${release_files[@]}" \ --verify-tag \ --generate-notes \ --title "Ydisks 闲鱼助手 $APP_VERSION" fi