name: Build and Release Probe Binary
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
build-and-release:
name: Build and Release for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
binary_ext: ""
archive_ext: "tar.gz"
- os: macos-latest
target: x86_64-apple-darwin
binary_ext: ""
archive_ext: "tar.gz"
- os: macos-latest
target: aarch64-apple-darwin
binary_ext: ""
archive_ext: "tar.gz"
- os: windows-latest
target: x86_64-pc-windows-msvc
binary_ext: ".exe"
archive_ext: "zip"
- os: ubuntu-22.04
target: aarch64-unknown-linux-gnu
binary_ext: ""
archive_ext: "tar.gz"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@1.84.0
with:
targets: ${{ matrix.target }}
components: rustfmt, clippy
- name: Setup Rust cache
uses: actions/cache@v4
timeout-minutes: 5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('rust-toolchain', 'rust-toolchain.toml') || 'stable' }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}-
${{ runner.os }}-${{ matrix.target }}-cargo-
${{ runner.os }}-cargo-
- name: Configure APT sources for arm64
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo bash -c 'cat > /etc/apt/sources.list << EOF
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb [arch=amd64] http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
deb [arch=amd64] http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted universe multiverse
deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted universe multiverse
EOF'
- name: Setup cross-compilation
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo dpkg --add-architecture arm64
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu pkg-config libssl-dev:arm64 libc6-dev-arm64-cross
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu" >> $GITHUB_ENV
echo "OPENSSL_INCLUDE_DIR=/usr/include" >> $GITHUB_ENV
- name: Build Release
shell: bash
run: |
if [[ "${{ matrix.target }}" == "x86_64-pc-windows-msvc" ]]; then
# For Windows, use static linking of the C++ runtime
mkdir -p .cargo
echo '[target.x86_64-pc-windows-msvc]' > .cargo/config.toml
echo 'rustflags = ["-C", "target-feature=+crt-static", "-C", "link-args=/DEBUG:NONE", "-C", "link-args=/NOLOGO"]' >> .cargo/config.toml
cargo build --release --target ${{ matrix.target }}
else
# For other platforms, use the default build
cargo build --release --target ${{ matrix.target }}
fi
- name: Install zip on Windows
if: runner.os == 'Windows'
run: |
choco install zip -y
- name: Package Binary
shell: bash
run: |
BINARY_NAME="probe"
VERSION="${GITHUB_REF#refs/tags/}" # Extracts tag like v1.0.0
ARCHIVE_NAME="$BINARY_NAME-${VERSION}-${{ matrix.target }}"
mkdir -p "$ARCHIVE_NAME"
# Copy binary
cp "target/${{ matrix.target }}/release/$BINARY_NAME${{ matrix.binary_ext }}" "$ARCHIVE_NAME/"
# Copy documentation and license files
cp README.md "$ARCHIVE_NAME/" || true
cp LICENSE "$ARCHIVE_NAME/" || true
cp ABOUT.MD "$ARCHIVE_NAME/" || true
# Create archive
if [ "${{ matrix.archive_ext }}" = "tar.gz" ]; then
tar -czf "$ARCHIVE_NAME.tar.gz" "$ARCHIVE_NAME"
echo "ASSET=$ARCHIVE_NAME.tar.gz" >> $GITHUB_ENV
elif [ "${{ matrix.archive_ext }}" = "zip" ]; then
zip -r "$ARCHIVE_NAME.zip" "$ARCHIVE_NAME"
echo "ASSET=$ARCHIVE_NAME.zip" >> $GITHUB_ENV
fi
# Generate SHA256 checksum
if [ "${{ runner.os }}" = "Windows" ]; then
certutil -hashfile "$ARCHIVE_NAME.${{ matrix.archive_ext }}" SHA256 | grep -v "^SHA256" | grep -v "^CertUtil" > "$ARCHIVE_NAME.${{ matrix.archive_ext }}.sha256"
else
shasum -a 256 "$ARCHIVE_NAME.${{ matrix.archive_ext }}" > "$ARCHIVE_NAME.${{ matrix.archive_ext }}.sha256"
fi
echo "CHECKSUM=$ARCHIVE_NAME.${{ matrix.archive_ext }}.sha256" >> $GITHUB_ENV
- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
${{ env.ASSET }}
${{ env.CHECKSUM }}
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-crates-io:
name: Publish to crates.io
needs: build-and-release
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Setup Rust cache
uses: actions/cache@v4
timeout-minutes: 5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('rust-toolchain', 'rust-toolchain.toml') || 'stable' }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-
${{ runner.os }}-cargo-
- name: Verify package can be published
run: cargo package --list
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
publish-mcp-agent:
name: Publish MCP Agent to npm
needs: publish-npm-package
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: extract_version
run: |
# Remove 'v' prefix from tag (e.g., v1.0.0 -> 1.0.0)
VERSION="${GITHUB_REF#refs/tags/v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
registry-url: "https://registry.npmjs.org/"
scope: "@buger"
token: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: cd mcp-agent && npm install
- name: Update package version and dependencies
run: |
cd mcp-agent
# Update version in package.json without git operations
npm version $VERSION --no-git-tag-version
# Update dependency on @buger/probe to use the specific version
npm pkg set dependencies."@buger/probe"="^$VERSION"
echo "Updated MCP Agent package.json to version $VERSION with @buger/probe dependency set to ^$VERSION"
- name: Build
run: cd mcp-agent && npm run build
- name: Publish to npm
run: cd mcp-agent && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-mcp:
name: Publish MCP to npm
needs: publish-npm-package
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: extract_version
run: |
# Remove 'v' prefix from tag (e.g., v1.0.0 -> 1.0.0)
VERSION="${GITHUB_REF#refs/tags/v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
registry-url: "https://registry.npmjs.org/"
scope: "@buger"
token: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: cd mcp && npm install
- name: Update package version and dependencies
run: |
cd mcp
# Update version in package.json without git operations
npm version $VERSION --no-git-tag-version
# Update dependency on @buger/probe to use the specific version
npm pkg set dependencies."@buger/probe"="^$VERSION"
echo "Updated MCP package.json to version $VERSION with @buger/probe dependency set to ^$VERSION"
- name: Build
run: cd mcp && npm run build
- name: Publish to npm
run: cd mcp && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-npm-package:
name: Publish Node.js Package to npm
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: extract_version
run: |
# Remove 'v' prefix from tag (e.g., v1.0.0 -> 1.0.0)
VERSION="${GITHUB_REF#refs/tags/v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
registry-url: "https://registry.npmjs.org/"
scope: "@buger"
token: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: cd npm && npm install
- name: Update package version
run: |
cd npm
# Update version in package.json without git operations
npm version $VERSION --no-git-tag-version
echo "Updated npm package.json to version $VERSION"
- name: Publish to npm
run: cd npm && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-probe-chat-package:
name: Publish Probe Chat Package to npm
needs: publish-npm-package
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: extract_version
run: |
# Remove 'v' prefix from tag (e.g., v1.0.0 -> 1.0.0)
VERSION="${GITHUB_REF#refs/tags/v}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Extracted version: $VERSION"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
registry-url: "https://registry.npmjs.org/"
scope: "@buger"
token: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: cd examples/chat && npm install
- name: Update package version and dependencies
run: |
cd examples/chat
# Update version in package.json without git operations
npm version $VERSION --no-git-tag-version
# Update dependency on @buger/probe to use the specific version
npm pkg set dependencies."@buger/probe"="^$VERSION"
echo "Updated probe-chat package.json to version $VERSION with @buger/probe dependency set to ^$VERSION"
- name: Publish to npm
run: cd examples/chat && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}