|
| 1 | +name: CD # Continuous Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[v]?[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +jobs: |
| 9 | + |
| 10 | + publish: |
| 11 | + name: Publishing for ${{ matrix.job.os }} |
| 12 | + runs-on: ${{ matrix.job.os }} |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + rust: [stable] |
| 16 | + job: |
| 17 | + - os: macos-latest |
| 18 | + os-name: macos |
| 19 | + target: x86_64-apple-darwin |
| 20 | + architecture: x86_64 |
| 21 | + binary-postfix: "" |
| 22 | + use-cross: false |
| 23 | + - os: ubuntu-latest |
| 24 | + os-name: linux |
| 25 | + target: x86_64-unknown-linux-gnu |
| 26 | + architecture: x86_64 |
| 27 | + binary-postfix: "" |
| 28 | + use-cross: false |
| 29 | + - os: windows-latest |
| 30 | + os-name: windows |
| 31 | + target: x86_64-pc-windows-msvc |
| 32 | + architecture: x86_64 |
| 33 | + binary-postfix: ".exe" |
| 34 | + use-cross: false |
| 35 | + - os: ubuntu-latest |
| 36 | + os-name: linux |
| 37 | + target: aarch64-unknown-linux-gnu |
| 38 | + architecture: arm64 |
| 39 | + binary-postfix: "" |
| 40 | + use-cross: true |
| 41 | + - os: ubuntu-latest |
| 42 | + os-name: linux |
| 43 | + target: i686-unknown-linux-gnu |
| 44 | + architecture: i686 |
| 45 | + binary-postfix: "" |
| 46 | + use-cross: true |
| 47 | + |
| 48 | + steps: |
| 49 | + - name: Checkout repository |
| 50 | + uses: actions/checkout@v3 |
| 51 | + - name: Install Rust toolchain |
| 52 | + uses: actions-rs/toolchain@v1 |
| 53 | + with: |
| 54 | + toolchain: ${{ matrix.rust }} |
| 55 | + profile: minimal |
| 56 | + override: true |
| 57 | + - uses: Swatinem/rust-cache@v1 |
| 58 | + - name: Cargo build |
| 59 | + uses: actions-rs/cargo@v1 |
| 60 | + with: |
| 61 | + command: build |
| 62 | + use-cross: ${{ matrix.job.use-cross }} |
| 63 | + toolchain: ${{ matrix.rust }} |
| 64 | + args: --release --target ${{ matrix.job.target }} |
| 65 | + |
| 66 | + - name: install strip command |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then |
| 70 | + sudo apt update |
| 71 | + sudo apt-get install -y binutils-aarch64-linux-gnu |
| 72 | + fi |
| 73 | + - name: Packaging final binary |
| 74 | + shell: bash |
| 75 | + run: | |
| 76 | + cd target/${{ matrix.job.target }}/release |
| 77 | +
|
| 78 | + ####### reduce binary size by removing debug symbols ####### |
| 79 | + BINARY_NAME=rtstore-tpl${{ matrix.job.binary-postfix }} |
| 80 | + if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then |
| 81 | + GCC_PREFIX="aarch64-linux-gnu-" |
| 82 | + else |
| 83 | + GCC_PREFIX="" |
| 84 | + fi |
| 85 | + "$GCC_PREFIX"strip $BINARY_NAME |
| 86 | +
|
| 87 | + ########## create tar.gz ########## |
| 88 | + RELEASE_NAME=rtstore-tpl-${GITHUB_REF/refs\/tags\//}-${{ matrix.job.os-name }}-${{ matrix.job.architecture }} |
| 89 | + tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME |
| 90 | +
|
| 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 | + - name: Releasing assets |
| 98 | + uses: softprops/action-gh-release@v1 |
| 99 | + with: |
| 100 | + files: | |
| 101 | + target/${{ matrix.job.target }}/release/rtstore-tpl-*.tar.gz |
| 102 | + target/${{ matrix.job.target }}/release/rtstore-tpl-*.sha256 |
| 103 | + env: |
| 104 | + GITHUB_TOKEN: ${{ secrets.CR_PAT }} |
| 105 | + |
| 106 | + publish-cargo: |
| 107 | + name: Publishing to Cargo |
| 108 | + runs-on: ubuntu-latest |
| 109 | + steps: |
| 110 | + - name: Checkout repository |
| 111 | + uses: actions/checkout@v3 |
| 112 | + - uses: actions-rs/toolchain@v1 |
| 113 | + with: |
| 114 | + toolchain: stable |
| 115 | + profile: minimal |
| 116 | + override: true |
| 117 | + - uses: Swatinem/rust-cache@v1 |
| 118 | + - uses: actions-rs/cargo@v1 |
| 119 | + with: |
| 120 | + command: publish |
| 121 | + args: --token ${{ secrets.CRATE_KEY}} |
0 commit comments