workflow.yml•6.04 kB
name: Inspektor Gadget MCP Server CI
env:
REGISTRY: 'ghcr.io'
GO_VERSION: '1.24'
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
workflow_dispatch:
permissions: read-all
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Build Go application
run: |
go vet -v ./...
go build ./...
- name: Run tests
run: |
go test -v ./...
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Prepare version
id: prepare-version
run: |
# Determine the version for ig-mcp-server
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
COMMIT=$(git rev-parse --short HEAD)
VERSION="sha-${COMMIT}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Determine the version for the Docker image
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
IMAGE_VERSION="${GITHUB_REF#refs/tags/v}"
else
IMAGE_VERSION="latest"
fi
echo "image_version=$IMAGE_VERSION" >> $GITHUB_OUTPUT
- name: Extract metadata
id: extract-metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
- name: Build and Push image
if: github.event_name != 'pull_request'
id: push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
context: .
file: Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ github.repository }}:${{ steps.prepare-version.outputs.image_version }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ steps.prepare-version.outputs.version }}
build-binaries:
name: Build Binaries
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
- os: windows
arch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Build and generate tarball
run: |
target=ig-mcp-server-${{ matrix.os }}-${{ matrix.arch }}
make $target
binary_name=ig-mcp-server
# Since the binary name is different on Windows, we handle it separately
if [ ${{ matrix.os }} = "windows" ]; then
mv $target.exe $binary_name.exe
tar --sort=name --owner=root:0 --group=root:0 \
-czf ${target}.tar.gz \
$binary_name.exe
exit 0
fi
# Prepare binary as artifact, it will be used by other jobs
mv $target $binary_name
tar --sort=name --owner=root:0 --group=root:0 \
-czf ${target}.tar.gz \
$binary_name
- name: Add ig-mcp-server-${{ matrix.os }}-${{ matrix.arch }}.tar.gz as artifact
uses: actions/upload-artifact@v4
with:
name: ig-mcp-server-${{ matrix.os }}-${{ matrix.arch }}-tar-gz
path: ig-mcp-server-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
lint:
name: Lint Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Lint
uses: golangci/golangci-lint-action@v9
with:
# This version number must be kept in sync with Makefile lint one.
version: v2.1.6
working-directory: /home/runner/work/ig-mcp-server/ig-mcp-server
docker-build:
name: Test Docker Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Test Docker Image
uses: docker/build-push-action@v6
with:
context: .
tags: mcp/inspektor-gadget
file: Dockerfile
push: false
load: true
platforms: linux/amd64
- name: Validate Docker Image
run: |
npx --yes @modelcontextprotocol/inspector@0.16.3 \
--cli docker run --rm -i mcp/inspektor-gadget -gadget-discoverer=artifacthub --method tools/list
release:
name: Release
runs-on: ubuntu-latest
needs: [lint, build, build-binaries, docker-build]
permissions:
contents: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Create Draft Release
id: create_release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: Release ${{ github.ref_name }}
draft: true
- name: Get all artifacts
uses: actions/download-artifact@v5
with:
pattern: ig-mcp-server-*-tar-gz
- name: Upload ig-mcp-server binaries as release assets
uses: csexton/release-asset-action@v3
with:
pattern: "ig-mcp-server-*-*-tar-gz/ig-mcp-server-*-*.tar.gz"
github-token: ${{ secrets.GITHUB_TOKEN }}
release-url: ${{ steps.create_release.outputs.upload_url }}