1+ name : Publish to crates.io
2+
3+ on :
4+ release :
5+ types : [created]
6+ workflow_dispatch :
7+ inputs :
8+ version :
9+ description : ' Version to publish (e.g., 0.1.0)'
10+ required : true
11+ type : string
12+
13+ permissions :
14+ contents : write
15+
16+ jobs :
17+ verify :
18+ name : Verify Release
19+ runs-on : ubuntu-latest
20+ outputs :
21+ version : ${{ steps.get_version.outputs.version }}
22+ steps :
23+ - uses : actions/checkout@v4
24+
25+ - name : Install Rust
26+ uses : dtolnay/rust-toolchain@stable
27+
28+ - name : Get version
29+ id : get_version
30+ run : |
31+ if [ "${{ github.event_name }}" == "release" ]; then
32+ VERSION="${{ github.event.release.tag_name }}"
33+ VERSION="${VERSION#v}" # Remove 'v' prefix if present
34+ else
35+ VERSION="${{ github.event.inputs.version }}"
36+ fi
37+ echo "version=$VERSION" >> $GITHUB_OUTPUT
38+
39+ # Verify version in Cargo.toml matches
40+ CARGO_VERSION=$(grep "^version" Cargo.toml | sed 's/version = "\(.*\)"/\1/')
41+ if [ "$CARGO_VERSION" != "$VERSION" ]; then
42+ echo "Error: Cargo.toml version ($CARGO_VERSION) doesn't match release version ($VERSION)"
43+ exit 1
44+ fi
45+ echo "✅ Version $VERSION confirmed"
46+
47+ - name : Check crate name availability
48+ run : |
49+ if curl -s https://crates.io/api/v1/crates/ccagents | grep -q '"name":"ccagents"'; then
50+ echo "✅ Crate already exists, will publish new version"
51+ else
52+ echo "✅ Crate name is available for first publish"
53+ fi
54+
55+ - name : Run tests
56+ run : |
57+ cargo test --all-features
58+ cargo clippy -- -D warnings
59+ cargo fmt -- --check
60+
61+ - name : Verify package
62+ run : |
63+ cargo publish --dry-run
64+ echo "✅ Package verification successful"
65+
66+ publish-crates :
67+ name : Publish to crates.io
68+ needs : verify
69+ runs-on : ubuntu-latest
70+ environment : crates-io
71+ steps :
72+ - uses : actions/checkout@v4
73+
74+ - name : Install Rust
75+ uses : dtolnay/rust-toolchain@stable
76+
77+ - name : Publish to crates.io
78+ env :
79+ CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
80+ run : |
81+ cargo publish --token "$CARGO_REGISTRY_TOKEN"
82+ echo "✅ Published version ${{ needs.verify.outputs.version }} to crates.io"
83+
84+ - name : Wait for crates.io
85+ run : |
86+ echo "Waiting for crates.io to index the new version..."
87+ sleep 30
88+
89+ - name : Verify publication
90+ run : |
91+ VERSION="${{ needs.verify.outputs.version }}"
92+ if curl -s https://crates.io/api/v1/crates/ccagents | grep -q "\"max_version\":\"$VERSION\""; then
93+ echo "✅ Version $VERSION successfully published to crates.io"
94+ else
95+ echo "⚠️ Version may still be indexing on crates.io"
96+ fi
97+
98+ create-release-artifacts :
99+ name : Create Release Artifacts
100+ needs : [verify, publish-crates]
101+ runs-on : ${{ matrix.os }}
102+ strategy :
103+ matrix :
104+ include :
105+ - os : ubuntu-latest
106+ target : x86_64-unknown-linux-gnu
107+ binary_name : ccagents
108+ asset_name : ccagents-linux-amd64
109+
110+ - os : ubuntu-latest
111+ target : x86_64-unknown-linux-musl
112+ binary_name : ccagents
113+ asset_name : ccagents-linux-musl-amd64
114+
115+ - os : ubuntu-latest
116+ target : aarch64-unknown-linux-gnu
117+ binary_name : ccagents
118+ asset_name : ccagents-linux-arm64
119+
120+ - os : macos-latest
121+ target : x86_64-apple-darwin
122+ binary_name : ccagents
123+ asset_name : ccagents-macos-amd64
124+
125+ - os : macos-latest
126+ target : aarch64-apple-darwin
127+ binary_name : ccagents
128+ asset_name : ccagents-macos-arm64
129+
130+ steps :
131+ - uses : actions/checkout@v4
132+
133+ - name : Install Rust
134+ uses : dtolnay/rust-toolchain@stable
135+ with :
136+ targets : ${{ matrix.target }}
137+
138+ - name : Install cross-compilation tools
139+ if : matrix.target == 'aarch64-unknown-linux-gnu'
140+ run : |
141+ sudo apt-get update
142+ sudo apt-get install -y gcc-aarch64-linux-gnu
143+
144+ - name : Install musl tools
145+ if : matrix.target == 'x86_64-unknown-linux-musl'
146+ run : |
147+ sudo apt-get update
148+ sudo apt-get install -y musl-tools
149+
150+ - name : Build
151+ run : cargo build --release --target ${{ matrix.target }}
152+
153+ - name : Strip binary (Linux/macOS)
154+ if : matrix.os != 'windows-latest'
155+ run : |
156+ strip target/${{ matrix.target }}/release/${{ matrix.binary_name }}
157+
158+ - name : Create archive
159+ run : |
160+ cd target/${{ matrix.target }}/release
161+ tar czf ../../../${{ matrix.asset_name }}.tar.gz ${{ matrix.binary_name }}
162+ cd ../../../
163+ sha256sum ${{ matrix.asset_name }}.tar.gz > ${{ matrix.asset_name }}.tar.gz.sha256
164+
165+ - name : Upload to release
166+ if : github.event_name == 'release'
167+ uses : softprops/action-gh-release@v1
168+ with :
169+ files : |
170+ ${{ matrix.asset_name }}.tar.gz
171+ ${{ matrix.asset_name }}.tar.gz.sha256
172+
173+ - name : Upload artifacts (manual trigger)
174+ if : github.event_name == 'workflow_dispatch'
175+ uses : actions/upload-artifact@v3
176+ with :
177+ name : binaries-${{ matrix.asset_name }}
178+ path : |
179+ ${{ matrix.asset_name }}.tar.gz
180+ ${{ matrix.asset_name }}.tar.gz.sha256
181+
182+ create-tag :
183+ name : Create Git Tag
184+ needs : [verify, publish-crates]
185+ runs-on : ubuntu-latest
186+ if : github.event_name == 'workflow_dispatch'
187+ steps :
188+ - uses : actions/checkout@v4
189+ with :
190+ fetch-depth : 0
191+
192+ - name : Configure Git
193+ run : |
194+ git config user.name "GitHub Actions"
195+ git config user.email "actions@github.com"
196+
197+ - name : Create and push tag
198+ run : |
199+ VERSION="${{ needs.verify.outputs.version }}"
200+ git tag -a "v$VERSION" -m "Release version $VERSION"
201+ git push origin "v$VERSION"
202+ echo "✅ Created tag v$VERSION"
203+
204+ - name : Create GitHub Release
205+ uses : softprops/action-gh-release@v1
206+ with :
207+ tag_name : v${{ needs.verify.outputs.version }}
208+ name : v${{ needs.verify.outputs.version }}
209+ body : |
210+ ## 🚀 Released to crates.io
211+
212+ Version ${{ needs.verify.outputs.version }} has been published to [crates.io](https://crates.io/crates/ccagents).
213+
214+ ### Installation
215+
216+ ```bash
217+ cargo install ccagents
218+ ```
219+
220+ ### Changes
221+
222+ See [CHANGELOG.md](https://github.com/Bitropy/ccagents/blob/main/CHANGELOG.md) for details.
223+ draft : false
224+ prerelease : false
0 commit comments