steps:
- name: 'rust:latest'
id: 'fetch'
entrypoint: 'cargo'
args:
- 'fetch'
- '--locked'
- name: 'rust:latest'
id: 'build'
entrypoint: 'cargo'
waitFor: ['fetch']
args:
- 'build'
- '--release'
- '--locked'
- name: 'rust:latest'
id: 'test'
entrypoint: 'cargo'
waitFor: ['build']
args:
- 'test'
- '--locked'
- name: 'rust:latest'
id: 'coverage'
entrypoint: 'bash'
waitFor: ['test']
args:
- '-c'
- |
cargo install cargo-tarpaulin --locked
cargo tarpaulin --out Xml --output-dir ./coverage --locked
# Extract line coverage percentage
if [ -f coverage/cobertura.xml ]; then
COV_RATE=$$(grep -oP 'line-rate="\K[0-9.]+' coverage/cobertura.xml | head -1)
COV_PCT=$$(echo "$$COV_RATE * 100" | bc)
echo "Line coverage: $$COV_PCT%"
# Check if coverage meets threshold
if (( $$(echo "$$COV_RATE < 0.80" | bc -l) )); then
echo "ERROR: Coverage $$COV_PCT% is below 80% threshold"
exit 1
fi
echo "Coverage threshold met (>= 80%)"
else
echo "ERROR: Coverage report not found"
exit 1
fi
- name: 'rust:latest'
id: 'clippy'
entrypoint: 'bash'
waitFor: ['build']
args:
- '-c'
- |
rustup component add clippy
cargo clippy --all-targets --locked -- -D warnings
- name: 'rust:latest'
id: 'fmt'
entrypoint: 'bash'
waitFor: ['fetch']
args:
- '-c'
- |
rustup component add rustfmt
cargo fmt -- --check
- name: 'rust:latest'
id: 'docs'
entrypoint: 'cargo'
waitFor: ['build']
args:
- 'doc'
- '--no-deps'
- '--locked'
- name: 'rust:latest'
id: 'package'
entrypoint: 'cargo'
waitFor: ['coverage', 'clippy', 'fmt']
args:
- 'package'
- '--locked'
- '--allow-dirty'
- name: 'rust:latest'
id: 'publish'
entrypoint: 'bash'
waitFor: ['package']
secretEnv: ['CRATES_IO_TOKEN']
args:
- '-c'
- |
if [ -n "$TAG_NAME" ]; then
echo "Publishing version $TAG_NAME to crates.io..."
cargo publish --token "$$CRATES_IO_TOKEN" --locked --allow-dirty
echo ""
echo "Successfully published $TAG_NAME to crates.io!"
echo "View at: https://crates.io/crates/wirepusher"
else
echo "Skipping crates.io publish (not a tagged release)"
echo "To publish: git tag v1.0.0 && git push origin v1.0.0"
fi
- name: 'curlimages/curl:latest'
id: 'notify-release'
waitFor: ['publish']
entrypoint: 'sh'
secretEnv: ['WIREPUSHER_TOKEN']
args:
- '-c'
- |
if [ -z "$TAG_NAME" ]; then
echo "=== No Git tag detected ==="
echo "Skipping notification (only runs on tags)"
exit 0
fi
echo "=== Sending release notification via NotifAI ==="
curl -s -X POST https://api.wirepusher.dev/notifai \
-H "Authorization: Bearer $$WIREPUSHER_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"text\": \"WirePusher Rust SDK $TAG_NAME released to crates.io successfully. Add wirepusher = version to Cargo.toml. View package at https://crates.io/crates/wirepusher\",
\"type\": \"release\"
}"
echo ""
echo "✓ Release notification sent via NotifAI"
timeout: '600s'
options:
machineType: 'E2_HIGHCPU_8'
logging: CLOUD_LOGGING_ONLY
artifacts:
objects:
location: 'gs://${PROJECT_ID}_cloudbuild/artifacts/rust-sdk/${BUILD_ID}'
paths:
- 'target/package/*.crate'
- 'target/doc/**'
- 'coverage/*'
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/crates-io-token/versions/latest
env: 'CRATES_IO_TOKEN'
- versionName: projects/$PROJECT_ID/secrets/wirepusher-token/versions/latest
env: 'WIREPUSHER_TOKEN'