-
Notifications
You must be signed in to change notification settings - Fork 5
304 lines (256 loc) · 10.3 KB
/
release.yml
File metadata and controls
304 lines (256 loc) · 10.3 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# Workflow: Release
#
# This workflow is triggered when a tag is pushed to the repository.
# It builds binaries for multiple platforms, creates a GitHub release,
# and uploads the built artifacts as release assets.
name: Release
# Trigger: Run when tags matching semantic versioning pattern are pushed
on:
push:
tags:
- 'v*.*.*' # Matches tags like v1.0.0, v2.1.3, etc.
# Set permissions for release creation and asset uploads
permissions:
contents: write # Required for creating releases and uploading assets
packages: write # Required for publishing packages
# Define environment variables for the release process
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
# Define the release jobs
jobs:
# Job 1: Create the GitHub release
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
release_version: ${{ env.RELEASE_VERSION }}
steps:
# Step 1: Check out the source code
- name: Checkout source code
uses: actions/checkout@v4
# Step 2: Extract version from the git tag
# This removes the 'v' prefix from tags like 'v1.0.0' to get '1.0.0'
- name: Get release version
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "Release version: ${GITHUB_REF#refs/tags/v}"
# Step 3: Create the GitHub release
# Create a release note for later use by the upload action
- name: Create Release
id: create_release
run: |
# Create release using GitHub CLI
cat > release_notes.md << 'EOF'
## MCP Rust Examples Release ${{ env.RELEASE_VERSION }}
This release contains compiled binaries for the MCP Rust Examples tutorial project.
### Features
- 20 comprehensive Rust examples demonstrating MCP (Model Context Protocol) usage
- Cross-platform binaries for Linux, macOS, and Windows
- Educational code with extensive documentation and comments
### Installation
1. Download the appropriate binary for your platform
2. Extract the archive
3. Run the desired example binary
### Examples Included
- Hello World and Calculator examples
- Text processing and HTTP client examples
- Database integration and streaming examples
- Authentication and notification services
- Data pipelines and search services
- Blockchain integration and ML model server
- Microservice gateway and enterprise server
### Usage
Each example can be run independently:
```bash
./example_01_hello_world
./example_02_calculator
# ... and so on
```
For more information, see the [README.md](README.md) in the repository.
EOF
# Create release
gh release create ${{ github.ref_name }} \
--title "Release ${{ env.RELEASE_VERSION }}" \
--notes-file release_notes.md \
--draft=false \
--prerelease=false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Job 2: Build binaries for multiple platforms
build:
name: Build Release Binaries
needs: create-release
runs-on: ${{ matrix.os }}
# Strategy matrix: build for multiple operating systems and architectures
strategy:
matrix:
include:
# Linux builds
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive_name: mcp-rust-examples-linux-x64
archive_extension: tar.gz
# macOS builds
- os: macos-latest
target: x86_64-apple-darwin
archive_name: mcp-rust-examples-macos-x64
archive_extension: tar.gz
- os: macos-latest
target: aarch64-apple-darwin
archive_name: mcp-rust-examples-macos-arm64
archive_extension: tar.gz
# Windows builds
- os: windows-latest
target: x86_64-pc-windows-msvc
archive_name: mcp-rust-examples-windows-x64
archive_extension: zip
steps:
# Step 1: Check out the source code
- name: Checkout source code
uses: actions/checkout@v4
# Step 2: Install Rust toolchain with Cargo.lock v4 support
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.86.0
with:
targets: ${{ matrix.target }}
# Step 3: Setup Rust caching for faster builds
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
# Step 4: Build all examples for the target platform
# We build all binary examples defined in Cargo.toml for the specific target
- name: Build release binaries
run: cargo build --release --target ${{ matrix.target }} --all-targets
# Step 5: Prepare binaries for packaging (Unix systems)
- name: Prepare binaries (Unix)
if: matrix.os != 'windows-latest'
run: |
# Create a directory to hold all the binaries
mkdir -p release-binaries
# Copy all built binaries to the release directory
# The binaries are located in target/{target}/release/
for binary in target/${{ matrix.target }}/release/example_*; do
if [ -f "$binary" ] && [ -x "$binary" ]; then
cp "$binary" release-binaries/
fi
done
# Also copy the main binary if it exists
if [ -f "target/${{ matrix.target }}/release/mcp_rust_examples" ]; then
cp "target/${{ matrix.target }}/release/mcp_rust_examples" release-binaries/
fi
# List the contents to verify
ls -la release-binaries/
# Step 6: Prepare binaries for packaging (Windows)
- name: Prepare binaries (Windows)
if: matrix.os == 'windows-latest'
run: |
# Create a directory to hold all the binaries
New-Item -ItemType Directory -Path release-binaries -Force
# Copy all built binaries to the release directory
# Windows binaries have .exe extension
Get-ChildItem -Path "target\${{ matrix.target }}\release" -Name "example_*.exe" | ForEach-Object {
Copy-Item -Path "target\${{ matrix.target }}\release\$_" -Destination "release-binaries\"
}
# Also copy the main binary if it exists
if (Test-Path "target\${{ matrix.target }}\release\mcp_rust_examples.exe") {
Copy-Item -Path "target\${{ matrix.target }}\release\mcp_rust_examples.exe" -Destination "release-binaries\"
}
# List the contents to verify
Get-ChildItem -Path release-binaries
shell: powershell
# Step 7: Create archive (tar.gz for Unix, zip for Windows)
- name: Create archive (Unix)
if: matrix.archive_extension == 'tar.gz'
run: |
cd release-binaries
tar -czf ../${{ matrix.archive_name }}.${{ matrix.archive_extension }} *
cd ..
ls -la ${{ matrix.archive_name }}.${{ matrix.archive_extension }}
- name: Create archive (Windows)
if: matrix.archive_extension == 'zip'
run: |
Compress-Archive -Path "release-binaries\*" -DestinationPath "${{ matrix.archive_name }}.${{ matrix.archive_extension }}"
Get-Item "${{ matrix.archive_name }}.${{ matrix.archive_extension }}"
shell: powershell
# Step 8: Upload the archive as a release asset
- name: Upload Release Asset
run: |
# Upload asset using GitHub CLI
gh release upload ${{ github.ref_name }} \
./${{ matrix.archive_name }}.${{ matrix.archive_extension }} \
--clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Job 3: Publish to crates.io
publish-crate:
name: Publish to crates.io
needs: create-release
runs-on: ubuntu-latest
steps:
# Step 1: Check out the source code
- name: Checkout source code
uses: actions/checkout@v4
# Step 2: Install Rust toolchain
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.86.0
# Step 3: Setup Rust cache
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
# Step 4: Verify the package can be published
- name: Verify package
run: |
echo "Verifying package for crates.io publishing..."
echo "Package contains educational examples without git dependencies"
cargo package --verbose --allow-dirty
cargo package --list --allow-dirty
# Step 5: Publish to crates.io
- name: Publish to crates.io
run: |
echo "Publishing MCP Rust Examples to crates.io..."
echo "📦 Publishing educational Rust examples for the MCP community"
cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --verbose --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Job 4: Generate and upload checksums for verification
checksums:
name: Generate Checksums
needs: [create-release, build, publish-crate]
runs-on: ubuntu-latest
steps:
# Step 1: Check out the source code
- name: Checkout source code
uses: actions/checkout@v4
# Step 2: Download all release assets
- name: Download release assets
run: |
# Create directory for downloaded assets
mkdir -p assets
# Get the release ID and download all assets
release_id=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }}" | \
jq -r '.id')
# Download each asset
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id/assets" | \
jq -r '.[].browser_download_url' | \
while read url; do
wget -P assets/ "$url"
done
# Step 3: Generate SHA256 checksums
- name: Generate checksums
run: |
cd assets
sha256sum * > ../checksums.txt
cd ..
cat checksums.txt
# Step 4: Upload checksums file
- name: Upload checksums
run: |
# Upload checksums using GitHub CLI
gh release upload ${{ github.ref_name }} \
./checksums.txt \
--clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}