|
| 1 | +name: Rust CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "*.*.*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish-binary: |
| 10 | + runs-on: ${{ matrix.platform.os }} |
| 11 | + strategy: |
| 12 | + matrix: |
| 13 | + rust: [ stable ] |
| 14 | + platform: |
| 15 | + - os: macos-latest |
| 16 | + os-name: macos |
| 17 | + target: x86_64-apple-darwin |
| 18 | + architecture: x86_64 |
| 19 | + binary-postfix: "" |
| 20 | + use-cross: false |
| 21 | + - os: ubuntu-latest |
| 22 | + os-name: linux |
| 23 | + target: x86_64-unknown-linux-gnu |
| 24 | + architecture: x86_64 |
| 25 | + binary-postfix: "" |
| 26 | + use-cross: false |
| 27 | + - os: windows-latest |
| 28 | + os-name: windows |
| 29 | + target: x86_64-pc-windows-msvc |
| 30 | + architecture: x86_64 |
| 31 | + binary-postfix: ".exe" |
| 32 | + use-cross: false |
| 33 | + - os: ubuntu-latest |
| 34 | + os-name: linux |
| 35 | + target: aarch64-unknown-linux-gnu |
| 36 | + architecture: arm64 |
| 37 | + binary-postfix: "" |
| 38 | + use-cross: true |
| 39 | + - os: ubuntu-latest |
| 40 | + os-name: linux |
| 41 | + target: i686-unknown-linux-gnu |
| 42 | + architecture: i686 |
| 43 | + binary-postfix: "" |
| 44 | + use-cross: true |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Install Rust toolchain |
| 48 | + uses: actions-rs/toolchain@v1 |
| 49 | + with: |
| 50 | + toolchain: ${{ matrix.rust }} |
| 51 | + profile: minimal |
| 52 | + override: true |
| 53 | + |
| 54 | + - name: Checkout repository |
| 55 | + uses: actions/checkout@v2 |
| 56 | + |
| 57 | + - name: Cargo build |
| 58 | + uses: actions-rs/cargo@v1 |
| 59 | + with: |
| 60 | + command: build |
| 61 | + use-cross: ${{ matrix.platform.use-cross }} |
| 62 | + toolchain: ${{ matrix.rust }} |
| 63 | + args: --release --target ${{ matrix.platform.target }} |
| 64 | + |
| 65 | + - name: Install strip command |
| 66 | + if: ${{ matrix.platform.target == 'aarch64-unknown-linux-gnu' }} |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + sudo apt update |
| 70 | + sudo apt-get install -y binutils-aarch64-linux-gnu |
| 71 | +
|
| 72 | + - name: Package final binary |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + cd target/${{ matrix.platform.target }}/release |
| 76 | + ####### reduce binary size by removing debug symbols ####### |
| 77 | + BINARY_NAME=rscolorq${{ matrix.platform.binary-postfix }} |
| 78 | + if [[ ${{ matrix.platform.target }} == aarch64-unknown-linux-gnu ]]; then |
| 79 | + GCC_PREFIX="aarch64-linux-gnu-" |
| 80 | + else |
| 81 | + GCC_PREFIX="" |
| 82 | + fi |
| 83 | +
|
| 84 | + if [[ ${{ matrix.platform.target }} != x86_64-pc-windows-msvc ]]; then |
| 85 | + "$GCC_PREFIX"strip $BINARY_NAME |
| 86 | + fi |
| 87 | +
|
| 88 | + ########## create tar.gz ########## |
| 89 | + RELEASE_NAME=rscolorq-${GITHUB_REF/refs\/tags\//}-${{ matrix.platform.os-name }}-${{ matrix.platform.architecture }} |
| 90 | + tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME |
| 91 | + ########## create sha256 ########## |
| 92 | + if [[ ${{ runner.os }} == 'Windows' ]]; then |
| 93 | + certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256 |
| 94 | + else |
| 95 | + shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256 |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Releasing assets |
| 99 | + uses: softprops/action-gh-release@v1 |
| 100 | + with: |
| 101 | + files: | |
| 102 | + target/${{ matrix.platform.target }}/release/rscolorq-*.tar.gz |
| 103 | + target/${{ matrix.platform.target }}/release/rscolorq-*.sha256 |
| 104 | + env: |
| 105 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments