-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·177 lines (156 loc) · 5.67 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·177 lines (156 loc) · 5.67 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env bash
set -e
# Reporting
gpg --version
git --version
if [[ -z $INPUT_GITHUB_TOKEN && $INPUT_PUSH == "true" ]]; then
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}" which is required to push.' >&2
exit 1
fi
echo "Configuring Git username, email, and pull behavior..."
# Fix #56
git config --global --add safe.directory "*"
git config --local user.name "${INPUT_GIT_NAME}"
git config --local user.email "${INPUT_GIT_EMAIL}"
git config --local pull.rebase true
echo "Git name: $(git config --get user.name)"
echo "Git email: $(git config --get user.email)"
PIP_CMD=('pip' 'install')
if [[ $INPUT_COMMITIZEN_VERSION == 'latest' ]]; then
PIP_CMD+=('commitizen')
else
PIP_CMD+=("commitizen==${INPUT_COMMITIZEN_VERSION}")
fi
IFS=" " read -r -a INPUT_EXTRA_REQUIREMENTS <<<"$INPUT_EXTRA_REQUIREMENTS"
PIP_CMD+=("${INPUT_EXTRA_REQUIREMENTS[@]}")
echo "${PIP_CMD[@]}"
"${PIP_CMD[@]}"
echo "Commitizen version: $(cz version)"
if [[ $INPUT_WORKING_DIRECTORY ]]; then
cd $INPUT_WORKING_DIRECTORY
fi
PREV_REV="$(cz version --project)"
echo "PREVIOUS_REVISION=${PREV_REV}" >>"$GITHUB_ENV"
echo "previous_version=${PREV_REV}" >>"$GITHUB_OUTPUT"
PREV_REV_MAJOR="$(cz version --project --major)"
echo "PREVIOUS_REVISION_MAJOR=${PREV_REV_MAJOR}" >>"$GITHUB_ENV"
echo "previous_version_major=${PREV_REV_MAJOR}" >>"$GITHUB_OUTPUT"
PREV_REV_MINOR="$(cz version --project --minor)"
echo "PREVIOUS_REVISION_MINOR=${PREV_REV_MINOR}" >>"$GITHUB_ENV"
echo "previous_version_minor=${PREV_REV_MINOR}" >>"$GITHUB_OUTPUT"
CZ_CMD=('cz')
if [[ $INPUT_DEBUG == 'true' ]]; then
CZ_CMD+=('--debug')
fi
if [[ $INPUT_NO_RAISE ]]; then
CZ_CMD+=('--no-raise' "$INPUT_NO_RAISE")
fi
CZ_CMD+=('bump' '--yes')
if [[ $INPUT_GPG_SIGN == 'true' ]]; then
CZ_CMD+=('--gpg-sign')
fi
if [[ $INPUT_DRY_RUN == 'true' ]]; then
CZ_CMD+=('--dry-run')
fi
if [[ $INPUT_CHANGELOG == 'true' ]]; then
CZ_CMD+=('--changelog')
fi
if [[ $INPUT_PRERELEASE ]]; then
CZ_CMD+=('--prerelease' "$INPUT_PRERELEASE")
fi
if [[ $INPUT_DEVRELEASE ]]; then
CZ_CMD+=('--devrelease' "$INPUT_DEVRELEASE")
fi
if [[ $INPUT_LOCAL_VERSION == 'true' ]]; then
CZ_CMD+=('--local-version')
fi
if [[ $INPUT_COMMIT == 'false' ]]; then
CZ_CMD+=('--files-only')
fi
if [[ $INPUT_INCREMENT ]]; then
CZ_CMD+=('--increment' "$INPUT_INCREMENT")
fi
if [[ $INPUT_CHECK_CONSISTENCY == 'true' ]]; then
CZ_CMD+=('--check-consistency')
fi
if [[ $INPUT_GIT_REDIRECT_STDERR == 'true' ]]; then
CZ_CMD+=('--git-output-to-stderr')
fi
if [[ $INPUT_BUILD_METADATA ]]; then
CZ_CMD+=('--build-metadata' "$INPUT_BUILD_METADATA")
fi
if [[ $INPUT_MANUAL_VERSION ]]; then
CZ_CMD+=("$INPUT_MANUAL_VERSION")
fi
# Capture the would-be next version BEFORE running the actual bump.
# This is used as a fallback for the version output when `cz version --project`
# does not reflect the bump (e.g. version_provider=scm combined with
# commit:false, where neither version files nor git tags are updated).
# Strip `--changelog` and `--changelog-to-stdout` for the `--get-next` call:
# in commitizen < 4.10.1 these flags are incompatible with `--get-next`
# (NotAllowed); in newer versions they emit a no-op warning. Either way
# `--get-next` does not generate a changelog so the flag is unnecessary.
GET_NEXT_CMD=()
for arg in "${CZ_CMD[@]}"; do
if [[ $arg != '--changelog' && $arg != '--changelog-to-stdout' ]]; then
GET_NEXT_CMD+=("$arg")
fi
done
# Failures (no bumpable commits, etc.) are tolerated and produce an empty value.
NEXT_REV_PRE="$("${GET_NEXT_CMD[@]}" --get-next 2>/dev/null || true)"
if [[ $INPUT_CHANGELOG_INCREMENT_FILENAME ]]; then
CZ_CMD+=('--changelog-to-stdout')
echo "${CZ_CMD[@]}" ">$INPUT_CHANGELOG_INCREMENT_FILENAME"
"${CZ_CMD[@]}" >"$INPUT_CHANGELOG_INCREMENT_FILENAME"
else
echo "${CZ_CMD[@]}"
"${CZ_CMD[@]}"
fi
if [[ $INPUT_ACTOR ]]; then
ACTOR=$INPUT_ACTOR
else
ACTOR=$GITHUB_ACTOR
fi
REV="$(cz version --project)"
NEXT_REV_MAJOR="$(cz version --project --major)"
NEXT_REV_MINOR="$(cz version --project --minor)"
# Fall back to the pre-computed --get-next value when `cz version --project`
# did not reflect the bump. This happens with version_provider=scm and
# commit:false, where the bump does not update any tracked files and no
# tag is created, so the project's reported version remains unchanged.
if [[ $REV == "$PREV_REV" && -n "$NEXT_REV_PRE" && "$NEXT_REV_PRE" != "$PREV_REV" ]]; then
REV="$NEXT_REV_PRE"
NEXT_REV_MAJOR="${REV%%.*}"
NEXT_REV_REST="${REV#*.}"
NEXT_REV_MINOR="${NEXT_REV_REST%%.*}"
fi
if [[ $REV == "$PREV_REV" ]]; then
INPUT_PUSH='false'
fi
echo "REVISION=${REV}" >>"$GITHUB_ENV"
echo "version=${REV}" >>"$GITHUB_OUTPUT"
echo "next_version=${REV}" >>"$GITHUB_OUTPUT"
echo "NEXT_REVISION_MAJOR=${NEXT_REV_MAJOR}" >>"$GITHUB_ENV"
echo "next_version_major=${NEXT_REV_MAJOR}" >>"$GITHUB_OUTPUT"
echo "NEXT_REVISION_MINOR=${NEXT_REV_MINOR}" >>"$GITHUB_ENV"
echo "next_version_minor=${NEXT_REV_MINOR}" >>"$GITHUB_OUTPUT"
GITHUB_DOMAIN=${GITHUB_SERVER_URL#*//}
CURRENT_BRANCH="$(git branch --show-current)"
INPUT_BRANCH="${INPUT_BRANCH:-$CURRENT_BRANCH}"
INPUT_REPOSITORY="${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}"
echo "Repository: ${INPUT_REPOSITORY}"
echo "Actor: ${ACTOR}"
if [[ $INPUT_PUSH == 'true' ]]; then
if [[ $INPUT_MERGE != 'true' && $GITHUB_EVENT_NAME == 'pull_request' ]]; then
echo "Refusing to push on pull_request event since that would merge the pull request." >&2
echo "You probably want to run on push to your default branch instead." >&2
else
echo "Pushing to branch..."
REMOTE_REPO="https://${ACTOR}:${INPUT_GITHUB_TOKEN}@${GITHUB_DOMAIN}/${INPUT_REPOSITORY}.git"
git pull "$REMOTE_REPO" "$INPUT_BRANCH"
git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags
fi
else
echo "Not pushing"
fi
echo "Done."