From 97cc8cd417cc89963d94a2fbbc5ec3abf6f96acf Mon Sep 17 00:00:00 2001 From: hms5232 Date: Sun, 23 Jun 2024 14:56:15 +0800 Subject: [PATCH] ci: build pipeline --- .github/workflows/build.yml | 71 +++++++++++++++++++++++++++++++ .github/workflows/debug_build.yml | 35 +++++++++++++++ .github/workflows/release.yml | 69 ++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/debug_build.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8d03c57 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +name: Reusable build workflow + +on: + workflow_call: + inputs: + version: + required: true + type: string + description: Used in filename. + target: + required: true + type: string + description: Toolchain which compile for. + os: + required: true + type: string + description: The runner os. + bin: + required: false + type: string + description: Built binary filename. + default: ufwlog + command: + required: false + type: string + description: The commands to run. + default: build + strip: + required: false + type: boolean + default: true + args: + required: false + type: string + description: Arguments to be passed to cross build. + default: "--locked --release" + upload-artifact: + required: false + type: boolean + description: Upload to artifact or not. + default: true + binary-mode: + required: false + type: string + description: The binary where in. Should be one of "release" or "debug" + default: release + +jobs: + build: + + runs-on: ${{ inputs.os }} + + name: ${{ inputs.bin }} + steps: + - uses: actions/checkout@v4 + - name: Build + uses: houseabsolute/actions-rust-cross@v0 + with: + command: ${{ inputs.command }} + target: ${{ inputs.target }} + args: ${{ inputs.args }} + strip: true + - uses: actions/upload-artifact@v4 + with: + # Name of the artifact to upload. + # Optional. Default is 'artifact' + name: ${{ inputs.bin }}_${{ inputs.version }}_${{ inputs.target }} + + # A file, directory or wildcard pattern that describes what to upload + # Required. + path: target/${{ inputs.target }}/${{ inputs.binary-mode }}/${{ inputs.bin }} diff --git a/.github/workflows/debug_build.yml b/.github/workflows/debug_build.yml new file mode 100644 index 0000000..c0b4b5a --- /dev/null +++ b/.github/workflows/debug_build.yml @@ -0,0 +1,35 @@ +name: Debug build + +on: + pull_request: + branches: [ "main" ] + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + bin: ufwlog + command: build + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + bin: ufwlog + command: build + name: ${{ matrix.platform.target }} + uses: ./.github/workflows/build.yml + with: + version: ${{ github.sha }} + os: ${{ matrix.platform.os }} + binary-mode: debug + command: ${{ matrix.platform.command }} + bin: ${{ matrix.platform.bin }} + target: ${{ matrix.platform.target }} + args: "--locked" + strip: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c87b211 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,69 @@ +name: Release + +on: + workflow_dispatch: + release: + types: [ published ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + strategy: + fail-fast: false + matrix: + platform: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + bin: ufwlog + command: build + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + bin: ufwlog + command: build + name: Build/${{ matrix.platform.target }} + uses: ./.github/workflows/build.yml + with: + version: ${{ github.ref_name }} + os: ${{ matrix.platform.os }} + command: ${{ matrix.platform.command }} + bin: ${{ matrix.platform.bin }} + target: ${{ matrix.platform.target }} + args: "--locked --release" + strip: true + + upload: + permissions: + contents: write + strategy: + fail-fast: false + matrix: + platform: + - release_for: x86_64-unknown-linux-gnu + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + bin: ufwlog + command: build + - release_for: aarch64-unknown-linux-gnu + os: ubuntu-latest + target: aarch64-unknown-linux-gnu + bin: ufwlog + command: build + + runs-on: ${{ matrix.platform.os }} + + name: Upload/${{ matrix.platform.target }} + needs: + - build + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: ${{ matrix.platform.bin }}_${{ github.ref_name }}_${{ matrix.platform.target }} + - name: Rename binary + run: mv ${{ matrix.platform.bin }} ${{ matrix.platform.bin }}_${{ github.ref_name }}_${{ matrix.platform.target }} + - name: Upload binary + uses: softprops/action-gh-release@v1 + with: + files: ${{ matrix.platform.bin }}_${{ github.ref_name }}_${{ matrix.platform.target }}