Skip to content

Commit 0e1acff

Browse files
chore: fix publish workflow for MCP registry (#786)
1 parent 2762666 commit 0e1acff

File tree

4 files changed

+133
-33
lines changed

4 files changed

+133
-33
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: Build and Push Docker Image
3+
on:
4+
workflow_call:
5+
secrets:
6+
DOCKERHUB_USERNAME:
7+
required: true
8+
DOCKERHUB_PASSWORD:
9+
required: true
10+
11+
jobs:
12+
build-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
19+
with:
20+
persist-credentials: false
21+
22+
- name: Get version and date
23+
id: release-meta
24+
run: |
25+
VERSION=$(npm pkg get version | tr -d '"')
26+
DATE=$(date +'%Y-%m-%d')
27+
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
28+
echo "DATE=${DATE}" >> "$GITHUB_OUTPUT"
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
32+
33+
- name: Login to Docker Hub
34+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef
35+
with:
36+
username: "${{ secrets.DOCKERHUB_USERNAME }}"
37+
password: "${{ secrets.DOCKERHUB_PASSWORD }}"
38+
39+
- name: Build and push image to dockerhub registry
40+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
41+
with:
42+
context: .
43+
platforms: linux/amd64,linux/arm64
44+
tags: ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:latest, ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:${{ steps.release-meta.outputs.VERSION }}, ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:${{ steps.release-meta.outputs.VERSION }}-${{ steps.release-meta.outputs.DATE }}
45+
file: Dockerfile
46+
push: true
47+
provenance: mode=max
48+
sbom: true
49+
build-args: |
50+
VERSION=${{ steps.release-meta.outputs.VERSION }}

.github/workflows/docker.yml

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@ permissions:
77
contents: read
88
issues: write
99
jobs:
10-
push:
10+
docker-push:
11+
uses: ./.github/workflows/docker-publish.yml
12+
permissions:
13+
contents: read
14+
secrets:
15+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
16+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
17+
18+
handle-failure:
1119
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
issues: write
23+
needs: docker-push
24+
if: ${{ always() && needs.docker-push.result == 'failure' }}
1225
steps:
1326
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
1427
with:
@@ -17,43 +30,22 @@ jobs:
1730
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1831
with:
1932
persist-credentials: false
20-
- name: Set up Docker Buildx
21-
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
22-
- name: Login to Docker Hub
23-
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef
24-
with:
25-
username: "${{ secrets.DOCKERHUB_USERNAME }}"
26-
password: "${{ secrets.DOCKERHUB_PASSWORD }}"
27-
- name: Set date and version
28-
id: set-properties
33+
- name: Get version and date
34+
id: release-meta
2935
run: |
30-
DATE=$(date +'%Y-%m-%d')
3136
VERSION=$(npm pkg get version | tr -d '"')
32-
echo "DATE=${DATE}" >> "$GITHUB_OUTPUT"
37+
DATE=$(date +'%Y-%m-%d')
3338
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
34-
- name: Build and push image to dockerhub registry
35-
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
36-
with:
37-
context: .
38-
platforms: linux/amd64,linux/arm64
39-
tags: ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:latest, ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}, ${{ vars.DOCKERHUB_IMAGE_REPOSITORY }}:${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }}
40-
file: Dockerfile
41-
push: true
42-
provenance: mode=max
43-
sbom: true
44-
build-args: |
45-
VERSION=${{ steps.set-properties.outputs.VERSION }}
39+
echo "DATE=${DATE}" >> "$GITHUB_OUTPUT"
4640
- uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
4741
id: app-token
48-
if: ${{ failure() }}
4942
with:
5043
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
5144
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
5245
- name: Create Issue
53-
if: ${{ failure() }}
5446
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
5547
with:
5648
token: ${{ steps.app-token.outputs.token }}
57-
title: Release Failure for Docker Image ${{ steps.set-properties.outputs.VERSION }}-${{ steps.set-properties.outputs.DATE }}
49+
title: Release Failure for Docker Image ${{ steps.release-meta.outputs.VERSION }}-${{ steps.release-meta.outputs.DATE }}
5850
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
5951
labels: "docker, release_failure"

.github/workflows/mcp-publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Publish to MCP Registry
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
jobs:
8+
mcp-publish:
9+
runs-on: ubuntu-latest
10+
environment: Production
11+
permissions:
12+
id-token: write
13+
contents: read
14+
steps:
15+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
16+
- uses: actions/checkout@v5
17+
with:
18+
persist-credentials: false
19+
20+
- name: Install MCP Publisher
21+
run: |
22+
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
23+
24+
- name: Login to MCP Registry
25+
run: ./mcp-publisher login github-oidc
26+
27+
- name: Publish to MCP Registry
28+
run: ./mcp-publisher publish

.github/workflows/publish.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,42 @@ jobs:
101101
run: |
102102
gh release create ${{ needs.check.outputs.VERSION }} --title "${{ needs.check.outputs.VERSION }}" --generate-notes --target ${{ github.sha }} ${{ (needs.check.outputs.RELEASE_CHANNEL != 'latest' && '--prerelease') || ''}}
103103
104-
- name: Install MCP Publisher
104+
- name: Wait for package to be available on npm
105105
run: |
106-
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
106+
PACKAGE_NAME=$(jq -r '.name' < package.json)
107+
VERSION="${{ needs.check.outputs.VERSION }}"
108+
# Strip the 'v' prefix for npm
109+
NPM_VERSION="${VERSION#v}"
110+
MAX_ATTEMPTS=30
111+
SLEEP_SECONDS=10
107112
108-
- name: Login to MCP Registry
109-
run: ./mcp-publisher login github-oidc
113+
echo "Waiting for ${PACKAGE_NAME}@${NPM_VERSION} to be available on npm..."
110114
111-
- name: Publish to MCP Registry
112-
run: ./mcp-publisher publish
115+
for i in $(seq 1 $MAX_ATTEMPTS); do
116+
if npm view "${PACKAGE_NAME}@${NPM_VERSION}" version >/dev/null 2>&1; then
117+
echo "✓ Package ${PACKAGE_NAME}@${NPM_VERSION} is now available on npm"
118+
exit 0
119+
fi
120+
echo "Attempt $i/$MAX_ATTEMPTS: Package not yet available, waiting ${SLEEP_SECONDS}s..."
121+
sleep $SLEEP_SECONDS
122+
done
123+
124+
echo "::error::Package ${PACKAGE_NAME}@${NPM_VERSION} did not become available after $((MAX_ATTEMPTS * SLEEP_SECONDS)) seconds"
125+
exit 1
126+
127+
docker-push:
128+
needs: [check, publish]
129+
uses: ./.github/workflows/docker-publish.yml
130+
permissions:
131+
contents: read
132+
secrets:
133+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
134+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
135+
136+
mcp-publish:
137+
needs: [check, docker-push]
138+
if: needs.check.outputs.VERSION_EXISTS == 'false'
139+
uses: ./.github/workflows/mcp-publish.yml
140+
permissions:
141+
id-token: write
142+
contents: read

0 commit comments

Comments
 (0)