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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Release Pipeline
on:
push:
branches:
permissions:
contents: write
pull-requests: read
jobs:
lint-and-build:
runs-on: ubuntu-latest
environment: publish
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: true
- name: Read current version from Cargo.toml
id: current_version
run: |
echo "📖 Reading current version from Cargo.toml..."
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Current version: $CURRENT_VERSION"
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Bump version in Cargo.toml
id: new_version
run: |
echo "🔢 Analyzing commit message for version bump type..."
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
# Get the latest commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "Latest commit message: $COMMIT_MSG"
# Parse version parts (assuming semantic versioning x.y.z)
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
# Determine bump type based on commit message
if [[ "$COMMIT_MSG" =~ ^feat!\s*: ]]; then
echo "🚀 Breaking change detected (feat!:) - MAJOR bump"
NEW_MAJOR=$((MAJOR + 1))
NEW_MINOR=0
NEW_PATCH=0
BUMP_TYPE="major"
elif [[ "$COMMIT_MSG" =~ ^feat\s*: ]]; then
echo "✨ Feature detected (feat:) - MINOR bump"
NEW_MAJOR=$MAJOR
NEW_MINOR=$((MINOR + 1))
NEW_PATCH=0
BUMP_TYPE="minor"
elif [[ "$COMMIT_MSG" =~ ^fix\s*: ]]; then
echo "🐛 Fix detected (fix:) - PATCH bump"
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
BUMP_TYPE="patch"
else
echo "📦 No conventional commit pattern detected - defaulting to PATCH bump"
NEW_MAJOR=$MAJOR
NEW_MINOR=$MINOR
NEW_PATCH=$((PATCH + 1))
BUMP_TYPE="patch"
fi
NEW_VERSION="$NEW_MAJOR.$NEW_MINOR.$NEW_PATCH"
echo "Bumping from $CURRENT_VERSION to $NEW_VERSION ($BUMP_TYPE)"
# Update Cargo.toml
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" Cargo.toml
# Verify the change
echo "Updated Cargo.toml:"
grep '^version = ' Cargo.toml | head -1
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: "build-cache"
cache-on-failure: true
- name: Check code formatting
run: cargo fmt --all -- --check
- name: Run Clippy lints
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Run tests
run: cargo test --all-features
- name: Build release
run: cargo build --release
- name: Commit version bump
id: commit
run: |
NEW_VERSION="${{ steps.new_version.outputs.new_version }}"
echo "📝 Committing version bump to $NEW_VERSION..."
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml Cargo.lock
git commit -m "chore: bump version to $NEW_VERSION"
echo "🏷️ Creating git tag v$NEW_VERSION..."
git tag "v$NEW_VERSION"
echo "✅ Committed and tagged version $NEW_VERSION"
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "📦 Publishing to crates.io..."
cargo publish --token "${CARGO_REGISTRY_TOKEN}"
echo "✅ Successfully published to crates.io"
- name: Push changes and tags
run: |
echo "⬆️ Pushing commit and tags to GitHub..."
git push origin release
git push origin --tags
echo "✅ Successfully pushed changes"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.new_version.outputs.new_version }}
release_name: Release v${{ steps.new_version.outputs.new_version }}
body: |
## Changes in v${{ steps.new_version.outputs.new_version }}
Version bump: ${{ steps.new_version.outputs.bump_type }}
See [CHANGELOG](https://github.com/sinha-sahil/arche/blob/release/CHANGELOG.md) for details.
draft: false
prerelease: false