Skip to content

Commit 684faf8

Browse files
authored
Github action to build binaries for all OS/arch combos (#131)
1 parent 1dec839 commit 684faf8

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

.github/workflows/build.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build Rust binaries
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: Version to build (e.g. v0.4.1)
7+
required: true
8+
type: string
9+
10+
jobs:
11+
build-binary:
12+
runs-on: ${{ matrix.os.runner }}
13+
permissions:
14+
contents: write
15+
id-token: write
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
arch:
20+
- x64
21+
- arm64
22+
os:
23+
- name: linux
24+
runner: ubuntu-latest
25+
- name: windows
26+
runner: windows-latest
27+
- name: macos
28+
runner: macos-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
32+
with:
33+
ref: ${{ inputs.version }}
34+
- name: Get Rust target name
35+
id: rust-target
36+
env:
37+
RUST_OS: ${{ matrix.os.name }}
38+
RUST_ARCH: ${{ matrix.arch }}
39+
run: |
40+
echo target=$(.github/workflows/scripts/rust-build.sh --print-target) >> "$GITHUB_OUTPUT"
41+
- name: Rust toolkit setup
42+
uses: actions-rust-lang/setup-rust-toolchain@v1
43+
with:
44+
target: ${{ steps.rust-target.outputs.target }}
45+
- name: Build binary ${{ matrix.os.name }}-${{ matrix.arch }}
46+
env:
47+
RUST_OS: ${{ matrix.os.name }}
48+
RUST_ARCH: ${{ matrix.arch }}
49+
run: .github/workflows/scripts/rust-build.sh
50+
- name: Upload binaries to release
51+
uses: svenstaro/upload-release-action@v2
52+
with:
53+
tag: ${{ inputs.version }}
54+
release_id: ${{ inputs.version }}
55+
file: target/${{ steps.rust-target.outputs.target }}/release/elasticsearch-core-mcp-server
56+
asset_name: elasticsearch-core-mcp-server-${{ matrix.os.name }})-${{ matrix.arch }}
57+
overwrite: true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
PRINT_TARGET=false
4+
if [[ $1 == "--print-target" ]]; then
5+
PRINT_TARGET=true
6+
shift
7+
fi
8+
9+
# build Rust toolchain name
10+
if [[ "$RUST_ARCH" == "x64" ]]; then
11+
ARCH="x86_64"
12+
elif [[ "$RUST_ARCH" == "arm64" ]]; then
13+
ARCH="aarch64"
14+
else
15+
echo "Unsupported architecture: $RUST_ARCH"
16+
exit 1
17+
fi
18+
19+
if [[ "$RUST_OS" == "linux" ]]; then
20+
OS="unknown-linux-gnu"
21+
elif [[ "$RUST_OS" == "macos" ]]; then
22+
OS="apple-darwin"
23+
elif [[ "$RUST_OS" == "windows" ]]; then
24+
OS="pc-windows-msvc"
25+
else
26+
echo "Unsupported OS: $RUST_OS"
27+
exit 1
28+
fi
29+
30+
RUST_TOOLCHAIN="$ARCH-$OS"
31+
32+
if [[ "$PRINT_TARGET" == true ]]; then
33+
echo "$RUST_TOOLCHAIN"
34+
exit 0
35+
else
36+
cargo build --release --target "$RUST_TOOLCHAIN"
37+
fi

0 commit comments

Comments
 (0)