name: Publish DotNetMetadataMcpServer
on:
workflow_dispatch:
inputs:
versionOverride:
description: 'Override version (leave empty to use 1.0.0 with auto-incremented patch)'
required: false
type: string
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Run tests
run: dotnet test --configuration Release --no-build --logger "trx;LogFileName=test_results.trx"
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Set version
id: set-version
run: |
# Extract version prefix from project file
VERSION_PREFIX=$(grep -oP '<VersionPrefix>\K[^<]+' DotNetMetadataMcpServer/DotNetMetadataMcpServer.csproj)
if [ -z "$VERSION_PREFIX" ]; then
# Default version prefix if not found in project file
VERSION_PREFIX="1.0.0"
fi
if [ -n "${{ github.event.inputs.versionOverride }}" ]; then
# Use override version if provided
VERSION="${{ github.event.inputs.versionOverride }}"
else
# Use GitHub run number as patch version
VERSION="${VERSION_PREFIX}.${{ github.run_number }}"
fi
echo "Using version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
build-windows:
needs: [build, test]
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: |
dotnet publish DotNetMetadataMcpServer/DotNetMetadataMcpServer.csproj -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishReadyToRun=true /p:DebugType=None /p:DebugSymbols=false /p:Version=${{ needs.build.outputs.version }} /p:AssemblyVersion=${{ needs.build.outputs.version }}
- name: Create zip archive
run: |
$VERSION = "${{ needs.build.outputs.version }}"
$ZIP_NAME = "DotNetMetadataMcpServer-windows-x64-v$VERSION.zip"
Compress-Archive -Path DotNetMetadataMcpServer/bin/Release/net9.0/win-x64/publish/* -DestinationPath $ZIP_NAME
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: DotNetMetadataMcpServer-windows-x64
path: DotNetMetadataMcpServer-windows-x64-v${{ needs.build.outputs.version }}.zip
build-linux:
needs: [build, test]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: |
dotnet publish DotNetMetadataMcpServer/DotNetMetadataMcpServer.csproj -c Release -r linux-x64 --self-contained true /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishReadyToRun=true /p:DebugType=None /p:DebugSymbols=false /p:Version=${{ needs.build.outputs.version }} /p:AssemblyVersion=${{ needs.build.outputs.version }}
- name: Create zip archive
run: |
VERSION="${{ needs.build.outputs.version }}"
ZIP_NAME="DotNetMetadataMcpServer-linux-x64-v$VERSION.zip"
cd DotNetMetadataMcpServer/bin/Release/net9.0/linux-x64/publish/
chmod +x DotNetMetadataMcpServer
zip -r ../../../../../../$ZIP_NAME *
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: DotNetMetadataMcpServer-linux-x64
path: DotNetMetadataMcpServer-linux-x64-v${{ needs.build.outputs.version }}.zip
build-macos:
needs: [build, test]
runs-on: macos-latest
strategy:
matrix:
architecture: [osx-x64, osx-arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: |
dotnet publish DotNetMetadataMcpServer/DotNetMetadataMcpServer.csproj -c Release -r ${{ matrix.architecture }} --self-contained true /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishReadyToRun=true /p:DebugType=None /p:DebugSymbols=false /p:Version=${{ needs.build.outputs.version }} /p:AssemblyVersion=${{ needs.build.outputs.version }}
- name: Create zip archive
run: |
VERSION="${{ needs.build.outputs.version }}"
ZIP_NAME="DotNetMetadataMcpServer-${{ matrix.architecture }}-v$VERSION.zip"
cd DotNetMetadataMcpServer/bin/Release/net9.0/${{ matrix.architecture }}/publish/
zip -r ../../../../../../$ZIP_NAME *
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: DotNetMetadataMcpServer-${{ matrix.architecture }}
path: DotNetMetadataMcpServer-${{ matrix.architecture }}-v${{ needs.build.outputs.version }}.zip
build-docker:
needs: [build, test]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- 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: Log in to Docker Hub
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
continue-on-error: true
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
vrogozhin/dotnet-types-explorer-mcp
tags: |
type=raw,value=${{ needs.build.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
id: docker-build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ needs.build.outputs.version }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
if: github.event_name != 'pull_request'
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.docker-build.outputs.digest }}
push-to-registry: true
continue-on-error: true
create-release:
needs: [build, build-windows, build-linux, build-macos, build-docker]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build.outputs.version }}
name: Release v${{ needs.build.outputs.version }}
generate_release_notes: true
files: |
artifacts/DotNetMetadataMcpServer-windows-x64/DotNetMetadataMcpServer-windows-x64-v${{ needs.build.outputs.version }}.zip
artifacts/DotNetMetadataMcpServer-linux-x64/DotNetMetadataMcpServer-linux-x64-v${{ needs.build.outputs.version }}.zip
artifacts/DotNetMetadataMcpServer-osx-x64/DotNetMetadataMcpServer-osx-x64-v${{ needs.build.outputs.version }}.zip
artifacts/DotNetMetadataMcpServer-osx-arm64/DotNetMetadataMcpServer-osx-arm64-v${{ needs.build.outputs.version }}.zip
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ github.token }}