-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.bash
More file actions
80 lines (65 loc) · 2.71 KB
/
release.bash
File metadata and controls
80 lines (65 loc) · 2.71 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
#!/bin/bash
source $(dirname "$0")/definitions.bash > /dev/null
function run()
{
run_this_script_in_its_directory
declare -l part_to_increment=""
declare dry_run=false
while [ $# -gt 0 ]; do
case "$1" in
--increment=*)
part_to_increment="${1#*=}"
;;
--dry-run)
dry_run=true
;;
*)
error "Invalid argument: '$1'"
exit 1
esac
shift
done
if [ ! -f *.sln? ]; then
error "Current directory is not a solution directory."
exit 1
fi
assert_no_staged_but_uncommitted_changes
declare -r version_file_pathname=$(realpath version.txt)
declare -r previous_version=$(cat "$version_file_pathname")
IFS=- read -r current_version pre_release <<< "$previous_version"
if [[ "$pre_release" != "PreRelease" ]]; then
error "The version '$previous_version' is not a pre-release version! This should never happen!"
exit 1
fi
declare -r next_version="$(increment_version "$current_version" "$part_to_increment")-PreRelease"
info "Previous version: $previous_version"
info "Current version: $current_version"
info "Next version: $next_version"
declare -r version_tag_name="$current_version"
[[ $dry_run == true ]] && return
printf "$current_version" >| "$version_file_pathname"
git add "$version_file_pathname"
git commit --quiet --message="Release of version $current_version"
git tag "$version_tag_name"
info "Pushing current version and tag..."
# PEARL: GitHub will execute an "on: push" workflow twice, on the exact same commit, if we push both files and tags
# using a command like `git push origin HEAD --tags`. Several hours of troubleshooting and trying various tricks
# yielded no solution: the '--atomic' option has no effect, either with '--tags' or with the explicit tag name.
# The only solution seems to be to specify that the workflow must run on branches, which excludes tags.
git push --quiet origin HEAD
git push --quiet --tags
# PEARL: If two pushes happen in rapid succession, and if the github action triggered as a result of a push does
# a `git pull`, then it will receive the state of the repository after the 2nd push. (Even if the 2nd push was
# marked with [skip ci].) To overcome this problem, we have to add a delay between the two pushes.
declare -r wait_time="30s"
info "Waiting for $wait_time..."
sleep "$wait_time"
printf "$next_version" >| "$version_file_pathname"
git add "$version_file_pathname"
# PEARL: Still as of 2025 GitHub does not support `git push -o ci.skip`. So, we have to use `[skip ci]` in the
# commit message, which is the only thing that works on both GitHub and GitLab.
git commit --quiet --message="Increment version to $next_version [skip ci]"
info "Pushing next version..."
git push --quiet origin HEAD
}
run $@