|
| 1 | +# Before usage |
| 2 | +# - Change name of output files |
| 3 | +# - Change lint command if needed |
| 4 | + |
| 5 | +name: Release CLI |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: |
| 10 | + - "v*.*.*" |
| 11 | + |
| 12 | +env: |
| 13 | + CARGO_TERM_COLOR: always |
| 14 | + BINARY_NAME: change_me |
| 15 | + |
| 16 | +jobs: |
| 17 | + lint: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Install stable Rust |
| 23 | + uses: dtolnay/rust-toolchain@stable |
| 24 | + with: |
| 25 | + components: clippy |
| 26 | + |
| 27 | + - name: Cache Rust dependencies |
| 28 | + |
| 29 | + with: |
| 30 | + env-vars: "CARGO RUST" |
| 31 | + cache-on-failure: true |
| 32 | + |
| 33 | + - name: lint |
| 34 | + run: cargo clippy # instruct some packages if needed |
| 35 | + |
| 36 | + build-and-release: |
| 37 | + name: Build and Release |
| 38 | + runs-on: ${{ matrix.os }} |
| 39 | + needs: [lint] |
| 40 | + strategy: |
| 41 | + matrix: |
| 42 | + include: |
| 43 | + # linux x64 |
| 44 | + - os: ubuntu-latest |
| 45 | + target: x86_64-unknown-linux-gnu |
| 46 | + artifact_name: change_me |
| 47 | + asset_name: change_me-linux-amd64 |
| 48 | + |
| 49 | + # linux arm |
| 50 | + - os: ubuntu-latest |
| 51 | + target: aarch64-unknown-linux-gnu |
| 52 | + artifact_name: change_me |
| 53 | + asset_name: change_me-linux-arm |
| 54 | + |
| 55 | + # windows x64 |
| 56 | + - os: windows-latest |
| 57 | + target: x86_64-pc-windows-gnu |
| 58 | + artifact_name: change_me.exe |
| 59 | + asset_name: change_me-windows-amd64.exe |
| 60 | + |
| 61 | + # windows arm |
| 62 | + - os: windows-latest |
| 63 | + target: aarch64-pc-windows-msvc |
| 64 | + artifact_name: change_me.exe |
| 65 | + asset_name: change_me-windows-arm.exe |
| 66 | + |
| 67 | + # macos x64 |
| 68 | + - os: macos-latest |
| 69 | + target: x86_64-apple-darwin |
| 70 | + artifact_name: change_me |
| 71 | + asset_name: change_me-macos-amd64 |
| 72 | + |
| 73 | + # macos arm |
| 74 | + - os: macos-latest |
| 75 | + target: aarch64-apple-darwin |
| 76 | + artifact_name: change_me |
| 77 | + asset_name: change_me-macos-arm |
| 78 | + |
| 79 | + steps: |
| 80 | + - uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Install Rust |
| 83 | + run: rustup toolchain install stable --profile minimal |
| 84 | + |
| 85 | + - name: Add target |
| 86 | + run: rustup target add ${{ matrix.target }} |
| 87 | + |
| 88 | + - name: Install Linux ARM dependencies |
| 89 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 90 | + run: | |
| 91 | + sudo apt-get update |
| 92 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 93 | +
|
| 94 | + - name: Set linker for Linux ARM |
| 95 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 96 | + run: | |
| 97 | + echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config.toml |
| 98 | + echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml |
| 99 | +
|
| 100 | + - uses: Swatinem/rust-cache@v2 |
| 101 | + with: |
| 102 | + prefix-key: "v0-rust" |
| 103 | + shared-key: "${{ matrix.target }}" |
| 104 | + cache-on-failure: "true" |
| 105 | + cache-all-crates: "true" |
| 106 | + workspaces: | |
| 107 | + . -> target |
| 108 | + cache-targets: "true" |
| 109 | + |
| 110 | + - name: Build |
| 111 | + uses: actions-rs/cargo@v1 |
| 112 | + with: |
| 113 | + command: build |
| 114 | + args: --release --target ${{ matrix.target }} |
| 115 | + |
| 116 | + - name: Prepare artifact |
| 117 | + shell: bash |
| 118 | + run: | |
| 119 | + mkdir -p artifacts |
| 120 | + if [ "${{ matrix.os }}" = "windows-latest" ]; then |
| 121 | + cp "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" "artifacts/${{ matrix.asset_name }}" |
| 122 | + else |
| 123 | + cp "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" "artifacts/${{ matrix.asset_name }}" |
| 124 | + fi |
| 125 | +
|
| 126 | + - name: Upload artifact |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: ${{ matrix.asset_name }} |
| 130 | + path: artifacts/${{ matrix.asset_name }} |
| 131 | + |
| 132 | + create-release: |
| 133 | + needs: build-and-release |
| 134 | + runs-on: ubuntu-latest |
| 135 | + steps: |
| 136 | + - name: Download artifacts |
| 137 | + uses: actions/download-artifact@v4 |
| 138 | + |
| 139 | + - name: Create Release |
| 140 | + id: create_release |
| 141 | + uses: softprops/action-gh-release@v2 |
| 142 | + with: |
| 143 | + files: | |
| 144 | + change_me-linux-amd64/change_me-linux-amd64 |
| 145 | + change_me-windows-amd64.exe/change_me-windows-amd64.exe |
| 146 | + change_me-macos-amd64/change_me-macos-amd64 |
| 147 | + change_me-linux-arm/change_me-linux-arm |
| 148 | + change_me-windows-arm.exe/change_me-windows-arm.exe |
| 149 | + change_me-macos-arm/change_me-macos-arm |
| 150 | + draft: false |
| 151 | + prerelease: false |
| 152 | + generate_release_notes: true |
| 153 | + append_bode: true |
| 154 | + make_latest: true |
| 155 | + env: |
| 156 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments