|
12 | 12 | # |
13 | 13 | # Environment Variables: |
14 | 14 | # DRY_RUN - Enable dry run mode (default: true) |
15 | | -# When true, shows git commands without executing them |
| 15 | +# When true, shows commands without executing them, except for git commands |
| 16 | +# that are executed but before pushing the changes to the remote repository. |
16 | 17 | # |
17 | 18 | # Examples: |
18 | 19 | # ./.github/scripts/release.sh |
@@ -41,28 +42,65 @@ set -e |
41 | 42 | readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
42 | 43 | source "${SCRIPT_DIR}/common.sh" |
43 | 44 |
|
| 45 | +# Collect and stage changes across modules, then create a single commit |
44 | 46 | MODULES=$(go work edit -json | jq -r '.Use[] | "\(.DiskPath | ltrimstr("./"))"' | tr '\n' ' ' && echo) |
| 47 | + |
| 48 | +commit_title="chore(release): bump module versions" |
| 49 | +commit_body="" |
| 50 | + |
45 | 51 | for m in $MODULES; do |
| 52 | + next_tag_path=$(get_next_tag "${m}") |
46 | 53 | # if the module version file does not exist, skip it |
47 | | - if [[ ! -f "${ROOT_DIR}/.github/scripts/.${m}-next-tag" ]]; then |
| 54 | + if [[ ! -f "${next_tag_path}" ]]; then |
48 | 55 | echo "Skipping ${m} because the pre-release script did not run" |
49 | 56 | continue |
50 | 57 | fi |
51 | 58 |
|
52 | | - execute_or_echo git add "${ROOT_DIR}/${m}/version.go" |
53 | | - execute_or_echo git add "${ROOT_DIR}/${m}/go.mod" |
| 59 | + git add "${ROOT_DIR}/${m}/version.go" |
| 60 | + git add "${ROOT_DIR}/${m}/go.mod" |
| 61 | + if [[ -f "${ROOT_DIR}/${m}/go.sum" ]]; then |
| 62 | + git add "${ROOT_DIR}/${m}/go.sum" |
| 63 | + fi |
54 | 64 |
|
55 | | - nextTag=$(cat "${ROOT_DIR}/.github/scripts/.${m}-next-tag") |
| 65 | + nextTag=$(cat "${next_tag_path}") |
56 | 66 | echo "Next tag for ${m}: ${nextTag}" |
57 | | - execute_or_echo git commit -m "chore(${m}): bump version to ${nextTag}" |
| 67 | + commit_body="${commit_body}\n - ${m}: ${nextTag}" |
| 68 | +done |
| 69 | + |
| 70 | +# Create a single commit if there are staged changes |
| 71 | +if [[ -n "$(git diff --cached)" ]]; then |
| 72 | + git commit -m "${commit_title}" -m "$(echo -e "${commit_body}")" |
| 73 | +else |
| 74 | + echo "No changes detected in modules. Release process aborted." |
| 75 | + exit 1 # exit with error code 1 to not proceed with the release |
| 76 | +fi |
58 | 77 |
|
59 | | - execute_or_echo git tag "${m}/${nextTag}" |
| 78 | +# Create all tags after the single commit |
| 79 | +for m in $MODULES; do |
| 80 | + next_tag_path=$(get_next_tag "${m}") |
| 81 | + if [[ -f "${next_tag_path}" ]]; then |
| 82 | + nextTag=$(cat "${next_tag_path}") |
| 83 | + git tag "${m}/${nextTag}" |
| 84 | + fi |
60 | 85 | done |
61 | 86 |
|
| 87 | +if [[ "${DRY_RUN}" == "true" ]]; then |
| 88 | + echo "Remote operations will be skipped." |
| 89 | + # show the last commit, including the patch |
| 90 | + echo "Last commit:" |
| 91 | + git_log_format='%C(auto)%h%C(reset) %s%nAuthor: %an <%ae>%nDate: %ad' |
| 92 | + git -C "${ROOT_DIR}" --no-pager log -1 --pretty=format:"${git_log_format}" --date=iso-local |
| 93 | + git -C "${ROOT_DIR}" --no-pager show -1 --format= --patch --stat |
| 94 | + # list the new tags, that should point to the same last commit |
| 95 | + echo "New tags:" |
| 96 | + git -C "${ROOT_DIR}" --no-pager tag --list --points-at HEAD |
| 97 | +fi |
| 98 | + |
| 99 | +echo "Pushing changes and tags to remote repository..." |
| 100 | + |
62 | 101 | execute_or_echo git push origin main --tags |
63 | 102 |
|
64 | 103 | for m in $MODULES; do |
65 | | - nextTag=$(cat "${ROOT_DIR}/.github/scripts/.${m}-next-tag") |
| 104 | + nextTag=$(cat $(get_next_tag "${m}")) |
66 | 105 | curlGolangProxy "${m}" "${nextTag}" |
67 | | - execute_or_echo rm "${ROOT_DIR}/.github/scripts/.${m}-next-tag" |
68 | 106 | done |
0 commit comments