forked from homeassistant-ai/ha-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (175 loc) · 6.55 KB
/
Copy pathrelease-publish.yml
File metadata and controls
199 lines (175 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Release Publish
on:
# Trigger after SemVer Release completes
workflow_run:
workflows: ["SemVer Release"]
types: [completed]
branches: [ main, master ]
# Also support manual dispatch
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
prepare:
name: Prepare release metadata
runs-on: ubuntu-latest
permissions:
contents: read
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
ref: master
fetch-depth: 0
- name: Extract version from pyproject.toml
id: version
run: |
VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Release version: $VERSION"
publish_pypi:
name: Publish PyPI package
needs: prepare
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/ha-mcp
permissions:
contents: read
id-token: write # Required for PyPI trusted publishing
env:
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
ref: master
fetch-depth: 0
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Build distribution
run: uv build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
skip-existing: true
publish_docker:
name: Publish Docker image
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Required to push to GHCR
env:
VERSION: ${{ needs.prepare.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
ref: master
fetch-depth: 0
- 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: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ env.VERSION }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }}
type=semver,pattern={{major}},value=${{ env.VERSION }}
type=raw,value=latest
type=raw,value=stable
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Match architectures supported by uv base image
# uv image only provides amd64 and arm64, not 32-bit platforms
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_VERSION=${{ env.VERSION }}
publish_mcp:
name: Publish MCP server manifest
needs: [publish_pypi, publish_docker, prepare]
runs-on: ubuntu-latest
if: ${{ always() }}
permissions:
contents: read
id-token: write # Required for MCP Registry OIDC authentication
env:
VERSION: ${{ needs.prepare.outputs.version }}
IMAGE: ghcr.io/${{ github.repository }}:${{ needs.prepare.outputs.version }}
steps:
- name: Report upstream job results
run: |
echo "PyPI publish conclusion: ${{ needs.publish_pypi.result }}"
echo "Docker publish conclusion: ${{ needs.publish_docker.result }}"
- uses: actions/checkout@v6
if: ${{ needs.publish_pypi.result == 'success' && needs.publish_docker.result == 'success' }}
with:
ref: master
fetch-depth: 0
- name: Install MCP Publisher CLI
if: ${{ needs.publish_pypi.result == 'success' && needs.publish_docker.result == 'success' }}
run: |
set -euo pipefail
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
- name: Render server manifest for publish
if: ${{ needs.publish_pypi.result == 'success' && needs.publish_docker.result == 'success' }}
run: |
set -euo pipefail
python scripts/render_server_manifest.py \
--input server.json \
--output server.json \
--version "$VERSION" \
--oci-image "$IMAGE"
cat server.json
- name: Validate server manifest
if: ${{ needs.publish_pypi.result == 'success' && needs.publish_docker.result == 'success' }}
run: |
set -euo pipefail
python -m pip install --quiet jsonschema
python scripts/validate_server_manifest.py server.json
- name: Login to MCP Registry
if: ${{ needs.publish_pypi.result == 'success' && needs.publish_docker.result == 'success' }}
run: ./mcp-publisher login github-oidc
- name: Publish server to MCP Registry
if: ${{ needs.publish_pypi.result == 'success' && needs.publish_docker.result == 'success' }}
run: |
set +e # Don't exit on error
OUTPUT=$(./mcp-publisher publish --server server.json 2>&1)
EXIT_CODE=$?
echo "$OUTPUT"
# If publish succeeded, we're done
if [ $EXIT_CODE -eq 0 ]; then
echo "✓ Successfully published to MCP Registry"
exit 0
fi
# If version already exists, treat as success
if echo "$OUTPUT" | grep -qi "cannot publish duplicate version\|version.*already.*exist\|already.*published"; then
echo "⚠ Version $VERSION already exists in MCP Registry (published previously)"
echo "✓ Treating as success"
exit 0
fi
# Any other error is a real failure
echo "✗ Failed to publish to MCP Registry"
exit $EXIT_CODE
- name: Skip MCP publish
if: ${{ needs.publish_pypi.result != 'success' || needs.publish_docker.result != 'success' }}
run: |
echo "Skipping MCP publish because one or more upstream publish jobs failed."