-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpkg
More file actions
executable file
·132 lines (117 loc) · 3.6 KB
/
Copy pathpkg
File metadata and controls
executable file
·132 lines (117 loc) · 3.6 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
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
#!/bin/bash
set -euo pipefail
# Default level is patch
LEVEL=${LEVEL:-patch}
increment_version() {
local VERSION_FILE="VERSION"
if [[ ! -f $VERSION_FILE ]]; then
echo "v0.0.0" > $VERSION_FILE
fi
local CURRENT_VERSION
CURRENT_VERSION=$(cat $VERSION_FILE | sed 's/^v//')
echo "Current version: $CURRENT_VERSION"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
case $LEVEL in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
*) echo "Invalid level: $LEVEL"; exit 1 ;;
esac
local NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
echo "New version: $NEW_VERSION"
echo "$NEW_VERSION" > $VERSION_FILE
}
git_commit_and_tag() {
local VERSION
VERSION=$(cat VERSION | sed 's/^v//')
git add .
git commit -m "$(echo $LEVEL | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}') release v$VERSION"
git tag "v$VERSION"
echo "Tagged commit with version: v$VERSION"
}
git_push() {
local VERSION
VERSION=$(cat VERSION | sed 's/^v//')
git push origin master
git push origin "v$VERSION"
echo "Pushed commit and tag to remote origin"
}
release() {
local VERSION
VERSION=$(cat VERSION | sed 's/^v//')
local ARCHIVE_NAME="usgc-themes-v$VERSION.tar.gz"
local LATEST_ARCHIVE_NAME="usgc-themes.tar.gz"
# Create a tar.gz archive excluding unnecessary files
tar --exclude='.git' --exclude='pkg' --exclude='VERSION' -czf "$ARCHIVE_NAME" .
# Create a copy with a consistent name for the latest release
cp "$ARCHIVE_NAME" "$LATEST_ARCHIVE_NAME"
# Create a GitHub release and upload both archives
gh release create "v$VERSION" "$ARCHIVE_NAME" "$LATEST_ARCHIVE_NAME" --title "Release v$VERSION" --notes "Automated release for version v$VERSION"
# Delete the archives after upload
rm -f "$ARCHIVE_NAME" "$LATEST_ARCHIVE_NAME"
echo "GitHub release created and archives deleted: $ARCHIVE_NAME, $LATEST_ARCHIVE_NAME"
echo "Release link https://github.com/usgraphics/usgc-themes/releases/latest/download/usgc-themes.tar.gz"
}
publish() {
increment_version
git_commit_and_tag
git_push
}
usage() {
echo "Usage: $0 <command> [options] [environment]"
echo "Commands:"
echo " publish [--level|-l <major|minor|patch>] - Increment version, commit, tag and push"
echo " release - Build and publish release on Github.com"
echo " all <env> - Publish, build and release"
exit 1
}
parse_args() {
LEVEL="patch" # Default level
COMMAND=""
while [[ $# -gt 0 ]]; do
case "$1" in
release|publish|all)
COMMAND="$1"
shift
;;
--level|-l)
LEVEL="$2"
shift 2
;;
*)
if [[ -z "$COMMAND" ]]; then
echo "Error: Unknown command $1"
usage
else
# Pass remaining args to the command handler
break
fi
;;
esac
done
# Store remaining arguments
ARGS=("$@")
if [[ -z "$COMMAND" ]]; then
usage
fi
}
main() {
parse_args "$@"
case "$COMMAND" in
publish)
publish
;;
release)
release
;;
all)
[[ ${#ARGS[@]} -eq 1 ]] || usage
release
build "${ARGS[0]}"
;;
*)
usage
;;
esac
}
main "$@"