Build & release sidecar #39
This file contains 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: Build & release sidecar | |
on: | |
workflow_dispatch: | |
env: | |
CARGO_INCREMENTAL: 0 | |
CARGO_NET_RETRY: 10 | |
VERSIONS_REPOSITORY: ${{ github.repository_owner }}/versions | |
jobs: | |
build: | |
name: ${{ matrix.job.name }} | |
runs-on: ${{ matrix.job.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
job: | |
- { target: aarch64-unknown-linux-gnu , os: ubuntu-24.04, use-cross: true, name: linux-arm64 } | |
- { target: arm-unknown-linux-gnueabihf, os: ubuntu-24.04, use-cross: true, name: linux-armhf } | |
- { target: riscv64gc-unknown-linux-gnu, os: ubuntu-24.04, use-cross: true, name: linux-riscv64 } | |
- { target: x86_64-unknown-linux-gnu , os: ubuntu-24.04, use-cross: true, name: linux-x64 } | |
- { target: x86_64-pc-windows-msvc , os: windows-2019, name: win32-x64 } | |
- { target: aarch64-pc-windows-msvc , os: windows-2019, name: win32-arm64 } | |
- { target: x86_64-apple-darwin , os: macos-13, name: darwin-x64 } | |
- { target: aarch64-apple-darwin , os: macos-14, name: darwin-arm64 } | |
env: | |
BUILD_CMD: cargo | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Point gcloud SDK to Python | |
shell: bash | |
run: echo "CLOUDSDK_PYTHON=${{ steps.setup-python.outputs.python-path }}" >> $GITHUB_ENV | |
- name: Extract build target information | |
shell: bash | |
run: | | |
OS=$(echo "${{ matrix.job.name }}" | cut -d'-' -f1) | |
ARCH=$(echo "${{ matrix.job.name }}" | cut -d'-' -f2) | |
echo "OS_NAME=${OS}" >> $GITHUB_ENV | |
echo "ARCH=${ARCH}" >> $GITHUB_ENV | |
- name: Install Linux cross-compilation dependencies | |
if: runner.os == 'Linux' | |
shell: bash | |
run: | | |
sudo apt-get -y update | |
case ${{ matrix.job.target }} in | |
arm-unknown-linux-*) sudo apt-get -y install gcc-arm-linux-gnueabihf ;; | |
aarch64-unknown-linux-gnu) sudo apt-get -y install gcc-aarch64-linux-gnu ;; | |
esac | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: 1.79.0 | |
targets: ${{ matrix.job.target }} | |
components: rust-src | |
- name: Install target std library | |
if: matrix.job.target == 'aarch64-pc-windows-msvc' | |
run: | | |
rustup target add aarch64-pc-windows-msvc | |
rustup component add rust-std-aarch64-pc-windows-msvc | |
- name: Install cross for cross-compilation | |
if: matrix.job.use-cross | |
shell: bash | |
run: | | |
cargo install cross --git https://github.com/cross-rs/cross | |
- name: Overwrite build command env variable | |
if: matrix.job.use-cross | |
shell: bash | |
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
shared-key: ${{ matrix.job.target }} | |
- name: Build binary | |
shell: bash | |
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }} | |
- name: Set binary name & path | |
id: bin | |
shell: bash | |
run: | | |
# Figure out suffix of binary | |
EXE_suffix="" | |
case ${{ matrix.job.target }} in | |
*-pc-windows-*) EXE_suffix=".exe" ;; | |
esac; | |
# Setup paths | |
BIN_NAME="webserver${EXE_suffix}" | |
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}" | |
# Let subsequent steps know where to find the binary | |
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT | |
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT | |
- name: Create zip file | |
shell: pwsh | |
run: | | |
# Create a staging directory structure | |
New-Item -ItemType Directory -Force -Path staging/target/release | |
# Copy binary to staging directory with correct name | |
if ($env:RUNNER_OS -eq "Windows") { | |
Copy-Item "${{ steps.bin.outputs.BIN_PATH }}" "staging/target/release/webserver.exe" | |
} else { | |
Copy-Item "${{ steps.bin.outputs.BIN_PATH }}" "staging/target/release/webserver" | |
} | |
# Create zip file | |
Push-Location staging | |
if ($env:RUNNER_OS -eq "Windows") { | |
Compress-Archive -Path * -DestinationPath ../sidecar.zip -Force | |
} else { | |
zip -r ../sidecar.zip . | |
} | |
Pop-Location | |
- name: Authenticate with Google Cloud | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: '${{ secrets.GCP_GAE_SA_KEY }}' | |
- name: Configure Google Cloud SDK | |
uses: 'google-github-actions/setup-gcloud@v2' | |
with: | |
project_id: '${{ secrets.GCP_PROJECT_ID }}' | |
- name: Update version | |
env: | |
OS_NAME: ${{ env.OS_NAME }} | |
ARCH: ${{ env.ARCH }} | |
GITHUB_TOKEN: ${{ secrets.BINARIES_RELEASE_PAT }} | |
GITHUB_USERNAME: ${{ github.repository_owner }} | |
run: | | |
./update_version.sh | |
- name: Upload zip to GCP | |
env: | |
OS_NAME: ${{ env.OS_NAME }} | |
ARCH: ${{ env.ARCH }} | |
CARGO_PKG_VERSION: ${{ env.CARGO_PKG_VERSION }} | |
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} | |
GCP_BUCKET_NAME: ${{ secrets.GCP_BUCKET_NAME }} | |
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }} | |
shell: bash | |
run: | | |
SPECIFIC_VERSION_PATH="${CARGO_PKG_VERSION}/${OS_NAME}/${ARCH}/sidecar.zip" | |
LATEST_VERSION_PATH="latest/${OS_NAME}/${ARCH}/sidecar.zip" | |
# Copy the built binary to version-specific folder in GCP bucket | |
gsutil cp "./sidecar.zip" "gs://sidecar-bin/${SPECIFIC_VERSION_PATH}" | |
# Also update the latest version | |
gsutil cp "./sidecar.zip" "gs://sidecar-bin/${LATEST_VERSION_PATH}" |