|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # manual trigger release |
| 5 | + inputs: |
| 6 | + create_release: |
| 7 | + description: 'Create new release' |
| 8 | + required: true |
| 9 | + type: boolean |
| 10 | + release_version: |
| 11 | + description: "Version (e.g. 1.0.0)" |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + |
| 15 | +jobs: |
| 16 | + build_macos: |
| 17 | + name: build_macos |
| 18 | + runs-on: ${{ matrix.os }} |
| 19 | + strategy: |
| 20 | + matrix: |
| 21 | + build: [macos-x86_64, macos-arm64] |
| 22 | + include: |
| 23 | + - build: macos-x86_64 |
| 24 | + os: macos-latest |
| 25 | + rust: stable |
| 26 | + target: x86_64-apple-darwin |
| 27 | + archive-name: cardea-weather-apple-darwin-x86_64.tar.gz |
| 28 | + bin-path: macos-x86_64-binary |
| 29 | + - build: macos-arm64 |
| 30 | + os: macos-latest |
| 31 | + rust: stable |
| 32 | + target: aarch64-apple-darwin |
| 33 | + archive-name: cardea-weather-apple-darwin-aarch64.tar.gz |
| 34 | + bin-path: macos-arm64-binary |
| 35 | + fail-fast: false |
| 36 | + steps: |
| 37 | + - name: Checkout repository |
| 38 | + id: checkout |
| 39 | + uses: actions/checkout@v5 |
| 40 | + |
| 41 | + - name: Install Rust |
| 42 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 43 | + with: |
| 44 | + toolchain: ${{ matrix.rust }} |
| 45 | + target: ${{ matrix.target }} |
| 46 | + |
| 47 | + - name: List targets |
| 48 | + run: | |
| 49 | + rustup target list --installed |
| 50 | +
|
| 51 | + - name: Build binary |
| 52 | + run: cargo build --release --target ${{ matrix.target }} |
| 53 | + env: |
| 54 | + RUST_BACKTRACE: 1 |
| 55 | + |
| 56 | + - name: Strip binary |
| 57 | + run: | |
| 58 | + strip "target/${{ matrix.target }}/release/cardea-weather" |
| 59 | +
|
| 60 | + ls -al "target/${{ matrix.target }}/release" |
| 61 | +
|
| 62 | + - name: Build archive |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + mkdir archive |
| 66 | + cd archive |
| 67 | +
|
| 68 | + cp "../target/${{ matrix.target }}/release/cardea-weather" ./ |
| 69 | +
|
| 70 | + tar -czf "${{ matrix.archive-name }}" * |
| 71 | + ls -al |
| 72 | +
|
| 73 | + - name: Upload archive |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: ${{ matrix.bin-path }} |
| 77 | + path: archive/${{ matrix.archive-name }} |
| 78 | + |
| 79 | + build_linux: |
| 80 | + name: build_linux |
| 81 | + runs-on: ${{ matrix.os }} |
| 82 | + container: |
| 83 | + image: ${{ matrix.image }} |
| 84 | + strategy: |
| 85 | + matrix: |
| 86 | + build: [linux-x86_64, linux-aarch64] |
| 87 | + include: |
| 88 | + - build: linux-x86_64 |
| 89 | + os: ubuntu-22.04 |
| 90 | + image: ubuntu:20.04 |
| 91 | + rust: nightly |
| 92 | + target: x86_64-unknown-linux-gnu |
| 93 | + archive-name: cardea-weather-unknown-linux-gnu-x86_64.tar.gz |
| 94 | + bin-path: linux-x86_64-binary |
| 95 | + - build: linux-aarch64 |
| 96 | + os: ubuntu-22.04-arm |
| 97 | + image: arm64v8/ubuntu:20.04 |
| 98 | + rust: nightly |
| 99 | + target: aarch64-unknown-linux-gnu |
| 100 | + archive-name: cardea-weather-unknown-linux-gnu-aarch64.tar.gz |
| 101 | + bin-path: linux-aarch64-binary |
| 102 | + fail-fast: false |
| 103 | + steps: |
| 104 | + - name: Checkout repository |
| 105 | + id: checkout |
| 106 | + uses: actions/checkout@v5 |
| 107 | + |
| 108 | + - name: Install dependencies silently |
| 109 | + run: | |
| 110 | + export DEBIAN_FRONTEND=noninteractive |
| 111 | + apt update && apt install -y curl build-essential pkg-config |
| 112 | +
|
| 113 | + - name: Install Rust-stable |
| 114 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 115 | + |
| 116 | + - name: Build binary |
| 117 | + run: cargo build --release --target ${{ matrix.target }} |
| 118 | + env: |
| 119 | + RUST_BACKTRACE: 1 |
| 120 | + |
| 121 | + - name: Strip binary |
| 122 | + run: | |
| 123 | + strip "target/${{ matrix.target }}/release/cardea-weather" |
| 124 | +
|
| 125 | + ls -al "target/${{ matrix.target }}/release" |
| 126 | +
|
| 127 | + - name: Build archive |
| 128 | + shell: bash |
| 129 | + run: | |
| 130 | + mkdir archive |
| 131 | + cd archive |
| 132 | +
|
| 133 | + cp "../target/${{ matrix.target }}/release/cardea-weather" ./ |
| 134 | +
|
| 135 | + tar -czf "${{ matrix.archive-name }}" * |
| 136 | + ls -al |
| 137 | +
|
| 138 | + - name: Upload archive |
| 139 | + uses: actions/upload-artifact@v4 |
| 140 | + with: |
| 141 | + name: ${{ matrix.bin-path }} |
| 142 | + path: archive/${{ matrix.archive-name }} |
| 143 | + |
| 144 | + release: |
| 145 | + name: release |
| 146 | + runs-on: ubuntu-latest |
| 147 | + permissions: |
| 148 | + contents: write |
| 149 | + needs: [build_macos, build_linux] |
| 150 | + steps: |
| 151 | + - name: Download artifacts (linux-x86_64-binary) |
| 152 | + uses: actions/download-artifact@v4 |
| 153 | + with: |
| 154 | + name: linux-x86_64-binary |
| 155 | + path: linux-x86_64-binary |
| 156 | + |
| 157 | + - name: Download artifacts (linux-aarch64-binary) |
| 158 | + uses: actions/download-artifact@v4 |
| 159 | + with: |
| 160 | + name: linux-aarch64-binary |
| 161 | + path: linux-aarch64-binary |
| 162 | + |
| 163 | + - name: Download artifacts (macos-x86_64-binary) |
| 164 | + uses: actions/download-artifact@v4 |
| 165 | + with: |
| 166 | + name: macos-x86_64-binary |
| 167 | + path: macos-x86_64-binary |
| 168 | + |
| 169 | + - name: Download artifacts (macos-arm64-binary) |
| 170 | + uses: actions/download-artifact@v4 |
| 171 | + with: |
| 172 | + name: macos-arm64-binary |
| 173 | + path: macos-arm64-binary |
| 174 | + |
| 175 | + - name: Display structure of downloaded files |
| 176 | + run: | |
| 177 | + ls -al |
| 178 | + ls -al linux-x86_64-binary |
| 179 | + ls -al linux-aarch64-binary |
| 180 | + ls -al macos-x86_64-binary |
| 181 | + ls -al macos-arm64-binary |
| 182 | +
|
| 183 | + - name: Tag and release names |
| 184 | + id: tag_and_release_names |
| 185 | + run: | |
| 186 | + echo "tag_name=${{ github.event.inputs.release_version }}" >> $GITHUB_OUTPUT |
| 187 | + echo "release_name=Cardea-Weather ${{ github.event.inputs.release_version }}" >> $GITHUB_OUTPUT |
| 188 | +
|
| 189 | + - name: Create Release and Upload Release Asset |
| 190 | + if: ${{ github.event.inputs.create_release == 'true' && github.ref == 'refs/heads/main'}} |
| 191 | + uses: softprops/action-gh-release@v2.2.2 |
| 192 | + with: |
| 193 | + name: ${{ steps.tag_and_release_names.outputs.release_name }} |
| 194 | + tag_name: ${{ steps.tag_and_release_names.outputs.tag_name }} |
| 195 | + body: TODO New Release. |
| 196 | + draft: true |
| 197 | + prerelease: true |
| 198 | + files: | |
| 199 | + linux-x86_64-binary/* |
| 200 | + linux-aarch64-binary/* |
| 201 | + macos-x86_64-binary/* |
| 202 | + macos-arm64-binary/* |
0 commit comments