name: Release
on:
push:
tags:
- 'v*' # Triggers on version tags like v1.0.0, v2.1.3, etc.
permissions:
contents: write # Required for creating releases
id-token: write # Required for npm publishing with provenance
packages: write # Required for publishing image to ghcr
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }} # e.g. owner/repo (must be lowercase for Docker)
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch full history for changelog generation
- name: Use Node.js # will read version from .nvmrc
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run prettier
run: npm run prettier
- name: Run tests
run: npm run test:unit
- name: Build
run: npm run build
- name: Extract version from tag
id: version
run: |
# Remove 'v' prefix from tag to get version
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Generate changelog for GitHub Release
id: changelog
run: |
# Get the previous tag
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
# Generate changelog between tags
if [ -n "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s (%h)" $PREV_TAG..HEAD)
else
CHANGELOG=$(git log --pretty=format:"- %s (%h)")
fi
# Save changelog to output (handle multiline)
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Publish to npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
# Publish to npm with provenance
if [[ "${{ steps.version.outputs.version }}" == *"-"* ]]; then
# Pre-release version - publish with next tag
npm publish --tag next --provenance --access public
else
# Stable release - publish with latest tag
npm publish --provenance --access public
fi
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Create release body
cat > release_body.md << 'EOF'
## Changes in ${{ steps.version.outputs.tag }}
${{ steps.changelog.outputs.changelog }}
## Usage
```bash
npx -y @dynatrace-oss/dynatrace-managed-mcp-server@${{ steps.version.outputs.version }}
```
EOF
# Create the release
if [[ "${{ steps.version.outputs.version }}" == *"-"* ]]; then
gh release create "${{ steps.version.outputs.tag }}" \
--title "Release ${{ steps.version.outputs.tag }}" \
--notes-file release_body.md \
--prerelease
else
gh release create "${{ steps.version.outputs.tag }}" \
--title "Release ${{ steps.version.outputs.tag }}" \
--notes-file release_body.md
fi
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.version }}
type=raw,value=latest
- name: Build and push
id: ghcrpush
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
provenance: true
- name: Install cosign
uses: sigstore/cosign-installer@v4.0.0
- name: Sign ghcr image
run: |
cosign sign --yes "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.ghcrpush.outputs.digest }}"
# From https://github.com/modelcontextprotocol/registry/blob/main/docs/guides/publishing/github-actions.md
- name: Install MCP Publisher
run: |
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
# Login to GitHub - apparently this works out of the box with GH Workflows
- name: Login to MCP Registry
run: ./mcp-publisher login github-oidc
# Publish the package to the MCP Registry
- name: Publish to MCP Registry
run: ./mcp-publisher publish