|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: ['v*'] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-22.04 |
| 12 | + strategy: |
| 13 | + fail-fast: true |
| 14 | + matrix: |
| 15 | + target: |
| 16 | + - x86_64-unknown-linux-musl |
| 17 | + |
| 18 | + steps: |
| 19 | + |
| 20 | + |
| 21 | + - name: install apt depenedencies |
| 22 | + run: | |
| 23 | + sudo apt-get update |
| 24 | + sudo apt-get install -y musl-tools |
| 25 | +
|
| 26 | + - name: Get Rust toolchain |
| 27 | + id: toolchain |
| 28 | + working-directory: . |
| 29 | + run: | |
| 30 | + awk -F'[ ="]+' '$1 == "channel" { print "toolchain=" $2 }' rust-toolchain >> "$GITHUB_OUTPUT" |
| 31 | +
|
| 32 | + - uses: dtolnay/rust-toolchain@v1 |
| 33 | + with: |
| 34 | + toolchain: ${{ steps.toolchain.outputs.toolchain }} |
| 35 | + targets: ${{ matrix.target }} |
| 36 | + |
| 37 | + - uses: Swatinem/[email protected] |
| 38 | + |
| 39 | + - name: install cargo-about |
| 40 | + run: | |
| 41 | + cargo install --locked cargo-about |
| 42 | +
|
| 43 | + - name: Build |
| 44 | + run: | |
| 45 | + cargo build --target=${{ matrix.target }} --release --locked |
| 46 | +
|
| 47 | + - name: Rename binaries |
| 48 | + run: | |
| 49 | + mkdir bin |
| 50 | + kble_bins=("kble" "kble-c2a" "kble-eb90" "kble-serialport") |
| 51 | + for b in "${kble_bins[@]}" ; do |
| 52 | + cp "./target/${{ matrix.target }}/release/${b}" "./bin/${b}-${{ matrix.target }}" |
| 53 | + done |
| 54 | + ls -lh ./bin |
| 55 | +
|
| 56 | + |
| 57 | + with: |
| 58 | + name: release-executable-${{ matrix.target }} |
| 59 | + if-no-files-found: error |
| 60 | + path: ./bin/ |
| 61 | + |
| 62 | + build_kble_serialport_win: |
| 63 | + name: build / kble-serialport.exe |
| 64 | + # C2A Boom ecosystem does **NOT** support native Windows environment. |
| 65 | + # However, WSL2 environment is supported and has many use cases in the real world. |
| 66 | + # Here, there are difficulties in running kble-serialport inside WSL2, |
| 67 | + # a component that interfaces with external hardware (USB-RS devices). |
| 68 | + # Although it is possible to show a Windows host USB devices |
| 69 | + # to a WSL2 Linux VM using the usbipd-win project, this is still a bit unstable. |
| 70 | + # Also, kble-serialport is a very small component that does not need to be updated frequently for practical use. |
| 71 | + # For these reasons, we currently choose to run only kble-serialport on Windows host. |
| 72 | + |
| 73 | + runs-on: windows-2022 |
| 74 | + |
| 75 | + env: |
| 76 | + TARGET: x86_64-pc-windows-msvc |
| 77 | + |
| 78 | + steps: |
| 79 | + |
| 80 | + |
| 81 | + - name: Get Rust toolchain |
| 82 | + id: toolchain |
| 83 | + working-directory: . |
| 84 | + shell: bash |
| 85 | + run: | |
| 86 | + awk -F'[ ="]+' '$1 == "channel" { print "toolchain=" $2 }' rust-toolchain >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - uses: dtolnay/rust-toolchain@v1 |
| 89 | + with: |
| 90 | + toolchain: ${{ steps.toolchain.outputs.toolchain }} |
| 91 | + targets: ${{ env.TARGET }} |
| 92 | + |
| 93 | + - uses: Swatinem/[email protected] |
| 94 | + |
| 95 | + - name: install cargo-about |
| 96 | + run: | |
| 97 | + cargo install --locked cargo-about |
| 98 | +
|
| 99 | + - name: Build |
| 100 | + run: | |
| 101 | + cargo build --target=${{ env.TARGET }} -p kble-serialport --release --locked |
| 102 | +
|
| 103 | + - name: Rename binary |
| 104 | + shell: bash |
| 105 | + run: | |
| 106 | + mkdir bin |
| 107 | + cp "./target/${{ env.TARGET }}/release/kble-serialport.exe" "./bin/kble-serialport-${{ env.TARGET }}.exe" |
| 108 | + ls -lh ./bin |
| 109 | +
|
| 110 | + |
| 111 | + with: |
| 112 | + name: release-executable-${{ env.TARGET }} |
| 113 | + if-no-files-found: error |
| 114 | + path: ./bin/ |
| 115 | + |
| 116 | + release: |
| 117 | + name: Release |
| 118 | + needs: [ build, build_kble_serialport_win ] |
| 119 | + permissions: |
| 120 | + contents: write |
| 121 | + |
| 122 | + runs-on: ubuntu-22.04 |
| 123 | + |
| 124 | + steps: |
| 125 | + |
| 126 | + with: |
| 127 | + pattern: release-executable-* |
| 128 | + merge-multiple: true |
| 129 | + |
| 130 | + - run: chmod +x kble-* |
| 131 | + |
| 132 | + - run: ls -lh |
| 133 | + |
| 134 | + - name: Release to GitHub Release |
| 135 | + if: startsWith(github.ref, 'refs/tags/') |
| 136 | + |
| 137 | + with: |
| 138 | + draft: true |
| 139 | + fail_on_unmatched_files: true |
| 140 | + generate_release_notes: true |
| 141 | + files: | |
| 142 | + kble* |
0 commit comments