Debian Codegraph @

.justfile

raw
1 test: fmt clippy
2 RUST_TEST_THREADS=1 cargo test
3
4 fmt:
5 cargo fmt --all -- --check
6
7 clippy:
8 cargo clippy --all-targets --all-features
9
10 update:
11 cargo update
12
13 clean:
14 cargo clean
15
16 # Coverage report
17 coverage:
18 cargo llvm-cov --all-features --workspace
19
20 # Check if working directory is clean
21 check-clean:
22 #!/usr/bin/env bash
23 if [[ -n $(git status --porcelain) ]]; then
24 echo "❌ Working directory is not clean. Commit or stash your changes first."
25 git status --short
26 exit 1
27 fi
28 echo "✅ Working directory is clean"
29
30 # Check if on develop branch
31 check-develop:
32 #!/usr/bin/env bash
33 current_branch=$(git branch --show-current)
34 if [[ "$current_branch" != "develop" ]]; then
35 echo "❌ Not on develop branch (currently on: $current_branch)"
36 echo "Switch to develop branch first: git checkout develop"
37 exit 1
38 fi
39 echo "✅ On develop branch"
40
41 # Check if tag already exists for a given version
42 check-tag-not-exists version:
43 #!/usr/bin/env bash
44 set -euo pipefail
45 version="{{version}}"
46
47 git fetch --tags --quiet
48
49 if git rev-parse -q --verify "refs/tags/${version}" >/dev/null 2>&1; then
50 echo "❌ Tag ${version} already exists!"
51 exit 1
52 fi
53
54 echo "✅ No tag exists for version ${version}"
55
56 _bump bump_kind: check-develop check-clean clean update test
57 #!/usr/bin/env bash
58 set -euo pipefail
59
60 bump_kind="{{bump_kind}}"
61
62 cleanup() {
63 status=$?
64 if [ $status -ne 0 ]; then
65 echo "↩️ Restoring version files after failure..."
66 git checkout -- Cargo.toml Cargo.lock >/dev/null 2>&1 || true
67 fi
68 exit $status
69 }
70 trap cleanup EXIT
71
72 previous_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
73 echo "ℹ️ Current version: ${previous_version}"
74
75 echo "🔧 Bumping ${bump_kind} version..."
76 cargo set-version --bump "${bump_kind}"
77 new_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
78 echo "📝 New version: ${new_version}"
79
80 validate_bump() {
81 local previous=$1 bump=$2 current=$3
82 IFS=. read -r prev_major prev_minor prev_patch <<<"${previous}"
83 IFS=. read -r new_major new_minor new_patch <<<"${current}"
84
85 case "${bump}" in
86 patch)
87 (( new_major == prev_major && new_minor == prev_minor && new_patch == prev_patch + 1 )) || { echo "❌ Expected patch bump from ${previous}, got ${current}"; exit 1; }
88 ;;
89 minor)
90 (( new_major == prev_major && new_minor == prev_minor + 1 && new_patch == 0 )) || { echo "❌ Expected minor bump from ${previous}, got ${current}"; exit 1; }
91 ;;
92 major)
93 (( new_major == prev_major + 1 && new_minor == 0 && new_patch == 0 )) || { echo "❌ Expected major bump from ${previous}, got ${current}"; exit 1; }
94 ;;
95 esac
96 }
97
98 validate_bump "${previous_version}" "${bump_kind}" "${new_version}"
99
100 echo "🔍 Verifying tag does not exist for ${new_version}..."
101 git fetch --tags --quiet
102 if git rev-parse -q --verify "refs/tags/${new_version}" >/dev/null 2>&1; then
103 echo "❌ Tag ${new_version} already exists!"
104 exit 1
105 fi
106
107 echo "🔄 Updating dependencies..."
108 cargo update
109
110 echo "🧹 Running clean build..."
111 cargo clean
112
113 echo "🧪 Running tests with new version (via just test)..."
114 just test
115
116 git add .
117 git commit -m "bump version to ${new_version}"
118 git push origin develop
119 echo "✅ Version bumped and pushed to develop"
120
121 # Bump version and commit (patch level)
122 bump:
123 @just _bump patch
124
125 # Bump minor version
126 bump-minor:
127 @just _bump minor
128
129 # Bump major version
130 bump-major:
131 @just _bump major
132
133 # Internal function to handle the merge and tag process
134 _deploy-merge-and-tag:
135 #!/usr/bin/env bash
136 set -euo pipefail
137
138 new_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
139 echo "🚀 Starting deployment for version $new_version..."
140
141 # Double-check tag doesn't exist (safety check)
142 echo "🔍 Verifying tag doesn't exist..."
143 git fetch --tags --quiet
144 if git rev-parse -q --verify "refs/tags/${new_version}" >/dev/null 2>&1; then
145 echo "❌ Tag ${new_version} already exists on remote!"
146 echo "This should not happen. The tag may have been created in a previous run."
147 exit 1
148 fi
149
150 # Ensure develop is up to date
151 echo "🔄 Ensuring develop is up to date..."
152 git pull origin develop
153
154 # Switch to main and merge develop
155 echo "🔄 Switching to main branch..."
156 git checkout main
157 git pull origin main
158
159 echo "🔀 Merging develop into main..."
160 if ! git merge develop --no-edit; then
161 echo "❌ Merge failed! Please resolve conflicts manually."
162 git checkout develop
163 exit 1
164 fi
165
166 # Create signed tag
167 echo "🏷️ Creating signed tag $new_version..."
168 git tag -s "$new_version" -m "Release version $new_version"
169
170 # Push main and tag atomically
171 echo "⬆️ Pushing main branch and tag..."
172 if ! git push origin main "$new_version"; then
173 echo "❌ Push failed! Rolling back..."
174 git tag -d "$new_version"
175 git checkout develop
176 exit 1
177 fi
178
179 # Switch back to develop
180 echo "🔄 Switching back to develop..."
181 git checkout develop
182
183 echo "✅ Deployment complete!"
184 echo "🎉 Version $new_version has been released"
185 echo "📋 Summary:"
186 echo " - develop branch: bumped and pushed"
187 echo " - main branch: merged and pushed"
188 echo " - tag $new_version: created and pushed"
189 echo "🔗 Monitor release: https://github.com/nbari/pg_exporter/actions"
190
191 # Deploy: merge to main, tag, and push everything
192 deploy: bump _deploy-merge-and-tag
193
194 # Deploy with minor version bump
195 deploy-minor: bump-minor _deploy-merge-and-tag
196
197 # Deploy with major version bump
198 deploy-major: bump-major _deploy-merge-and-tag