Repository navigation
110 lines (97 loc) · 4.59 KB
/
Copy pathpublish.yml
File metadata and controls
110 lines (97 loc) · 4.59 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
name: Publish
# Cut a release by pushing a `v*` tag (see CLAUDE.md): this publishes the crate
# to crates.io via Trusted Publishing (OIDC, no stored token) and then registers
# the server in the official MCP Registry via GitHub Actions OIDC, which grants
# the `io.github.tarides` namespace from the repo owner. release.yml builds the
# static tarball + GitHub release on the same tag, in parallel.
#
# Also runnable via workflow_dispatch (e.g. to (re)register the server when the
# crate is already published). The crate publish is skipped when the version in
# Cargo.toml is already on crates.io, so re-runs are safe.
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
id-token: write # OIDC for both crates.io Trusted Publishing and mcp-publisher
contents: read
env:
# crates.io rejects API requests without a User-Agent (HTTP 403).
CRATES_UA: "sudo-proxy-ci (+https://github.com/tarides/sudo-proxy)"
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
- name: Determine crate version
id: ver
run: |
VERSION=$(grep -m1 '^version' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Releasing sudo-proxy $VERSION"
# crates.io Trusted Publishing: exchange the OIDC token for a short-lived
# publish token (configured at crates.io -> sudo-proxy -> Trusted Publishing).
- name: Authenticate to crates.io
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
id: auth
- name: Publish crate to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
VERSION: ${{ steps.ver.outputs.version }}
run: |
if curl -fsS -A "$CRATES_UA" "https://crates.io/api/v1/crates/sudo-proxy/${VERSION}" >/dev/null 2>&1; then
echo "sudo-proxy ${VERSION} already on crates.io — skipping cargo publish"
else
cargo publish
fi
# The MCP Registry validates ownership by reading the `mcp-name:` marker
# and the version from the crate on crates.io, so the crate must be served
# before we publish the server. Poll until the index catches up.
- name: Wait for crate to be live on crates.io
env:
VERSION: ${{ steps.ver.outputs.version }}
run: |
for i in $(seq 1 30); do
if curl -fsS -A "$CRATES_UA" "https://crates.io/api/v1/crates/sudo-proxy/${VERSION}" >/dev/null; then
echo "sudo-proxy ${VERSION} is live"
exit 0
fi
echo "waiting for sudo-proxy ${VERSION} (attempt ${i})..."
sleep 10
done
echo "crate ${VERSION} did not appear on crates.io in time" >&2
exit 1
# The MCPB package entry in server.json points at a GitHub release asset
# (built + uploaded by release.yml on the same tag) and must carry that
# file's sha256. release.yml runs in parallel, so wait for the asset, then
# compute and inject the hash. The registry validates the URL with a HEAD
# request at publish time, so the asset must be live before we publish.
- name: Wait for MCPB asset and inject sha256 into server.json
run: |
URL=$(jq -r '.packages[] | select(.registryType=="mcpb") | .identifier' server.json)
echo "MCPB asset: $URL"
TMP=$(mktemp)
for i in $(seq 1 60); do
if curl -fsSL -A "$CRATES_UA" "$URL" -o "$TMP"; then
echo "MCPB asset is live"
break
fi
echo "waiting for MCPB asset (attempt ${i})..."
sleep 10
[ "$i" -eq 60 ] && { echo "MCPB asset did not appear in time" >&2; exit 1; }
done
SHA=$(sha256sum "$TMP" | awk '{print $1}')
echo "sha256=$SHA"
jq --arg h "$SHA" \
'(.packages[] | select(.registryType=="mcpb") | .fileSha256) = $h' \
server.json > server.json.tmp
mv server.json.tmp server.json
- 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
- name: Authenticate to MCP Registry
run: ./mcp-publisher login github-oidc
- name: Publish server to MCP Registry
run: ./mcp-publisher publish