forked from multimediallc/codeowners-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-release.sh
More file actions
executable file
·73 lines (60 loc) · 2.46 KB
/
Copy pathpost-release.sh
File metadata and controls
executable file
·73 lines (60 loc) · 2.46 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
#! /usr/bin/env bash
set -eu
ACTIONS_FILE="action.yml"
CLI_TOOL_FILE="tools/cli/main.go"
README_FILE="README.md"
function check_git_clean() {
if ! git diff-index --quiet HEAD --; then
echo "Error: Your Git working directory is not clean."
echo "Please commit or stash your changes before running this script."
exit 1
fi
echo "Git working directory is clean."
git fetch origin
echo "Switching to origin/main"
git checkout origin/main >/dev/null 2>&1
}
VERSION_TAG="$(gh release list --limit 1 --json tagName --jq '.[0].tagName')"
DEV_TAG="$(echo "${VERSION_TAG}" | awk -F'[.-]' '{print $1"."$2"."$3+1".dev"}')"
BRANCH_NAME="post/${VERSION_TAG}"
echo "--- Starting update process for version ${VERSION_TAG} ---"
check_git_clean
if [ ! -f "${README_FILE}" ]; then
echo "Error: ${README_FILE} not found in the current directory. Make sure you are running this from the root."
exit 1
fi
echo "Creating branch '${BRANCH_NAME}'..."
if git rev-parse --verify "${BRANCH_NAME}" >/dev/null 2>&1; then
echo "Error: Branch '${BRANCH_NAME}' already exists."
git checkout "${BRANCH_NAME}"
else
git checkout -b "${BRANCH_NAME}"
fi
echo "Updating ${ACTIONS_FILE}, ${CLI_TOOL_FILE}, and ${README_FILE}..."
# sed -i works differently on macOS and Linux.
# For GNU sed (Linux), -i without an argument is fine.
# For BSD sed (macOS), -i requires an argument (even if empty string for no backup).
if sed --version 2>/dev/null | grep -q GNU; then # GNU sed
sed -i "s|RELEASE_VERSION: '.*'|RELEASE_VERSION: ''|g" "${ACTIONS_FILE}"
sed -i "s|Version: .*|Version: \"${DEV_TAG}\",|g" "${CLI_TOOL_FILE}"
sed -i "s|codeowners-plus@.*|codeowners-plus@${VERSION_TAG}|g" "${README_FILE}"
else # BSD sed (macOS)
sed -i '' "s|RELEASE_VERSION: '.*'|RELEASE_VERSION: ''|g" "${ACTIONS_FILE}"
sed -i '' "s|Version: .*|Version: \"${DEV_TAG}\",|g" "${CLI_TOOL_FILE}"
sed -i '' "s|codeowners-plus@.*|codeowners-plus@${VERSION_TAG}|g" "${README_FILE}"
fi
gofmt -w tools/cli
echo "${ACTIONS_FILE}, ${CLI_TOOL_FILE}, and ${README_FILE} updated."
echo "Committing changes..."
git add "${ACTIONS_FILE}" "${CLI_TOOL_FILE}" "${README_FILE}"
git commit -m "${VERSION_TAG}"
echo "--- Post release process completed successfully! ---"
echo ""
echo "Branch '${BRANCH_NAME}' created locally."
echo ""
echo "Next steps:"
echo " 1. Review the changes: git diff origin/main"
echo " 2. Push the branch: git push origin ${BRANCH_NAME}"
echo " 3. Create a pull request on GitHub to merge into main."
echo ""
exit 0