|
| 1 | +name: CD # Continuous Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[v]?[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + name: Publishing for ${{ matrix.job.os }} |
| 11 | + runs-on: ${{ matrix.job.os }} |
| 12 | + strategy: |
| 13 | + matrix: |
| 14 | + rust: [ stable ] |
| 15 | + job: |
| 16 | + - { os: macos-latest, target: x86_64-apple-darwin, architecture: x86_64, binary-postfix: "", use-cross: false } |
| 17 | + - { os: macos-latest, target: aarch64-apple-darwin, architecture: arm64, binary-postfix: "", use-cross: false } |
| 18 | + - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, architecture: x86_64, binary-postfix: "", use-cross: false } |
| 19 | + - { os: windows-latest, target: x86_64-pc-windows-msvc, architecture: x86_64, binary-postfix: ".exe", use-cross: false } |
| 20 | + - { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, architecture: arm64, binary-postfix: "", use-cross: true } |
| 21 | + - { os: ubuntu-latest, target: i686-unknown-linux-gnu, architecture: i686, binary-postfix: "", use-cross: true } |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Install Rust toolchain |
| 28 | + uses: actions-rs/toolchain@v1 |
| 29 | + with: |
| 30 | + toolchain: ${{ matrix.rust }} |
| 31 | + target: ${{ matrix.job.target }} |
| 32 | + profile: minimal |
| 33 | + override: true |
| 34 | + |
| 35 | + - uses: Swatinem/rust-cache@v2 |
| 36 | + |
| 37 | + - name: Build Cargo package |
| 38 | + uses: actions-rs/cargo@v1 |
| 39 | + with: |
| 40 | + command: build |
| 41 | + use-cross: ${{ matrix.job.use-cross }} |
| 42 | + toolchain: ${{ matrix.rust }} |
| 43 | + args: --release --target ${{ matrix.job.target }} |
| 44 | + |
| 45 | + - name: Install strip command (if needed) |
| 46 | + if: startsWith(matrix.job.target, 'aarch64') |
| 47 | + run: sudo apt-get install -y binutils-aarch64-linux-gnu |
| 48 | + |
| 49 | + - name: Package final binary |
| 50 | + run: | |
| 51 | + cd target/${{ matrix.job.target }}/release |
| 52 | + BINARY_NAME=example-rs${{ matrix.job.binary-postfix }} |
| 53 | + GCC_PREFIX=$( [ "${{ matrix.job.target }}" == "aarch64-unknown-linux-gnu" ] && echo "aarch64-linux-gnu-" || echo "" ) |
| 54 | + "$GCC_PREFIX"strip $BINARY_NAME |
| 55 | +
|
| 56 | + RELEASE_NAME=example-rs-${GITHUB_REF/refs\/tags\//}-${{ matrix.job.os-name }}-${{ matrix.job.architecture }} |
| 57 | + tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME |
| 58 | + shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256 |
| 59 | +
|
| 60 | + - name: Release assets |
| 61 | + uses: softprops/action-gh-release@v2 |
| 62 | + with: |
| 63 | + files: | |
| 64 | + target/${{ matrix.job.target }}/release/example-rs-*.tar.gz |
| 65 | + target/${{ matrix.job.target }}/release/example-rs-*.sha256 |
| 66 | + env: |
| 67 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + publish-cargo: |
| 69 | + name: Publishing to Cargo |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - name: Checkout repository |
| 73 | + uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: Install Rust toolchain |
| 76 | + uses: dtolnay/rust-toolchain@stable |
| 77 | + |
| 78 | + - uses: Swatinem/rust-cache@v2 |
| 79 | + |
| 80 | + - run: cargo publish |
| 81 | + env: |
| 82 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
0 commit comments