-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag_and_release.sh
More file actions
89 lines (69 loc) · 2.62 KB
/
tag_and_release.sh
File metadata and controls
89 lines (69 loc) · 2.62 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
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
#!/usr/bin/env bash
# THIS SCRIPT IS CUSTOM - inspired from changesets.
# The difference is, there is no workflow. So everything runs from your computer.
# Which also means, no collaboration kind of, not everyone can release.
set -euo pipefail
if [ -n "$(git status --porcelain)" ]; then
echo "❗ Please commit all changes before bumping the version."
exit 1
fi
# Written by AI :)
NAME=$(sed -n 's/^name *= *"\([^"]*\)".*/\1/p' Cargo.toml)
CURRENT=$(sed -n 's/^version *= *"\([^"]*\)".*/\1/p' Cargo.toml)
echo "🦋 What kind of change is this for $NAME? (current version is $CURRENT) [patch, minor, major] >"
read -r BUMP
case "$BUMP" in
patch) NEW=$(echo "$CURRENT" | awk -F. '{$NF+=1; OFS="."; print $1,$2,$3}') ;;
minor) NEW=$(echo "$CURRENT" | awk -F. '{$(NF-1)+=1; $NF=0; OFS="."; print $1,$2,$3}') ;;
major) NEW=$(echo "$CURRENT" | awk -F. '{$1+=1; $2=0; $3=0; OFS="."; print $1,$2,$3}') ;;
*) echo "Please specify patch, minor, or major"; exit 1 ;;
esac
echo "🦋 Would tag and push $NAME $CURRENT -> $NEW"
read -p "Proceed? [Y/n] " -r CONFIRM
CONFIRM=${CONFIRM:-y}
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
# ============================================
# Update & Commit - Release manifests
# ============================================
# Update the Cargo.toml
echo "🦋 Updating Cargo.toml to version ${NEW}"
sed -i.bak "s/^version *= *\"[^\"]*\"/version = \"${NEW}\"/" Cargo.toml
rm Cargo.toml.bak
# Update npm/package.json if it exists
if [ -f "npm/package.json" ]; then
echo "🦋 Updating npm/package.json to version ${NEW}"
sed -i.bak "s/\"version\":[[:space:]]*\"[^\"]*\"/\"version\": \"${NEW}\"/" npm/package.json
rm npm/package.json.bak
git add npm/package.json
fi
# Update Cargo.lock to reflect the new version
echo "🦋 Updating Cargo.lock..."
cargo generate-lockfile
# Regenerate CHANGELOG.md from conventional commits (requires git-cliff)
echo "🦋 Regenerating CHANGELOG.md..."
git cliff --tag "v${NEW}" -o CHANGELOG.md
# Commit
echo "🦋 Committing version bump ${NEW}..."
git add .
git commit -m "release: ${NAME} v${NEW}"
# ============================================
# cargo-dist Publish GitHub Releases via actions
# ============================================
# Create the git tag.
echo "🦋 Creating git tag v${NEW}"
git tag "v${NEW}"
# Create release binaries (with cargo-dist)
echo "🦋 Pushing..."
git push --tags
git push
# ============================================
# PUBLISHING: I put it here as documentation, but this is manual for now!
# ============================================
# crates.io
# cargo publish
# npm
# cd npm
# npm publish