vouchington-tooling 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vouchington-tooling",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Vouchington CLI and extractable tooling libraries.",
5
5
  "homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
6
6
  "bugs": {
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ usage() {
5
+ echo "usage: backfill-slash-release-tags.sh --package NAME [--package NAME]... [--dry-run] [--write] [--push] [--remote NAME]" >&2
6
+ }
7
+
8
+ packages=()
9
+ explicit_dry=0
10
+ do_write=0
11
+ do_push=0
12
+ remote=origin
13
+
14
+ while [ $# -gt 0 ]; do
15
+ case "$1" in
16
+ --package)
17
+ [ $# -ge 2 ] || { usage; exit 2; }
18
+ packages+=("$2")
19
+ shift 2
20
+ ;;
21
+ --dry-run)
22
+ explicit_dry=1
23
+ shift
24
+ ;;
25
+ --write)
26
+ do_write=1
27
+ shift
28
+ ;;
29
+ --push)
30
+ do_push=1
31
+ shift
32
+ ;;
33
+ --remote)
34
+ [ $# -ge 2 ] || { usage; exit 2; }
35
+ remote="$2"
36
+ shift 2
37
+ ;;
38
+ -h | --help)
39
+ usage
40
+ exit 2
41
+ ;;
42
+ *)
43
+ usage
44
+ exit 2
45
+ ;;
46
+ esac
47
+ done
48
+
49
+ if [ "${#packages[@]}" -eq 0 ]; then
50
+ usage
51
+ exit 2
52
+ fi
53
+
54
+ if [ "$explicit_dry" -eq 1 ] && { [ "$do_write" -eq 1 ] || [ "$do_push" -eq 1 ]; }; then
55
+ echo "cannot combine --dry-run with --write or --push" >&2
56
+ exit 2
57
+ fi
58
+
59
+ dry_run=1
60
+ if [ "$do_write" -eq 1 ] || [ "$do_push" -eq 1 ]; then
61
+ dry_run=0
62
+ fi
63
+
64
+ semver='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$'
65
+ push_refs=()
66
+
67
+ for package in "${packages[@]}"; do
68
+ if [[ ! "$package" =~ ^[A-Za-z0-9._-]+$ ]]; then
69
+ echo "invalid package name: ${package}" >&2
70
+ exit 2
71
+ fi
72
+
73
+ while IFS= read -r hyphen_tag; do
74
+ [ -n "$hyphen_tag" ] || continue
75
+ version="${hyphen_tag#"${package}-v"}"
76
+ if [[ ! "$version" =~ $semver ]]; then
77
+ echo "hyphen tag ${hyphen_tag} is not <package>-v<semver>" >&2
78
+ exit 1
79
+ fi
80
+
81
+ slash_tag="${package}/v${version}"
82
+ commit="$(git rev-parse "refs/tags/${hyphen_tag}^{commit}")"
83
+
84
+ if git rev-parse -q --verify "refs/tags/${slash_tag}" >/dev/null; then
85
+ existing="$(git rev-parse "refs/tags/${slash_tag}^{commit}")"
86
+ if [ "$existing" != "$commit" ]; then
87
+ echo "slash tag ${slash_tag} points at ${existing}, expected ${commit}" >&2
88
+ exit 1
89
+ fi
90
+ echo "skip ${slash_tag} (already at ${commit})"
91
+ continue
92
+ fi
93
+
94
+ echo "create ${slash_tag} -> ${commit}"
95
+ if [ "$dry_run" -eq 0 ]; then
96
+ git tag -a "${slash_tag}" -m "${package} v${version}" "$commit"
97
+ push_refs+=("refs/tags/${slash_tag}")
98
+ fi
99
+ done < <(git tag --list "${package}-v*")
100
+ done
101
+
102
+ if [ "$do_push" -eq 0 ]; then
103
+ exit 0
104
+ fi
105
+
106
+ if [ "${#push_refs[@]}" -eq 0 ]; then
107
+ echo "nothing to push"
108
+ exit 0
109
+ fi
110
+
111
+ git push --atomic "$remote" "${push_refs[@]}"