new, more reliable sponsorship system #22
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
| name: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| env: | |
| BIN_NAME: bot-rs | |
| PROJECT_NAME: bot-rs | |
| REPO_NAME: calagopus/bot | |
| jobs: | |
| dist: | |
| name: Dist | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| build: | |
| - x86_64-linux | |
| - aarch64-linux | |
| - riscv64-linux | |
| - ppc64le-linux | |
| include: | |
| - build: x86_64-linux | |
| os: ubuntu-24.04 | |
| target: x86_64-unknown-linux-musl | |
| - build: aarch64-linux | |
| os: ubuntu-24.04 | |
| target: aarch64-unknown-linux-musl | |
| - build: riscv64-linux | |
| os: ubuntu-24.04 | |
| target: riscv64gc-unknown-linux-gnu | |
| - build: ppc64le-linux | |
| os: ubuntu-24.04 | |
| target: powerpc64le-unknown-linux-gnu | |
| steps: | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| toolchain: stable | |
| target: ${{ matrix.target }} | |
| - name: Install cross | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Rust Cache | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| prefix-key: ${{ runner.os }}-${{ matrix.target }} | |
| - name: Run cargo test | |
| run: cross test --release --target ${{ matrix.target }} | |
| - name: Build release binary | |
| run: | | |
| RUSTFLAGS="-C target-feature=+crt-static" \ | |
| cross build --release --target ${{ matrix.target }} | |
| - name: Prepare binary with platform name | |
| run: | | |
| mkdir -p dist | |
| cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/$BIN_NAME-${{ matrix.build }}" | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.PROJECT_NAME }}-${{ matrix.build }} | |
| path: dist/${{ env.BIN_NAME }}-${{ matrix.build }} | |
| publish: | |
| name: Publish | |
| needs: [dist] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout sources | |
| uses: actions/checkout@v4 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Fetch version from Cargo.toml | |
| id: version | |
| run: echo "val=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT | |
| - name: Upload binaries to GitHub Release | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| file: artifacts/*/* | |
| file_glob: true | |
| tag: ${{ steps.version.outputs.val }} | |
| overwrite: true | |
| create-multiarch-image: | |
| name: Create multi-arch Docker image | |
| needs: [dist] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: dist | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Prepare binaries | |
| run: | | |
| mkdir -p .docker/amd64 .docker/arm64 .docker/riscv64 .docker/ppc64le .docker/s390x | |
| cp dist/${{ env.PROJECT_NAME }}-x86_64-linux/${{ env.BIN_NAME }}-x86_64-linux .docker/amd64/calagopus-bot | |
| cp dist/${{ env.PROJECT_NAME }}-aarch64-linux/${{ env.BIN_NAME }}-aarch64-linux .docker/arm64/calagopus-bot | |
| cp dist/${{ env.PROJECT_NAME }}-riscv64-linux/${{ env.BIN_NAME }}-riscv64-linux .docker/riscv64/calagopus-bot | |
| cp dist/${{ env.PROJECT_NAME }}-ppc64le-linux/${{ env.BIN_NAME }}-ppc64le-linux .docker/ppc64le/calagopus-bot | |
| chmod +x .docker/*/calagopus-bot | |
| - name: Extract version | |
| id: version | |
| run: echo "val=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT | |
| - name: Build & push multi-arch image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le | |
| push: true | |
| tags: ghcr.io/${{ env.REPO_NAME }}:latest,ghcr.io/${{ env.REPO_NAME }}:${{ steps.version.outputs.val }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |