1+ name : Publish tangle-subxt to crates.io
2+
3+ on :
4+ workflow_dispatch :
5+
6+ push :
7+ branches :
8+ - main
9+ paths :
10+ - " tangle-subxt/Cargo.toml"
11+ - " tangle-subxt/src/**"
12+
13+ permissions :
14+ contents : read
15+
16+ jobs :
17+ check-version-and-publish :
18+ runs-on : ubuntu-latest
19+
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 0 # Fetch full history to compare versions
25+
26+ - name : Install rust toolchain
27+ uses : dtolnay/rust-toolchain@stable
28+ with :
29+ toolchain : stable
30+
31+ - uses : swatinem/rust-cache@v2
32+ with :
33+ cache-on-failure : " true"
34+
35+ - name : Check if version changed
36+ id : version-check
37+ run : |
38+ # Get the current version from Cargo.toml
39+ CURRENT_VERSION=$(grep '^version = ' tangle-subxt/Cargo.toml | sed 's/version = "\(.*\)"/\1/')
40+ echo "Current version: $CURRENT_VERSION"
41+
42+ # Check if this version already exists on crates.io
43+ if cargo search tangle-subxt --limit 1 | grep -q "tangle-subxt = \"$CURRENT_VERSION\""; then
44+ echo "Version $CURRENT_VERSION already exists on crates.io"
45+ echo "should_publish=false" >> $GITHUB_OUTPUT
46+ else
47+ echo "Version $CURRENT_VERSION not found on crates.io, proceeding with publish"
48+ echo "should_publish=true" >> $GITHUB_OUTPUT
49+ echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
50+ fi
51+
52+ - name : Publish to crates.io
53+ if : steps.version-check.outputs.should_publish == 'true'
54+ env :
55+ CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
56+ run : |
57+ cd tangle-subxt
58+ cargo publish --token $CARGO_REGISTRY_TOKEN
59+
60+ - name : Create git tag
61+ if : steps.version-check.outputs.should_publish == 'true'
62+ env :
63+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
64+ run : |
65+ VERSION=${{ steps.version-check.outputs.version }}
66+ git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
67+ git config --global user.name "${GITHUB_ACTOR}"
68+ git tag "tangle-subxt-v$VERSION"
69+ git push origin "tangle-subxt-v$VERSION"
0 commit comments