1+ name : Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*.*.*'
7+ - ' v*.*.*-pre.*'
8+
9+ permissions :
10+ contents : write
11+
12+ jobs :
13+ check :
14+ uses : ./.github/workflows/check.yml
15+
16+ test :
17+ uses : ./.github/workflows/test.yml
18+ needs : check
19+
20+ create-release :
21+ name : Create GitHub Release
22+ runs-on : ubuntu-latest
23+ needs : check
24+
25+ steps :
26+ - name : Checkout code
27+ uses : actions/checkout@v4
28+ with :
29+ fetch-depth : 0
30+
31+ - name : Validate tag and branch (HEAD-based)
32+ shell : bash
33+ run : |
34+ set -e
35+
36+ TAG="${{ github.ref_name }}"
37+ TAG_COMMIT=$(git rev-list -n 1 "$TAG")
38+
39+ git fetch origin main dev
40+
41+ MAIN_HEAD=$(git rev-parse origin/main)
42+ DEV_HEAD=$(git rev-parse origin/dev)
43+
44+ echo "Tag: $TAG"
45+ echo "Tag commit: $TAG_COMMIT"
46+ echo "main HEAD: $MAIN_HEAD"
47+ echo "dev HEAD: $DEV_HEAD"
48+
49+ if [[ "$TAG" == *-pre.* ]]; then
50+ if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
51+ echo "❌ prerelease tag must be created from dev HEAD"
52+ exit 1
53+ fi
54+ echo "✅ prerelease tag validated on dev"
55+ else
56+ if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
57+ echo "❌ stable release tag must be created from main HEAD"
58+ exit 1
59+ fi
60+ echo "✅ stable release tag validated on main"
61+ fi
62+
63+ - name : Create GitHub Release
64+ uses : softprops/action-gh-release@v2
65+ with :
66+ draft : false
67+ prerelease : ${{ contains(github.ref_name, '-pre.') }}
68+ body : |
69+ ## ${{ github.ref_name }}
70+
71+ - [Documentation](https://docs.rs/any-uart)
72+ - [crates.io](https://crates.io/crates/any-uart)
73+ env :
74+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
75+
76+ publish-crates :
77+ name : Publish to crates.io
78+ runs-on : ubuntu-latest
79+ needs : check
80+
81+ steps :
82+ - name : Checkout code
83+ uses : actions/checkout@v4
84+ with :
85+ fetch-depth : 0
86+
87+ - name : Validate tag and branch (HEAD-based)
88+ shell : bash
89+ run : |
90+ set -e
91+
92+ TAG="${{ github.ref_name }}"
93+ TAG_COMMIT=$(git rev-list -n 1 "$TAG")
94+
95+ git fetch origin main dev
96+
97+ MAIN_HEAD=$(git rev-parse origin/main)
98+ DEV_HEAD=$(git rev-parse origin/dev)
99+
100+ echo "Tag: $TAG"
101+ echo "Tag commit: $TAG_COMMIT"
102+ echo "main HEAD: $MAIN_HEAD"
103+ echo "dev HEAD: $DEV_HEAD"
104+
105+ if [[ "$TAG" == *-pre.* ]]; then
106+ if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
107+ echo "❌ prerelease tag must be created from dev HEAD"
108+ exit 1
109+ fi
110+ echo "✅ prerelease tag validated on dev"
111+ else
112+ if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
113+ echo "❌ stable release tag must be created from main HEAD"
114+ exit 1
115+ fi
116+ echo "✅ stable release tag validated on main"
117+ fi
118+
119+ - name : Install Rust toolchain
120+ uses : dtolnay/rust-toolchain@master
121+ with :
122+ toolchain : nightly-2025-08-15
123+
124+ - name : Publish to crates.io
125+ run : cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
0 commit comments