.github/workflows/build.yml #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - 'binaries/**' | |
| - 'crates/**' | |
| - 'data/generated/**' | |
| - 'java_wrapper/**' | |
| - 'Cargo.lock' | |
| - 'Cargo.toml' | |
| - 'docker/Dockerfile.ci' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| CARGO_TERM_COLOR: always | |
| BINARY_NAME: pico_lobby | |
| LIB_NAME: pico_lobby_lib | |
| jobs: | |
| build-linux: | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-musl | |
| name: linux-x86_64-musl | |
| runner: ubuntu-latest | |
| library: false | |
| - target: aarch64-unknown-linux-musl | |
| name: linux-aarch64-musl | |
| runner: ubuntu-24.04-arm | |
| library: false | |
| - target: x86_64-unknown-linux-gnu | |
| name: linux-x86_64-gnu | |
| runner: ubuntu-latest | |
| library: true | |
| - target: aarch64-unknown-linux-gnu | |
| name: linux-aarch64-gnu | |
| runner: ubuntu-24.04-arm | |
| library: true | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - if: contains(matrix.target, 'musl') | |
| run: | | |
| sudo apt-get update -y | |
| sudo apt-get install -y musl-tools | |
| - run: rustup target add ${{ matrix.target }} | |
| - uses: actions/cache@v6 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ runner.arch }}-cargo-${{ matrix.target }}- | |
| ${{ runner.os }}-${{ runner.arch }}-cargo- | |
| - run: | | |
| if [ "${{ matrix.library }}" = "true" ]; then | |
| cargo build --release --target ${{ matrix.target }} --bin ${{ env.BINARY_NAME }} --lib | |
| else | |
| cargo build --release --target ${{ matrix.target }} --bin ${{ env.BINARY_NAME }} | |
| fi | |
| - if: matrix.library == true | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: lib-${{ matrix.name }} | |
| path: target/${{ matrix.target }}/release/lib${{ env.LIB_NAME }}.so | |
| - run: | | |
| mkdir -p artifacts | |
| cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} artifacts/ | |
| cd artifacts && tar -czf ../${{ env.BINARY_NAME }}_${{ matrix.name }}.tar.gz * | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ env.BINARY_NAME }}_${{ matrix.name }} | |
| path: ${{ env.BINARY_NAME }}_${{ matrix.name }}.tar.gz | |
| build-macos: | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - run: rustup target add aarch64-apple-darwin | |
| - uses: actions/cache@v6 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-aarch64-apple-darwin-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-aarch64-apple-darwin- | |
| ${{ runner.os }}-cargo- | |
| - run: cargo build --release --target aarch64-apple-darwin --bin ${{ env.BINARY_NAME }} --lib | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: lib-macos-aarch64 | |
| path: target/aarch64-apple-darwin/release/lib${{ env.LIB_NAME }}.dylib | |
| - run: | | |
| mkdir -p artifacts | |
| cp target/aarch64-apple-darwin/release/${{ env.BINARY_NAME }} artifacts/ | |
| cd artifacts && tar -czf ../${{ env.BINARY_NAME }}_macos-aarch64.tar.gz * | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ env.BINARY_NAME }}_macos-aarch64 | |
| path: ${{ env.BINARY_NAME }}_macos-aarch64.tar.gz | |
| build-windows: | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - run: rustup target add x86_64-pc-windows-msvc | |
| - uses: actions/cache@v6 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-cargo-x86_64-pc-windows-msvc-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo-x86_64-pc-windows-msvc- | |
| ${{ runner.os }}-cargo- | |
| - run: cargo build --release --target x86_64-pc-windows-msvc --bin ${{ env.BINARY_NAME }} --lib | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: lib-windows-x86_64 | |
| path: target/x86_64-pc-windows-msvc/release/${{ env.LIB_NAME }}.dll | |
| - run: | | |
| mkdir artifacts | |
| Copy-Item "target/x86_64-pc-windows-msvc/release/${{ env.BINARY_NAME }}.exe" artifacts/ | |
| Compress-Archive -Path artifacts/* -DestinationPath "${{ env.BINARY_NAME }}_windows-x86_64.zip" -Force | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ env.BINARY_NAME }}_windows-x86_64 | |
| path: ${{ env.BINARY_NAME }}_windows-x86_64.zip | |
| build-java: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-linux | |
| - build-macos | |
| - build-windows | |
| defaults: | |
| run: | |
| working-directory: java_wrapper | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'liberica' | |
| java-version: '21' | |
| cache: 'gradle' | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: lib-linux-x86_64-gnu | |
| path: java_wrapper/wrapper/src/main/resources/linux/x86_64 | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: lib-linux-aarch64-gnu | |
| path: java_wrapper/wrapper/src/main/resources/linux/aarch64 | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: lib-macos-aarch64 | |
| path: java_wrapper/wrapper/src/main/resources/macos/aarch64 | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: lib-windows-x86_64 | |
| path: java_wrapper/wrapper/src/main/resources/windows/x86_64 | |
| - run: ls -R wrapper/src/main/resources | |
| - run: | | |
| chmod +x gradlew | |
| ./gradlew build | |
| - run: | | |
| mv wrapper/build/libs/wrapper.jar ../${{ env.BINARY_NAME }}_java_wrapper.jar | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: ${{ env.BINARY_NAME }}_java_wrapper | |
| path: ${{ env.BINARY_NAME }}_java_wrapper.jar | |
| build-docker: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| runner: ubuntu-latest | |
| artifact_suffix: linux-x86_64-musl | |
| - platform: linux/arm64 | |
| runner: ubuntu-24.04-arm | |
| artifact_suffix: linux-aarch64-musl | |
| runs-on: ${{ matrix.runner }} | |
| needs: | |
| - build-linux | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - run: | | |
| platform=${{ matrix.platform }} | |
| echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
| - uses: actions/checkout@v7 | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| name: ${{ env.BINARY_NAME }}_${{ matrix.artifact_suffix }} | |
| path: ./docker | |
| - run: | | |
| cd docker | |
| tar -xzf ${{ env.BINARY_NAME }}_${{ matrix.artifact_suffix }}.tar.gz | |
| chmod +x ${{ env.BINARY_NAME }} | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| - run: | | |
| echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| - id: build | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: docker | |
| file: docker/Dockerfile.ci | |
| platforms: ${{ matrix.platform }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| tags: ghcr.io/${{ env.REPO_LC }} | |
| outputs: type=image,push-by-digest=true,name-canonical=true,push=true | |
| cache-from: type=gha,scope=${{ env.PLATFORM_PAIR }}-${{ matrix.runner }} | |
| cache-to: type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}-${{ matrix.runner }} | |
| - run: | | |
| mkdir -p ${{ runner.temp }}/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "${{ runner.temp }}/digests/${digest#sha256:}" | |
| - uses: actions/upload-artifact@v7 | |
| with: | |
| name: digests-${{ env.PLATFORM_PAIR }} | |
| path: ${{ runner.temp }}/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge-docker: | |
| runs-on: ubuntu-latest | |
| needs: build-docker | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/download-artifact@v8 | |
| with: | |
| path: ${{ runner.temp }}/digests | |
| pattern: digests-* | |
| merge-multiple: true | |
| - uses: docker/setup-buildx-action@v4 | |
| - uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=tag | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - run: | | |
| echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| - working-directory: ${{ runner.temp }}/digests | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf 'ghcr.io/${{ env.REPO_LC }}@sha256:%s ' *) | |
| - run: | | |
| docker buildx imagetools inspect ghcr.io/${{ env.REPO_LC }}:${{ steps.meta.outputs.version }} |