Skip to content

ci: add torii-arcade and torii-server release targets #28

ci: add torii-arcade and torii-server release targets

ci: add torii-arcade and torii-server release targets #28

Workflow file for this run

name: Release
on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
inputs:
binary:
description: 'Binary to release'
required: true
type: choice
options:
- torii-tokens
- torii-arcade
- torii-server
- torii-erc20
env:
CARGO_TERM_COLOR: always
jobs:
prepare:
name: Prepare Release
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'prepare-release-'))
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.release-info.outputs.TAG_NAME }}
version: ${{ steps.release-info.outputs.VERSION }}
binary_name: ${{ steps.release-info.outputs.BINARY_NAME }}
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install cargo-get
run: cargo install cargo-get
- name: Extract release info
id: release-info
run: |
# Determine release target
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
RELEASE_TARGET="${{ inputs.binary }}"
echo "Manual trigger for binary: $RELEASE_TARGET"
else
BRANCH_REF="${{ github.event.pull_request.head.ref }}"
if [[ "$BRANCH_REF" =~ ^prepare-release-(.+)$ ]]; then
RELEASE_TARGET="${BASH_REMATCH[1]}"
echo "PR-based trigger for binary: $RELEASE_TARGET"
else
echo "Error: Unknown release branch format: $BRANCH_REF"
echo "Expected: prepare-release-<binary-name>"
exit 1
fi
fi
case "$RELEASE_TARGET" in
torii-tokens)
PACKAGE_ENTRY="bins/torii-tokens"
BINARY_NAME="torii-tokens"
;;
torii-arcade)
PACKAGE_ENTRY="bins/torii-arcade"
BINARY_NAME="torii-arcade"
;;
torii-server)
PACKAGE_ENTRY="bins/torii-introspect-bin"
BINARY_NAME="torii-server"
;;
torii-erc20)
PACKAGE_ENTRY="bins/torii-erc20"
BINARY_NAME="torii-erc20"
;;
*)
echo "Error: Unknown release target: $RELEASE_TARGET"
exit 1
;;
esac
VERSION=$(cargo get package.version --entry "$PACKAGE_ENTRY")
TAG_NAME="${BINARY_NAME}-v${VERSION}"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_OUTPUT
echo "Binary: $BINARY_NAME"
echo "Version: $VERSION"
echo "Tag: $TAG_NAME"
build-binaries:
name: Build ${{ needs.prepare.outputs.binary_name }} - ${{ matrix.job.platform }}-${{ matrix.job.arch }}
needs: prepare
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
- os: ubuntu-latest-8-cores
platform: linux
target: x86_64-unknown-linux-gnu
arch: amd64
- os: ubuntu-latest-8-cores-arm64
platform: linux
target: aarch64-unknown-linux-gnu
arch: arm64
- os: macos-latest-large
platform: darwin
target: x86_64-apple-darwin
arch: amd64
- os: macos-latest-xlarge
platform: darwin
target: aarch64-apple-darwin
arch: arm64
- os: windows-latest
platform: win32
target: x86_64-pc-windows-msvc
arch: amd64
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.job.target }}
cache-on-failure: true
- name: Install protoc
uses: arduino/setup-protoc@v2
with:
version: "25.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup macOS ARM64
if: matrix.job.platform == 'darwin' && matrix.job.arch == 'arm64'
run: |
export SDKROOT=$(xcrun -sdk macosx --show-sdk-path)
export MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)
echo "SDKROOT=$SDKROOT" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET" >> $GITHUB_ENV
- name: Setup Linux ARM64
if: matrix.job.platform == 'linux' && matrix.job.arch == 'arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> $GITHUB_ENV
- name: Setup Windows
if: matrix.job.platform == 'win32'
run: |
echo "RUSTFLAGS=-Csymbol-mangling-version=v0" >> $env:GITHUB_ENV
- name: Build ${{ needs.prepare.outputs.binary_name }}
run: cargo build --release --target ${{ matrix.job.target }} --bin ${{ needs.prepare.outputs.binary_name }}
- name: Create archives (Unix)
if: matrix.job.platform != 'win32'
run: |
VERSION="${{ needs.prepare.outputs.version }}"
PLATFORM="${{ matrix.job.platform }}"
ARCH="${{ matrix.job.arch }}"
TARGET="${{ matrix.job.target }}"
BINARY="${{ needs.prepare.outputs.binary_name }}"
# Create archive for release
cd target/${TARGET}/release
tar -czvf ${BINARY}_${VERSION}_${PLATFORM}_${ARCH}.tar.gz ${BINARY}
mv ${BINARY}_${VERSION}_${PLATFORM}_${ARCH}.tar.gz ../../../
cd ../../..
# For Linux, stage binaries for Docker
if [ "$PLATFORM" = "linux" ]; then
mkdir -p docker-staging/${PLATFORM}/${ARCH}
cp target/${TARGET}/release/${BINARY} docker-staging/${PLATFORM}/${ARCH}/
fi
- name: Create archives (Windows)
if: matrix.job.platform == 'win32'
run: |
$VERSION = "${{ needs.prepare.outputs.version }}"
$PLATFORM = "${{ matrix.job.platform }}"
$ARCH = "${{ matrix.job.arch }}"
$TARGET = "${{ matrix.job.target }}"
$BINARY = "${{ needs.prepare.outputs.binary_name }}"
cd target\${TARGET}\release
7z a -tzip ${BINARY}_${VERSION}_${PLATFORM}_${ARCH}.zip ${BINARY}.exe
Move-Item ${BINARY}_${VERSION}_${PLATFORM}_${ARCH}.zip ..\..\..\..
- name: Upload binary artifacts (Linux only)
if: matrix.job.platform == 'linux'
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.job.target }}
path: docker-staging/
retention-days: 1
- name: Upload archive artifacts
uses: actions/upload-artifact@v4
with:
name: archives-${{ matrix.job.target }}
path: |
*.tar.gz
*.zip
retention-days: 1
create-draft-release:
name: Create Draft Release
needs: [prepare, build-binaries]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all archives
uses: actions/download-artifact@v4
with:
pattern: archives-*
path: artifacts
merge-multiple: true
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${{ needs.prepare.outputs.tag_name }}"
BINARY="${{ needs.prepare.outputs.binary_name }}"
VERSION="${{ needs.prepare.outputs.version }}"
# Collect all archive files (tar.gz and zip)
shopt -s nullglob # Don't fail if no matches
ARCHIVES=(./artifacts/*.tar.gz ./artifacts/*.zip)
if [ ${#ARCHIVES[@]} -eq 0 ]; then
echo "Error: No archive files found in ./artifacts/"
exit 1
fi
echo "Found ${#ARCHIVES[@]} archive files to release"
gh release create "$TAG_NAME" \
"${ARCHIVES[@]}" \
--draft \
--generate-notes \
--title "${BINARY}_v${VERSION}" \
--notes "Release **${BINARY}** version **${VERSION}**
## Assets
This release includes **${BINARY}** binaries for:
- Linux (x64, ARM64)
- macOS (x64, ARM64)
- Windows (x64)
## Docker Image
Multi-platform Docker image is available at:
- \`ghcr.io/${{ github.repository }}/${BINARY}:${VERSION}\`
- \`ghcr.io/${{ github.repository }}/${BINARY}:latest\`
"
docker-build-push:
name: Build Docker Image
needs: [prepare, build-binaries]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Download Linux AMD64 binaries
uses: actions/download-artifact@v4
with:
name: binaries-x86_64-unknown-linux-gnu
path: docker-context/
- name: Download Linux ARM64 binaries
uses: actions/download-artifact@v4
with:
name: binaries-aarch64-unknown-linux-gnu
path: docker-context/
- name: Prepare Docker context
run: |
mkdir -p docker-build-${{ needs.prepare.outputs.binary_name }}
cp docker/Dockerfile.${{ needs.prepare.outputs.binary_name }} docker-build-${{ needs.prepare.outputs.binary_name }}/Dockerfile
mv docker-context/linux docker-build-${{ needs.prepare.outputs.binary_name }}/
ls -R docker-build-${{ needs.prepare.outputs.binary_name }}/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: docker-build-${{ needs.prepare.outputs.binary_name }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ github.repository }}/${{ needs.prepare.outputs.binary_name }}:latest
ghcr.io/${{ github.repository }}/${{ needs.prepare.outputs.binary_name }}:${{ needs.prepare.outputs.version }}
labels: |
org.opencontainers.image.title=${{ needs.prepare.outputs.binary_name }}
org.opencontainers.image.version=${{ needs.prepare.outputs.version }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=MIT