From c0fc1873697d196eb9841762109ad97982d79f34 Mon Sep 17 00:00:00 2001 From: iHsin Date: Sat, 23 Mar 2024 14:52:45 +0800 Subject: [PATCH] ci: improve binary release workflow windows gnu disabled due to https://github.com/cross-rs/cross/issues/1453 --- .github/workflows/binary-pre-release.yml | 209 +++++++++++++++++ .github/workflows/binary-release.yml | 285 +++++++++++++---------- .github/workflows/build.yml | 47 ++++ 3 files changed, 419 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/binary-pre-release.yml create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/binary-pre-release.yml b/.github/workflows/binary-pre-release.yml new file mode 100644 index 00000000..08a7e498 --- /dev/null +++ b/.github/workflows/binary-pre-release.yml @@ -0,0 +1,209 @@ +name: binary-release + +on: + push: + branches: + - dev + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + PACKAGE: "tuic-server" + PACKAGE2: "tuic-client" + +jobs: + compile: + name: Compile + permissions: + contents: write + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + # Linux + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + release-name: x86_64-linux + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + release-name: x86_64-linux-musl + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: i686-unknown-linux-gnu + release-name: i686-linux + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: i686-unknown-linux-musl + release-name: i686-linux-musl + cross: true + file-ext: "" + extra-args: "" + # Linux arm + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + release-name: aarch64-linux + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: aarch64-unknown-linux-musl + release-name: aarch64-linux-musl + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: armv7-unknown-linux-gnueabi + release-name: armv7-linux + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: armv7-unknown-linux-gnueabihf + release-name: armv7-linux-hf + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: armv7-unknown-linux-musleabi + release-name: armv7-linux-musl + cross: true + file-ext: "" + extra-args: "" + - os: ubuntu-latest + target: armv7-unknown-linux-musleabihf + release-name: armv7-linux-muslhf + cross: true + file-ext: "" + extra-args: "" + + # Windows + - os: windows-latest + target: x86_64-pc-windows-msvc + release-name: x86_64-windows + cross: false + file-ext: ".exe" + extra-args: "" + - os: windows-latest + target: i686-pc-windows-msvc + release-name: i686-windows + cross: true + file-ext: ".exe" + extra-args: "" + + # Windows GNU + # - os: ubuntu-latest + # target: x86_64-pc-windows-gnu + # release-name: x86_64-windows-gnu + # cross: true + # file-ext: ".exe" + # extra-args: "" + + # MacOSX + - os: macos-latest + target: x86_64-apple-darwin + release-name: x86_64-darwin + cross: false + file-ext: "" + extra-args: "" + - os: macos-latest + target: aarch64-apple-darwin + release-name: aarch64-darwin + cross: true + file-ext: "" + extra-args: "" + + # FreeBSD + - os: ubuntu-latest + target: x86_64-unknown-freebsd + release-name: x86_64-freebsd + cross: true + file-ext: "" + extra-args: "" + + + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ matrix.target }}-release-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + ${{ matrix.target }}-release + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + target: ${{ matrix.target }} + + # Build client and server separately + # But i gotta say that's ugly + # Blame me that can't figure out how GHA matrix works + - uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --release -p ${{ env.PACKAGE }} --target ${{ matrix.target }} ${{ matrix.extra-args }} + + - name: Rename binary + run: mv target/${{ matrix.target }}/release/${{ env.PACKAGE }}${{ matrix.file-ext }} ${{ env.PACKAGE }}-${{ matrix.release-name }}${{ matrix.file-ext }} + + - name: Upload binaries + uses: actions/upload-artifact@v2 + with: + name: compile + path: ${{ env.PACKAGE }}-${{ matrix.release-name }}${{ matrix.file-ext }} + + - uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --release -p ${{ env.PACKAGE2 }} --target ${{ matrix.target }} ${{ matrix.extra-args }} + + - name: Rename binary + run: mv target/${{ matrix.target }}/release/${{ env.PACKAGE2 }}${{ matrix.file-ext }} ${{ env.PACKAGE2 }}-${{ matrix.release-name }}${{ matrix.file-ext }} + + - name: Upload binaries + uses: actions/upload-artifact@v2 + with: + name: compile + path: ${{ env.PACKAGE2 }}-${{ matrix.release-name }}${{ matrix.file-ext }} + + release: + name: Release + needs: [compile] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Download binaries + uses: actions/download-artifact@v2 + with: + name: compile + path: ./packages + + - name: Github release + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: latest + prerelease: true + title: "Bleeding edge/前沿版本" + files: | + packages/* + LICENSE \ No newline at end of file diff --git a/.github/workflows/binary-release.yml b/.github/workflows/binary-release.yml index 3fc5eb68..ba7194f0 100644 --- a/.github/workflows/binary-release.yml +++ b/.github/workflows/binary-release.yml @@ -1,167 +1,208 @@ name: binary-release on: - workflow_call: - inputs: - PACKAGE_NAME: - required: true - type: string + push: + tags: + - "v*" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + PACKAGE: "tuic-server" + PACKAGE2: "tuic-client" jobs: - binary-release: + compile: + name: Compile permissions: contents: write - + runs-on: ${{ matrix.os }} strategy: - fail-fast: false + fail-fast: false matrix: include: - - arch-name: x86_64-unknown-linux-gnu - os: ubuntu-latest + # Linux + - os: ubuntu-latest target: x86_64-unknown-linux-gnu + release-name: x86_64-linux cross: true - file-ext: - - - arch-name: x86_64-unknown-linux-musl - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: x86_64-unknown-linux-musl + release-name: x86_64-linux-musl cross: true - file-ext: - - - arch-name: x86_64-unknown-freebsd - os: ubuntu-latest - target: x86_64-unknown-freebsd - cross: true - file-ext: - - - arch-name: x86_64-pc-windows-msvc - os: windows-latest - target: x86_64-pc-windows-msvc - cross: false - file-ext: .exe - - - arch-name: x86_64-pc-windows-gnu - os: ubuntu-latest - target: x86_64-pc-windows-gnu - cross: true - file-ext: .exe - - - arch-name: x86_64-apple-darwin - os: macos-latest - target: x86_64-apple-darwin - cross: false - file-ext: - - - arch-name: i686-unknown-linux-gnu - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: i686-unknown-linux-gnu + release-name: i686-linux cross: true - file-ext: - - - arch-name: i686-unknown-linux-musl - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: i686-unknown-linux-musl + release-name: i686-linux-musl cross: true - file-ext: - - - arch-name: i686-pc-windows-msvc - os: windows-latest - target: i686-pc-windows-msvc - cross: true - file-ext: .exe - - - arch-name: aarch64-unknown-linux-gnu - os: ubuntu-latest + file-ext: "" + extra-args: "" + # Linux arm + - os: ubuntu-latest target: aarch64-unknown-linux-gnu + release-name: aarch64-linux cross: true - file-ext: - - - arch-name: aarch64-unknown-linux-musl - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: aarch64-unknown-linux-musl + release-name: aarch64-linux-musl cross: true - file-ext: - - - arch-name: aarch64-apple-darwin - os: macos-latest - target: aarch64-apple-darwin - cross: true - file-ext: - - - arch-name: armv7-unknown-linux-gnueabi - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: armv7-unknown-linux-gnueabi + release-name: armv7-linux cross: true - file-ext: - - - arch-name: armv7-unknown-linux-gnueabihf - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: armv7-unknown-linux-gnueabihf + release-name: armv7-linux-hf cross: true - file-ext: - - - arch-name: armv7-unknown-linux-musleabi - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: armv7-unknown-linux-musleabi + release-name: armv7-linux-musl cross: true - file-ext: - - - arch-name: armv7-unknown-linux-musleabihf - os: ubuntu-latest + file-ext: "" + extra-args: "" + - os: ubuntu-latest target: armv7-unknown-linux-musleabihf + release-name: armv7-linux-muslhf cross: true - file-ext: + file-ext: "" + extra-args: "" + + # Windows + - os: windows-latest + target: x86_64-pc-windows-msvc + release-name: x86_64-windows + cross: false + file-ext: ".exe" + extra-args: "" + - os: windows-latest + target: i686-pc-windows-msvc + release-name: i686-windows + cross: true + file-ext: ".exe" + extra-args: "" + + # Windows GNU + # - os: ubuntu-latest + # target: x86_64-pc-windows-gnu + # release-name: x86_64-windows-gnu + # cross: true + # file-ext: ".exe" + # extra-args: "" + + # MacOSX + - os: macos-latest + target: x86_64-apple-darwin + release-name: x86_64-darwin + cross: false + file-ext: "" + extra-args: "" + - os: macos-latest + target: aarch64-apple-darwin + release-name: aarch64-darwin + cross: true + file-ext: "" + extra-args: "" + + # FreeBSD + - os: ubuntu-latest + target: x86_64-unknown-freebsd + release-name: x86_64-freebsd + cross: true + file-ext: "" + extra-args: "" - runs-on: ${{ matrix.os }} steps: - - name: Checkout repository - uses: actions/checkout@v3 + - uses: actions/checkout@v2 with: - fetch-depth: 0 + submodules: recursive - - name: Install toolchain - uses: actions-rs/toolchain@v1 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ matrix.target }}-release-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + ${{ matrix.target }}-release + + - uses: dtolnay/rust-toolchain@master with: toolchain: nightly target: ${{ matrix.target }} - override: true - - - name: Get package version on Unix-like system - if: runner.os != 'Windows' - run: | - echo "version=$(sed -rn 's/^version = \"(.*)\"/\1/p' ${{ inputs.PACKAGE_NAME }}/Cargo.toml)" >> $GITHUB_ENV - echo "prerelease=$((sed -rn 's/^version = \"(.*)\"/\1/p' ${{ inputs.PACKAGE_NAME }}/Cargo.toml | grep -qF '-') && echo "true" || echo "false")" >> $GITHUB_ENV - - - name: Get package version on Windows - if: runner.os == 'Windows' - run: | - echo "version=$(Get-Content ${{ inputs.PACKAGE_NAME }}/Cargo.toml | Select-String -Pattern '^version = \"(.*)\"' | ForEach-Object { $_.Matches.Groups[1].Value })" >> $env:GITHUB_ENV - echo "prerelease=$((Get-Content ${{ inputs.PACKAGE_NAME }}/Cargo.toml | Select-String -Pattern '^version = \"(.*)\"' | ForEach-Object { $_.Matches.Groups[1].Value } | Select-String -Quiet '-') && echo "false" || echo "true")" >> $env:GITHUB_ENV - - - name: Build - uses: actions-rs/cargo@v1 + + # Build client and server separately + # But i gotta say that's ugly + # Blame me that can't figure out how GHA matrix works + - uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --release -p ${{ env.PACKAGE }} --target ${{ matrix.target }} ${{ matrix.extra-args }} + + - name: Rename binary + run: mv target/${{ matrix.target }}/release/${{ env.PACKAGE }}${{ matrix.file-ext }} ${{ env.PACKAGE }}-${{ matrix.release-name }}${{ matrix.file-ext }} + + - name: Upload binaries + uses: actions/upload-artifact@v2 + with: + name: compile + path: ${{ env.PACKAGE }}-${{ matrix.release-name }}${{ matrix.file-ext }} + + - uses: actions-rs/cargo@v1 with: use-cross: ${{ matrix.cross }} command: build - args: --release -p ${{ inputs.PACKAGE_NAME }} --target ${{ matrix.target }} + args: --release -p ${{ env.PACKAGE2 }} --target ${{ matrix.target }} ${{ matrix.extra-args }} + + - name: Rename binary + run: mv target/${{ matrix.target }}/release/${{ env.PACKAGE2 }}${{ matrix.file-ext }} ${{ env.PACKAGE2 }}-${{ matrix.release-name }}${{ matrix.file-ext }} - - name: Move binaries - run: | - mkdir artifacts/ - mv target/${{ matrix.target }}/release/${{ inputs.PACKAGE_NAME }}${{ matrix.file-ext }} artifacts/${{ inputs.PACKAGE_NAME }}-${{ env.version }}-${{ matrix.arch-name }}${{ matrix.file-ext }} + - name: Upload binaries + uses: actions/upload-artifact@v2 + with: + name: compile + path: ${{ env.PACKAGE2 }}-${{ matrix.release-name }}${{ matrix.file-ext }} - - name: Calculate SHA256 - run: | - cd artifacts/ - openssl dgst -sha256 -r ${{ inputs.PACKAGE_NAME }}-${{ env.version }}-${{ matrix.arch-name }}${{ matrix.file-ext }} > ${{ inputs.PACKAGE_NAME }}-${{ env.version }}-${{ matrix.arch-name }}${{ matrix.file-ext }}.sha256sum + release: + name: Release + needs: [compile] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Download binaries + uses: actions/download-artifact@v2 + with: + name: compile + path: ./packages - - name: Release binaries - uses: ncipollo/release-action@v1 + - name: Github release + uses: "marvinpinto/action-automatic-releases@latest" with: - artifacts: "artifacts/*" - name: ${{ inputs.PACKAGE_NAME }}-${{ env.version }} - tag: ${{ inputs.PACKAGE_NAME }}-${{ env.version }} - commit: ${{ github.sha }} - allowUpdates: true - prerelease: ${{ env.prerelease }} + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false + files: | + packages/* + LICENSE \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..b7846691 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +name: build + +on: + push: + branches: [ dev ] + paths-ignore: [ '*.md' ] + pull_request: + branches: [ dev ] + paths-ignore: [ '*.md' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Resume cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-build + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly-2024-03-01 + components: clippy + + - name: Build + run: cargo build --verbose + + - name: Run tests + run: cargo test --verbose + + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features \ No newline at end of file