Skip to content

Commit 34352e7

Browse files
RahulHereRahulHere
authored andcommitted
Add crates.io publishing support to release workflow (#2)
Enhance release system to support both GitHub Releases and crates.io: dump-version.sh: - Add --publish flag to publish to crates.io during release - Add --dry-run flag to preview changes without executing - Add --help flag with usage documentation - Add Step 8 for optional crates.io publishing release.yml: - Add publish-crates job that runs after release job - Trigger on PUBLISH_CRATES=true repo variable or [publish] in commit - Add CARGO_REGISTRY_TOKEN secret for crates.io auth - Update release notes with crates.io and GitHub install options
1 parent 5b67004 commit 34352e7

File tree

2 files changed

+272
-88
lines changed

2 files changed

+272
-88
lines changed

.github/workflows/release.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ on:
77
permissions:
88
contents: write
99

10+
env:
11+
# Set to 'true' to also publish to crates.io
12+
PUBLISH_CRATES: ${{ vars.PUBLISH_CRATES || 'false' }}
13+
1014
jobs:
1115
release:
1216
name: Create Release with Native Binaries
1317
runs-on: ubuntu-latest
18+
outputs:
19+
version: ${{ steps.version.outputs.version }}
20+
version_tag: ${{ steps.version.outputs.version_tag }}
21+
release_created: ${{ steps.check_release.outputs.exists != 'true' }}
1422
steps:
1523
- name: Checkout
1624
uses: actions/checkout@v4
@@ -100,6 +108,8 @@ jobs:
100108
101109
### Installation
102110
111+
#### From crates.io
112+
103113
\`\`\`toml
104114
# Add to Cargo.toml
105115
[dependencies]
@@ -112,6 +122,13 @@ jobs:
112122
cargo add gopher-orch@${VERSION}
113123
\`\`\`
114124
125+
#### From GitHub
126+
127+
\`\`\`toml
128+
[dependencies]
129+
gopher-orch = { git = "https://github.com/GopherSecurity/gopher-mcp-rust.git", tag = "${VERSION_TAG}" }
130+
\`\`\`
131+
115132
### Native Library Installation
116133
117134
\`\`\`bash
@@ -200,6 +217,52 @@ jobs:
200217
done
201218
fi
202219
220+
publish-crates:
221+
name: Publish to crates.io
222+
needs: release
223+
runs-on: ubuntu-latest
224+
if: |
225+
needs.release.outputs.release_created == 'true' &&
226+
(vars.PUBLISH_CRATES == 'true' || github.event.head_commit.message contains '[publish]')
227+
steps:
228+
- name: Checkout
229+
uses: actions/checkout@v4
230+
231+
- name: Setup Rust
232+
uses: dtolnay/rust-toolchain@stable
233+
234+
- name: Cache cargo
235+
uses: actions/cache@v4
236+
with:
237+
path: |
238+
~/.cargo/bin/
239+
~/.cargo/registry/index/
240+
~/.cargo/registry/cache/
241+
~/.cargo/git/db/
242+
target/
243+
key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
244+
245+
- name: Verify package
246+
run: |
247+
echo "Verifying package before publish..."
248+
cargo package --list
249+
cargo publish --dry-run
250+
251+
- name: Publish to crates.io
252+
env:
253+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
254+
run: |
255+
echo "Publishing version ${{ needs.release.outputs.version }} to crates.io..."
256+
cargo publish
257+
258+
- name: Summary
259+
run: |
260+
echo "## crates.io Publish Summary" >> $GITHUB_STEP_SUMMARY
261+
echo "" >> $GITHUB_STEP_SUMMARY
262+
echo "- **Version:** ${{ needs.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
263+
echo "- **crates.io:** https://crates.io/crates/gopher-orch/${{ needs.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
264+
echo "- **docs.rs:** https://docs.rs/gopher-orch/${{ needs.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
265+
203266
test:
204267
name: Run Tests
205268
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)