diff --git a/.github/workflows/build-multi-platform.yml b/.github/workflows/build-multi-platform.yml index 6247859..19ddea7 100644 --- a/.github/workflows/build-multi-platform.yml +++ b/.github/workflows/build-multi-platform.yml @@ -6,108 +6,34 @@ on: jobs: build-macos-intel: - runs-on: macos-latest - outputs: - artifact_id: ${{ steps.upload.outputs.artifact-id }} - artifact_url: ${{ steps.upload.outputs.artifact-url }} - steps: - - uses: actions/checkout@v6 - - name: Setup Flutter - uses: subosito/flutter-action@v2 - with: - flutter-version: '3.32.0' - - name: Install dependencies - run: flutter pub get - - name: Build macOS Intel - run: dart compile exe bin/main.dart -o api_tool_macos_intel - - name: Verify binary - run: | - git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git - dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_macos_intel - - name: Upload Artifact - id: upload - uses: actions/upload-artifact@v4 - with: - name: api_tool_macos_intel - path: api_tool_macos_intel + uses: ./.github/workflows/build-reusable.yml + with: + runner: macos-latest + artifact-name: api_tool_macos_intel + binary-name: api_tool_macos_intel build-macos-arm64: - runs-on: macos-latest - outputs: - artifact_id: ${{ steps.upload.outputs.artifact-id }} - artifact_url: ${{ steps.upload.outputs.artifact-url }} - steps: - - uses: actions/checkout@v6 - - name: Setup Flutter - uses: subosito/flutter-action@v2 - with: - flutter-version: '3.32.0' - - name: Install dependencies - run: flutter pub get - - name: Build macOS ARM64 - run: dart compile exe bin/main.dart -o api_tool_macos_arm64 --target-os=macos --target-arch=arm64 - - name: Verify binary - run: | - git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git - dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_macos_arm64 - - name: Upload Artifact - id: upload - uses: actions/upload-artifact@v4 - with: - name: api_tool_macos_arm64 - path: api_tool_macos_arm64 + uses: ./.github/workflows/build-reusable.yml + with: + runner: macos-latest + artifact-name: api_tool_macos_arm64 + binary-name: api_tool_macos_arm64 + compile-args: '--target-os=macos --target-arch=arm64' build-linux-x64: - runs-on: ubuntu-latest - outputs: - artifact_id: ${{ steps.upload.outputs.artifact-id }} - artifact_url: ${{ steps.upload.outputs.artifact-url }} - steps: - - uses: actions/checkout@v6 - - name: Setup Flutter - uses: subosito/flutter-action@v2 - with: - flutter-version: '3.32.0' - - name: Install dependencies - run: flutter pub get - - name: Build Linux x64 - run: dart compile exe bin/main.dart -o api_tool_linux --target-arch=x64 - - name: Verify binary - run: | - git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git - dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_linux - - name: Upload Artifact - id: upload - uses: actions/upload-artifact@v4 - with: - name: api_tool_linux - path: api_tool_linux + uses: ./.github/workflows/build-reusable.yml + with: + runner: ubuntu-latest + artifact-name: api_tool_linux + binary-name: api_tool_linux + compile-args: '--target-arch=x64' build-windows-x64: - runs-on: windows-latest - outputs: - artifact_id: ${{ steps.upload.outputs.artifact-id }} - artifact_url: ${{ steps.upload.outputs.artifact-url }} - steps: - - uses: actions/checkout@v6 - - name: Setup Flutter - uses: subosito/flutter-action@v2 - with: - flutter-version: '3.32.0' - - name: Install dependencies - run: flutter pub get - - name: Build Windows x64 - run: dart compile exe bin/main.dart -o api_tool_windows.exe - - name: Verify binary - run: | - git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git - dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_windows.exe - - name: Upload Artifact - id: upload - uses: actions/upload-artifact@v4 - with: - name: api_tool_windows - path: api_tool_windows.exe + uses: ./.github/workflows/build-reusable.yml + with: + runner: windows-latest + artifact-name: api_tool_windows + binary-name: api_tool_windows.exe comment-on-pr: needs: [build-macos-intel, build-macos-arm64, build-linux-x64, build-windows-x64] @@ -120,7 +46,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} comment-author: 'github-actions[bot]' body-includes: 编译完成,产物如下 - + - name: Create or Update PR Comment uses: peter-evans/create-or-update-comment@v4 with: @@ -128,8 +54,8 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body: | ✅ 编译完成,产物如下: - - [api_tool_macos_intel](${{ needs.build-macos-intel.outputs.artifact_url }}) - - [api_tool_macos_arm64](${{ needs.build-macos-arm64.outputs.artifact_url }}) - - [api_tool_linux](${{ needs.build-linux-x64.outputs.artifact_url }}) - - [api_tool_windows](${{ needs.build-windows-x64.outputs.artifact_url }}) + - [api_tool_macos_intel](${{ needs.build-macos-intel.outputs.artifact-url }}) + - [api_tool_macos_arm64](${{ needs.build-macos-arm64.outputs.artifact-url }}) + - [api_tool_linux](${{ needs.build-linux-x64.outputs.artifact-url }}) + - [api_tool_windows](${{ needs.build-windows-x64.outputs.artifact-url }}) edit-mode: replace diff --git a/.github/workflows/build-reusable.yml b/.github/workflows/build-reusable.yml new file mode 100644 index 0000000..3ee7f44 --- /dev/null +++ b/.github/workflows/build-reusable.yml @@ -0,0 +1,61 @@ +name: Build Single Platform + +on: + workflow_call: + inputs: + runner: + description: 'GitHub Actions runner (e.g. macos-latest, ubuntu-latest, windows-latest)' + required: true + type: string + artifact-name: + description: 'Name for the uploaded artifact' + required: true + type: string + binary-name: + description: 'Output binary file name' + required: true + type: string + compile-args: + description: 'Extra arguments for dart compile exe' + required: false + type: string + default: '' + outputs: + artifact-id: + description: 'Uploaded artifact ID' + value: ${{ jobs.build.outputs.artifact_id }} + artifact-url: + description: 'Uploaded artifact URL' + value: ${{ jobs.build.outputs.artifact_url }} + +jobs: + build: + runs-on: ${{ inputs.runner }} + outputs: + artifact_id: ${{ steps.upload.outputs.artifact-id }} + artifact_url: ${{ steps.upload.outputs.artifact-url }} + steps: + - uses: actions/checkout@v6 + + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: '3.32.0' + + - name: Install dependencies + run: flutter pub get + + - name: Build binary + run: dart compile exe bin/main.dart -o ${{ inputs.binary-name }} ${{ inputs.compile-args }} + + - name: Verify binary + run: | + git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git + dart run .github/scripts/cross_platform_verify.dart tdesign-flutter ${{ inputs.binary-name }} + + - name: Upload Artifact + id: upload + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.artifact-name }} + path: ${{ inputs.binary-name }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e9905bf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,123 @@ +name: Release on Version Change + +on: + push: + branches: [main] + paths: + - 'pubspec.yaml' + +permissions: + contents: write + +jobs: + check-version: + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.changed }} + new_version: ${{ steps.check.outputs.version }} + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 2 + + - name: Check version change + id: check + run: | + # 获取当前版本 + CURRENT_VERSION=$(grep '^version:' pubspec.yaml | head -1 | awk '{print $2}') + echo "Current version: $CURRENT_VERSION" + + # 获取上一次提交的版本 + PREVIOUS_VERSION=$(git show HEAD~1:pubspec.yaml 2>/dev/null | grep '^version:' | head -1 | awk '{print $2}' || echo "") + echo "Previous version: $PREVIOUS_VERSION" + + # 对比版本 + if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then + echo "Version changed: $PREVIOUS_VERSION -> $CURRENT_VERSION" + echo "changed=true" >> $GITHUB_OUTPUT + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT + else + echo "Version not changed, skipping release." + echo "changed=false" >> $GITHUB_OUTPUT + fi + + - name: Check tag exists + if: steps.check.outputs.changed == 'true' + id: tag-check + run: | + TAG="v${{ steps.check.outputs.version }}" + if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then + echo "Tag $TAG already exists, skipping release." + echo "changed=false" >> $GITHUB_OUTPUT + fi + + create-tag: + needs: check-version + if: needs.check-version.outputs.version_changed == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Create and push tag + run: | + TAG="v${{ needs.check-version.outputs.new_version }}" + git tag "$TAG" + git push origin "$TAG" + + build-macos-intel: + needs: create-tag + uses: ./.github/workflows/build-reusable.yml + with: + runner: macos-latest + artifact-name: api_tool_macos_intel + binary-name: api_tool_macos_intel + + build-macos-arm64: + needs: create-tag + uses: ./.github/workflows/build-reusable.yml + with: + runner: macos-latest + artifact-name: api_tool_macos_arm64 + binary-name: api_tool_macos_arm64 + compile-args: '--target-os=macos --target-arch=arm64' + + build-linux-x64: + needs: create-tag + uses: ./.github/workflows/build-reusable.yml + with: + runner: ubuntu-latest + artifact-name: api_tool_linux + binary-name: api_tool_linux + compile-args: '--target-arch=x64' + + build-windows-x64: + needs: create-tag + uses: ./.github/workflows/build-reusable.yml + with: + runner: windows-latest + artifact-name: api_tool_windows + binary-name: api_tool_windows.exe + + create-release: + needs: [check-version, create-tag, build-macos-intel, build-macos-arm64, build-linux-x64, build-windows-x64] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: release-assets + + - name: Create GitHub Release + id: release + run: | + TAG="v${{ needs.check-version.outputs.new_version }}" + + gh release create "$TAG" \ + --title "$TAG" \ + --generate-notes \ + ./release-assets/api_tool_macos_intel/api_tool_macos_intel \ + ./release-assets/api_tool_macos_arm64/api_tool_macos_arm64 \ + ./release-assets/api_tool_linux/api_tool_linux \ + ./release-assets/api_tool_windows/api_tool_windows.exe