biliget 0.6.9

简单的B站视频下载工具 支持免登录下载B站高清视频
name: Build

on:
  push:
    branches:
      - main
    tags:
      - 'v*'
  pull_request:
    branches:
      - main
  workflow_dispatch:

permissions:
  contents: write

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        build:
          - linux-arm64
          - linux-64bit
          - macos-arm64
          - macos-64bit
          - windows-64bit
          - windows-arm64
        include:
          - build: linux-arm64
            os: ubuntu-22.04-arm
            target: aarch64-unknown-linux-gnu
            archive-name: biliget-linux-arm64

          - build: linux-64bit
            os: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
            archive-name: biliget-linux-64bit

          - build: macos-arm64
            os: macos-14
            target: aarch64-apple-darwin
            archive-name: biliget-macos-arm64

          - build: macos-64bit
            os: macos-14
            target: x86_64-apple-darwin
            archive-name: biliget-macos-64bit

          - build: windows-64bit
            os: windows-2022
            target: x86_64-pc-windows-msvc
            archive-name: "biliget-64bit.exe"

          - build: windows-arm64
            os: windows-11-arm
            target: aarch64-pc-windows-msvc
            archive-name: "biliget-arm64.exe"

      fail-fast: false

    steps:
      - name: Checkout Code
        uses: actions/checkout@v6

      - name: Setup Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
          toolchain: stable
          components: clippy, rustfmt

      - name: Cache Cargo dependencies
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |
            ${{ runner.os }}-${{ matrix.target }}-cargo-

      - name: Install OpenSSL (Linux)
        if: contains(matrix.build, 'linux')
        run: |
          sudo apt update
          sudo apt install -y libssl-dev

      - name: Check formatting
        if: matrix.build == 'linux-64bit'
        run: cargo fmt --check

      - name: Clippy lint
        if: matrix.build == 'linux-64bit'
        run: cargo clippy --all-targets --all-features --target ${{ matrix.target }} -- -D warnings

      - name: Run tests
        run: cargo test --verbose --target ${{ matrix.target }}

      - name: Build binary
        run: cargo build --verbose --release --target ${{ matrix.target }}
        env:
          RUST_BACKTRACE: 1
          CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc

      - name: Copy target (Non-Windows)
        if: ${{ !contains(matrix.build, 'windows') }}
        run: |
          cp target/${{ matrix.target }}/release/biliget ${{ matrix.archive-name }}
          chmod +x ${{ matrix.archive-name }}

      - name: Copy target (Windows)
        if: contains(matrix.build, 'windows')
        shell: pwsh
        run: |
          Copy-Item -Path "target/${{ matrix.target }}/release/biliget.exe" -Destination "${{ matrix.archive-name }}"

      - name: Upload build artifact
        uses: actions/upload-artifact@v6
        with:
          name: ${{ matrix.archive-name }}
          path: ${{ matrix.archive-name }}
          if-no-files-found: error

  release:
    name: Create Release
    needs: build
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: ./all-artifacts
          merge-multiple: true

      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          files: ./all-artifacts/*
          generate_release_notes: true
          tag_name: ${{ github.ref_name }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}