Build Application #9
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: Build Application | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_override: | |
| description: "构建版本号(例如 v3.0.0),否则使用 Git SHA 的前 7 位" | |
| required: false | |
| default: "" | |
| type: string | |
| jobs: | |
| determine_version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| app_version: ${{ steps.version_info.outputs.app_version }} | |
| steps: | |
| - name: Checkout code (to get SHA) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine Version | |
| id: version_info | |
| run: | | |
| VERSION_INPUT="${{ github.event.inputs.version_override }}" | |
| SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) | |
| if [ -n "$VERSION_INPUT" ]; then | |
| APP_VERSION="$VERSION_INPUT" | |
| else | |
| APP_VERSION="$SHORT_SHA" | |
| fi | |
| echo "Determined App Version: $APP_VERSION" | |
| echo "app_version=$APP_VERSION" >> $GITHUB_OUTPUT | |
| build_app: | |
| needs: determine_version | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: Linux x86_64 (GNU) | |
| os: ubuntu-latest | |
| cpython_triple: x86_64-unknown-linux-gnu | |
| artifact_suffix: Linux-x64-gnu | |
| build_method: standard | |
| - name: Linux x86_64 (Manylinux) | |
| os: ubuntu-latest | |
| cpython_triple: x86_64-unknown-linux-gnu | |
| artifact_suffix: manylinux-x64-gnu | |
| build_method: manylinux | |
| - name: Linux aarch64 (GNU) | |
| os: ubuntu-24.04-arm | |
| cpython_triple: aarch64-unknown-linux-gnu | |
| artifact_suffix: Linux-arm64-gnu | |
| build_method: standard | |
| # macOS x86_64 Build | |
| - name: macOS x86_64 | |
| os: macos-15-intel | |
| cpython_triple: x86_64-apple-darwin | |
| artifact_suffix: macOS-x64 | |
| build_method: standard | |
| # macOS aarch64 Build | |
| - name: macOS aarch64 | |
| os: macos-15 | |
| cpython_triple: aarch64-apple-darwin | |
| artifact_suffix: macOS-arm64 | |
| build_method: standard | |
| # Windows x86_64 Build | |
| - name: Windows x86_64 | |
| os: windows-latest | |
| cpython_triple: x86_64-pc-windows-msvc | |
| artifact_suffix: Windows-x64 | |
| build_method: standard | |
| # Windows aarch64 Build | |
| - name: Windows aarch64 | |
| os: windows-11-arm | |
| cpython_triple: aarch64-pc-windows-msvc | |
| artifact_suffix: Windows-arm64 | |
| build_method: standard | |
| name: Build for ${{ matrix.name }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Make pack script executable | |
| run: chmod +x ./scripts/pack.sh | |
| - name: Build Linux x86_64 in Manylinux Container | |
| if: matrix.build_method == 'manylinux' | |
| run: | | |
| MANYLINUX_IMAGE="quay.io/pypa/manylinux2014:latest" | |
| echo "Building in $MANYLINUX_IMAGE container..." | |
| docker run \ | |
| --rm \ | |
| -v ${{ github.workspace }}:/ws \ | |
| -w /ws \ | |
| -e CPYTHON_TRIPLE=${{ matrix.cpython_triple }} \ | |
| $MANYLINUX_IMAGE \ | |
| /bin/bash -c "ldd --version && ./scripts/pack.sh" | |
| - name: Set up MSYS2 for Windows build | |
| if: runner.os == 'Windows' && matrix.build_method == 'standard' | |
| uses: msys2/setup-msys2@v2 | |
| with: | |
| msystem: UCRT64 | |
| - name: Build on Windows | |
| if: runner.os == 'Windows' && matrix.build_method == 'standard' | |
| env: | |
| CPYTHON_TRIPLE: ${{ matrix.cpython_triple }} | |
| run: | | |
| echo "Building with CPYTHON_TRIPLE=${CPYTHON_TRIPLE}" | |
| chmod +x ./scripts/pack.sh | |
| ./scripts/pack.sh | |
| shell: msys2 {0} | |
| - name: Build on macOS or Linux | |
| if: (runner.os == 'macOS' && matrix.build_method == 'standard') || (runner.os == 'linux' && matrix.build_method == 'standard') | |
| env: | |
| CPYTHON_TRIPLE: ${{ matrix.cpython_triple }} | |
| run: | | |
| if [[ "$CPYTHON_TRIPLE" == *"musl"* ]]; then | |
| echo "Warning: musl build is for Linux, skipping musl-dev install on macOS." | |
| fi | |
| echo "Building with CPYTHON_TRIPLE=${CPYTHON_TRIPLE}" | |
| chmod +x ./scripts/pack.sh | |
| ./scripts/pack.sh | |
| shell: bash | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: GDUTCourseGrabber-${{ needs.determine_version.outputs.app_version }}-${{ matrix.artifact_suffix }} | |
| path: dist/* | |
| docker_release: | |
| needs: determine_version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| gamernotitle/gdut-course-grabber:latest | |
| gamernotitle/gdut-course-grabber:${{ needs.determine_version.outputs.app_version }} |