|
| 1 | +name: Build/publish release |
| 2 | + |
| 3 | +#on: [push, pull_request] |
| 4 | +on: |
| 5 | + push: |
| 6 | + # Pattern matched against refs/tags |
| 7 | + tags: |
| 8 | + - "*" # Push events to every tag not containing / |
| 9 | + |
| 10 | +jobs: |
| 11 | + # cargo publish libraries and xiu to crates.io |
| 12 | + publish: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Install Rust toolchain |
| 21 | + uses: dtolnay/rust-toolchain@stable |
| 22 | + |
| 23 | + - name: Replace Online Manifest file |
| 24 | + run: make online |
| 25 | + |
| 26 | + - name: Install Cargo-workspace |
| 27 | + uses: baptiste0928/cargo-install@v3 |
| 28 | + with: |
| 29 | + crate: cargo-workspaces |
| 30 | + version: "^0.3.1" # You can specify any semver range |
| 31 | + |
| 32 | + - name: Run cargo workspace publish |
| 33 | + run: cargo workspaces publish --from-git --no-git-push --no-git-tag --no-global-tag --allow-dirty --token ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 34 | + |
| 35 | + # release on github including writing release note and build binaries on different os and upload |
| 36 | + release: |
| 37 | + name: Binary ${{ matrix.target }} (on ${{ matrix.os }}) |
| 38 | + runs-on: ${{ matrix.os }} |
| 39 | + needs: publish |
| 40 | + outputs: |
| 41 | + version: ${{ steps.extract_version.outputs.version }} |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + include: |
| 45 | + # supported |
| 46 | + - os: ubuntu-latest |
| 47 | + target: x86_64-unknown-linux-musl |
| 48 | + compress: true |
| 49 | + cargo_flags: "" |
| 50 | + |
| 51 | + # supported |
| 52 | + - os: ubuntu-latest |
| 53 | + target: x86_64-unknown-linux-gnu |
| 54 | + compress: true |
| 55 | + cargo_flags: "" |
| 56 | + |
| 57 | + #- os: ubuntu-latest |
| 58 | + # target: aarch64-unknown-linux-musl |
| 59 | + # compress: true |
| 60 | + # cargo_flags: "" |
| 61 | + |
| 62 | + # supported |
| 63 | + - os: ubuntu-latest |
| 64 | + target: aarch64-unknown-linux-gnu |
| 65 | + compress: true |
| 66 | + cargo_flags: "" |
| 67 | + |
| 68 | + #- os: ubuntu-latest |
| 69 | + # target: armv7-unknown-linux-musleabihf |
| 70 | + # compress: true |
| 71 | + # cargo_flags: "" |
| 72 | + |
| 73 | + # supported |
| 74 | + - os: ubuntu-latest |
| 75 | + target: armv7-unknown-linux-gnueabihf |
| 76 | + compress: true |
| 77 | + cargo_flags: "" |
| 78 | + |
| 79 | + #- os: ubuntu-latest |
| 80 | + # target: arm-unknown-linux-musleabihf |
| 81 | + # compress: true |
| 82 | + # cargo_flags: "" |
| 83 | + |
| 84 | + ##- os: ubuntu-latest |
| 85 | + ## target: riscv64gc-unknown-linux-gnu |
| 86 | + ## compress: false |
| 87 | + ## cargo_flags: "--no-default-features" |
| 88 | + |
| 89 | + # supported |
| 90 | + - os: windows-latest |
| 91 | + target: x86_64-pc-windows-msvc |
| 92 | + compress: true |
| 93 | + cargo_flags: "" |
| 94 | + |
| 95 | + # supported |
| 96 | + - os: windows-latest |
| 97 | + target: i686-pc-windows-msvc |
| 98 | + compress: true |
| 99 | + cargo_flags: "" |
| 100 | + |
| 101 | + # supported |
| 102 | + - os: macos-latest |
| 103 | + target: x86_64-apple-darwin |
| 104 | + compress: true |
| 105 | + cargo_flags: "" |
| 106 | + |
| 107 | + ## - os: macos-latest |
| 108 | + ## target: aarch64-apple-darwin |
| 109 | + ## compress: false |
| 110 | + ## cargo_flags: "" |
| 111 | + |
| 112 | + # supported |
| 113 | + - os: ubuntu-latest |
| 114 | + target: x86_64-unknown-freebsd |
| 115 | + compress: false |
| 116 | + cargo_flags: "" |
| 117 | + |
| 118 | + steps: |
| 119 | + - name: Checkout code |
| 120 | + uses: actions/checkout@v3 |
| 121 | + |
| 122 | + - name: Setup Rust toolchain |
| 123 | + uses: dtolnay/rust-toolchain@stable |
| 124 | + |
| 125 | + - run: sudo apt install musl-tools pkg-config libssl-dev gcc-multilib |
| 126 | + if: startsWith(matrix.os, 'ubuntu') |
| 127 | + |
| 128 | + - name: Set up project |
| 129 | + run: | |
| 130 | + export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/x86_64-linux-gnu/pkgconfig/ |
| 131 | + echo $PKG_CONFIG_PATH |
| 132 | + find /usr/lib -name openssl.pc |
| 133 | + #cat /usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc |
| 134 | + #dpkg -l | grep openssl |
| 135 | +
|
| 136 | + #/usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc |
| 137 | + if: startsWith(matrix.os, 'ubuntu') |
| 138 | + |
| 139 | + - name: cargo build |
| 140 | + uses: houseabsolute/actions-rust-cross@v0 |
| 141 | + with: |
| 142 | + command: build |
| 143 | + working-directory: ./application/xiu |
| 144 | + args: --release --locked ${{ matrix.cargo_flags }} |
| 145 | + target: ${{ matrix.target }} |
| 146 | + |
| 147 | + - name: Set exe extension for Windows |
| 148 | + run: echo "EXE=.exe" >> $env:GITHUB_ENV |
| 149 | + if: startsWith(matrix.os, 'windows') |
| 150 | + |
| 151 | + - name: Compress binaries |
| 152 | + uses: svenstaro/upx-action@v2 |
| 153 | + with: |
| 154 | + files: target/${{ matrix.target }}/release/xiu${{ env.EXE }} |
| 155 | + args: --best --lzma |
| 156 | + strip: false # We're stripping already in Cargo.toml |
| 157 | + if: ${{ matrix.compress }} |
| 158 | + |
| 159 | + - name: Copy Files |
| 160 | + if: ${{ !startsWith(matrix.os, 'windows') }} |
| 161 | + run: | |
| 162 | + echo ${GITHUB_WORKSPACE} |
| 163 | + ls -lrth |
| 164 | + cp -rf "./application/xiu/src/config/examples" "target/${{ matrix.target }}/release/" |
| 165 | + cp -f "./protocol/webrtc/src/clients/index.html" "target/${{ matrix.target }}/release/" |
| 166 | + cp -f "./protocol/webrtc/src/clients/whep.js" "target/${{ matrix.target }}/release/" |
| 167 | + cp -f "./docker/start.sh" "target/${{ matrix.target }}/release/" |
| 168 | +
|
| 169 | + - name: Upload artifact |
| 170 | + uses: actions/upload-artifact@v3 |
| 171 | + with: |
| 172 | + name: ${{ matrix.target }} |
| 173 | + path: | |
| 174 | + target/${{ matrix.target }}/release/xiu${{ env.EXE }} |
| 175 | + target/${{ matrix.target }}/release/config/examples |
| 176 | + target/${{ matrix.target }}/release/index.html |
| 177 | + target/${{ matrix.target }}/release/whep.js |
| 178 | + target/${{ matrix.target }}/release/start.sh |
| 179 | +
|
| 180 | + - name: Get version from tag |
| 181 | + id: extract_version |
| 182 | + run: | |
| 183 | + echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" |
| 184 | + shell: bash |
| 185 | + |
| 186 | + - name: Install CHANGELOG parser |
| 187 | + uses: taiki-e/install-action@parse-changelog |
| 188 | + |
| 189 | + - name: Get CHANGELOG entry |
| 190 | + run: parse-changelog ./application/xiu/CHANGELOG.md ${{ steps.extract_version.outputs.version }} | tee changelog_entry |
| 191 | + if: startsWith(github.ref_name, 'v') && github.ref_type == 'tag' |
| 192 | + shell: bash |
| 193 | + |
| 194 | + - name: Read changelog entry from file |
| 195 | + id: changelog_entry |
| 196 | + uses: juliangruber/read-file-action@v1 |
| 197 | + with: |
| 198 | + path: ./changelog_entry |
| 199 | + if: startsWith(github.ref_name, 'v') && github.ref_type == 'tag' |
| 200 | + |
| 201 | + - name: Release |
| 202 | + uses: svenstaro/upload-release-action@v2 |
| 203 | + with: |
| 204 | + repo_token: ${{ secrets.ACCESS_TOKEN }} |
| 205 | + file: target/${{ matrix.target }}/release/xiu${{ env.EXE }} |
| 206 | + tag: ${{ github.ref_name }} |
| 207 | + asset_name: xiu-${{ steps.extract_version.outputs.version }}-${{ matrix.target }}${{ env.EXE }} |
| 208 | + body: ${{ steps.changelog_entry.outputs.content }} |
| 209 | + if: startsWith(github.ref_name, 'v') && github.ref_type == 'tag' |
| 210 | + |
| 211 | + # Build docker images and upload to docker hub |
| 212 | + container-images: |
| 213 | + name: Publish images |
| 214 | + runs-on: ubuntu-latest |
| 215 | + needs: release |
| 216 | + # Run for tags and pushes to the default branch |
| 217 | + if: (startsWith(github.ref_name, 'v') && github.ref_type == 'tag') || github.event.repository.default_branch == github.ref_name |
| 218 | + |
| 219 | + steps: |
| 220 | + - name: Checkout code |
| 221 | + uses: actions/checkout@v3 |
| 222 | + |
| 223 | + - name: Download artifact aarch64-unknown-linux-gnu |
| 224 | + uses: actions/download-artifact@v3 |
| 225 | + with: |
| 226 | + name: aarch64-unknown-linux-gnu |
| 227 | + path: target/aarch64-unknown-linux-gnu/release |
| 228 | + |
| 229 | + - name: Download artifact x86_64-unknown-linux-gnu |
| 230 | + uses: actions/download-artifact@v3 |
| 231 | + with: |
| 232 | + name: x86_64-unknown-linux-gnu |
| 233 | + path: target/x86_64-unknown-linux-gnu/release |
| 234 | + |
| 235 | + - name: Download artifact armv7-unknown-linux-gnueabihf |
| 236 | + uses: actions/download-artifact@v3 |
| 237 | + with: |
| 238 | + name: armv7-unknown-linux-gnueabihf |
| 239 | + path: target/armv7-unknown-linux-gnueabihf/release |
| 240 | + |
| 241 | + #- name: Download artifact aarch64-unknown-linux-musl |
| 242 | + # uses: actions/download-artifact@v3 |
| 243 | + # with: |
| 244 | + # name: aarch64-unknown-linux-musl |
| 245 | + # path: target/aarch64-unknown-linux-musl/release |
| 246 | + |
| 247 | + #- name: Download artifact x86_64-unknown-linux-musl |
| 248 | + # uses: actions/download-artifact@v3 |
| 249 | + # with: |
| 250 | + # name: x86_64-unknown-linux-musl |
| 251 | + # path: target/x86_64-unknown-linux-musl/release |
| 252 | + |
| 253 | + #- name: Download artifact armv7-unknown-linux-musleabihf |
| 254 | + # uses: actions/download-artifact@v3 |
| 255 | + # with: |
| 256 | + # name: armv7-unknown-linux-musleabihf |
| 257 | + # path: target/armv7-unknown-linux-musleabihf/release |
| 258 | + |
| 259 | + - name: podman login |
| 260 | + run: podman login --username ${{ secrets.DOCKERHUB_USERNAME }} --password ${{ secrets.DOCKERHUB_TOKEN }} docker.io |
| 261 | + |
| 262 | + - name: podman build linux/arm64 |
| 263 | + run: ls -lrth target/aarch64-unknown-linux-gnu/release/ && podman build --format docker --platform linux/arm64/v8 --manifest xiu -f ./docker/Dockerfile target/aarch64-unknown-linux-gnu/release |
| 264 | + |
| 265 | + - name: podman build linux/amd64 |
| 266 | + run: podman build --format docker --platform linux/amd64 --manifest xiu -f ./docker/Dockerfile target/x86_64-unknown-linux-gnu/release |
| 267 | + |
| 268 | + - name: podman build linux/arm |
| 269 | + run: podman build --format docker --platform linux/arm/v7 --manifest xiu -f ./docker/Dockerfile target/armv7-unknown-linux-gnueabihf/release |
| 270 | + |
| 271 | + - name: podman manifest push latest |
| 272 | + run: podman manifest push xiu docker.io/harlancn/xiu:latest |
| 273 | + |
| 274 | + - name: podman manifest push tag version |
| 275 | + run: podman manifest push xiu docker.io/harlancn/xiu:${{ needs.publish.outputs.version }} |
| 276 | + if: startsWith(github.ref_name, 'v') |
| 277 | + |
| 278 | + #- name: podman build linux/arm64 (alpine edition) |
| 279 | + # run: podman build --format docker --platform linux/arm64/v8 --manifest myexe-alpine -f Containerfile.alpine target/aarch64-unknown-linux-musl/release |
| 280 | + |
| 281 | + #- name: podman build linux/amd64 (alpine edition) |
| 282 | + # run: podman build --format docker --platform linux/amd64 --manifest myexe-alpine -f Containerfile.alpine target/x86_64-unknown-linux-musl/release |
| 283 | + |
| 284 | + #- name: podman build linux/arm (alpine edition) |
| 285 | + # run: podman build --format docker --platform linux/arm/v7 --manifest myexe-alpine -f Containerfile.alpine target/armv7-unknown-linux-musleabihf/release |
| 286 | + |
| 287 | + #- name: podman manifest push latest (alpine edition) |
| 288 | + # run: podman manifest push myexe-alpine docker.io/harlancn/myexe:alpine |
| 289 | + |
| 290 | + #- name: podman manifest push tag version (alpine edition) |
| 291 | + # run: podman manifest push myexe-alpine docker.io/harlancn/myexe:${{ needs.publish.outputs.version }}-alpine |
| 292 | + # if: startsWith(github.ref_name, 'v') |
0 commit comments