-
Notifications
You must be signed in to change notification settings - Fork 6
43 lines (35 loc) · 1.67 KB
/
Copy pathpublish.yml
File metadata and controls
43 lines (35 loc) · 1.67 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
name: Publish
on:
push:
branches:
- main
tags:
- v[0-9]+.[0-9]+.[0-9]+
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Check if version is already published
run: |
# Get the workspace package info (not dependencies)
WORKSPACE_ROOT=$(cargo metadata --format-version=1 | jq -r '.workspace_root')
PACKAGE_NAME=$(cargo metadata --format-version=1 | jq -r --arg root "$WORKSPACE_ROOT" '.packages[] | select(.manifest_path | startswith($root)) | .name')
PACKAGE_VERSION=$(cargo metadata --format-version=1 | jq -r --arg root "$WORKSPACE_ROOT" '.packages[] | select(.manifest_path | startswith($root)) | .version')
echo "Checking if $PACKAGE_NAME version $PACKAGE_VERSION can be published..."
# Use cargo publish --dry-run to check if we can publish this version
# This is the most reliable method as it uses the same logic as actual publish
DRY_RUN_OUTPUT=$(cargo publish --dry-run --allow-dirty 2>&1)
if echo "$DRY_RUN_OUTPUT" | grep -q "already exists on crates.io index"; then
echo "Version $PACKAGE_VERSION of $PACKAGE_NAME already exists on crates.io. Skipping publish."
exit 0
else
echo "Version $PACKAGE_VERSION of $PACKAGE_NAME can be published. Proceeding with publish."
fi
- name: Publish to crates.io
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}