-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpublish
More file actions
executable file
·95 lines (79 loc) · 2.55 KB
/
publish
File metadata and controls
executable file
·95 lines (79 loc) · 2.55 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
#!/usr/bin/env zsh
# Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo "There are uncommitted changes. Please commit or stash them before running this script."
exit 1
fi
# Check for version argument. If not provided, read from CHANGELOG.md
if [ -z "$1" ]; then
if [ -f "$PWD/CHANGELOG.md" ]; then
TAG_VERSION=$(awk '/^## v/{print $2; exit}' "$PWD/CHANGELOG.md")
fi
if [ -z "$TAG_VERSION" ]; then
echo "Please provide a version tag (e.g., v1.0.0) or add it to the CHANGELOG.md in the format '## v1.0.0'"
exit 1
fi
else
TAG_VERSION=$1
fi
# Check if the tag already exists
if git rev-parse $TAG_VERSION > /dev/null 2>&1; then
echo "Tag '$TAG_VERSION' already exists. Exiting without creating a new tag."
exit 0
fi
# Get the repository name - try OpenSecOps remote first, then origin if OpenSecOps doesn't exist
if git remote | grep -q 'OpenSecOps'; then
REMOTE_URL=$(git remote get-url OpenSecOps)
else
REMOTE_URL=$(git remote get-url origin)
fi
REPO_NAME=$(basename -s .git "$REMOTE_URL")
cleanup() {
git checkout main
if [ $? -ne 0 ]; then
echo "Warning: Failed to switch back to 'main' branch."
fi
}
# Register cleanup function to run on script exit
trap cleanup EXIT
# Ensure on main branch & pull the latest changes
git checkout main
if [ $? -ne 0 ]; then
echo "Error: Failed to switch to 'main' branch."
exit 1
fi
git pull origin main
if [ $? -ne 0 ]; then
echo "Error: Failed to pull latest changes from 'main'."
exit 1
fi
# Get the tree object for the current HEAD of main
MAIN_TREE=$(git rev-parse HEAD^{tree})
# Check if the 'releases' branch exists
if ! git rev-parse --verify releases > /dev/null 2>&1; then
# Create a fresh 'releases' branch from 'main'
git checkout -b releases main
else
# Checkout the 'releases' branch
git checkout releases
fi
# Create a new commit on the 'releases' branch with the tree from 'main'
RELEASE_COMMIT=$(git commit-tree -m "Release $TAG_VERSION" $MAIN_TREE -p releases)
# Move the 'releases' branch to the new commit
git reset --hard $RELEASE_COMMIT
# Tag the release
git tag $TAG_VERSION
# Push the release branch and tags to the origin repo
git push origin releases --tags
if [ $? -ne 0 ]; then
echo "Error: Pushing to origin failed."
exit 1
fi
# Push the releases branch to the OpenSecOps repo's main branch
if git remote | grep -q 'OpenSecOps'; then
git push OpenSecOps releases:main --tags
if [ $? -ne 0 ]; then
echo "Error: Pushing to OpenSecOps failed."
exit 1
fi
fi