diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4539507..8b7a877 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -184,30 +184,39 @@ jobs: sudo apt update sudo apt install -y gh + # 创建或更新 Release - name: Create or update Release if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 设置 GH_TOKEN 环境变量 run: | RELEASE_NAME=${{ github.ref_name }} - gh release view "$RELEASE_NAME" > /dev/null 2>&1 - if [ $? -ne 0 ]; then - gh release create "$RELEASE_NAME" \ - ./app-amd64.tar.gz \ - ./app-amd64-lite.tar.gz \ - ./app-arm64.tar.gz \ - ./app-arm64-lite.tar.gz \ - ./app-arm-v7.tar.gz \ - ./app-arm-v7-lite.tar.gz \ - --title "$RELEASE_NAME" \ - --notes "Automated release for $RELEASE_NAME" - else - gh release upload "$RELEASE_NAME" \ - ./app-amd64.tar.gz \ - ./app-amd64-lite.tar.gz \ - ./app-arm64.tar.gz \ - ./app-arm64-lite.tar.gz \ - ./app-arm-v7.tar.gz \ - ./app-arm-v7-lite.tar.gz \ - --clobber + RELEASE_BODY="This release is automatically updated from the ${RELEASE_NAME} branch." + + # 检查是否已有同名 Release + EXISTING_RELEASE=$(gh release view "${RELEASE_NAME}" --json id --jq .id || echo "") + + if [[ -n "${EXISTING_RELEASE}" ]]; then + echo "release exist" + else + # 创建新的 Release + gh release create "${RELEASE_NAME}" \ + --prerelease=false \ + --title "${RELEASE_NAME}" \ + --notes "${RELEASE_BODY}" + fi + + # 上传多个文件并覆盖 + - name: Upload assets to Release + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 设置 GH_TOKEN 环境变量 + run: | + RELEASE_NAME=${{ github.ref_name }} + + FILES=$(find . -type f -name "app-*.tar.gz") + for FILE in ${FILES}; do + echo "type upload ${FILE}" + gh release upload "${RELEASE_NAME}" "${FILE}" --clobber + done