forked from commitizen-tools/commitizen-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·117 lines (104 loc) · 3.25 KB
/
entrypoint.sh
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
#!/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')
elif [[ $INPUT_COMMITIZEN_VERSION == 'custom' ]]; then
true
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)"
PREV_REV="$(cz version --project)"
echo "PREVIOUS_REVISION=${PREV_REV}" >>"$GITHUB_ENV"
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 ]]; then
CZ_CMD+=('--check-consistency')
fi
if [[ $INPUT_GIT_REDIRECT_STDERR == 'true' ]]; then
CZ_CMD+=('--git-output-to-stderr')
fi
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
REV="$(cz version --project)"
if [[ $REV == "$PREV_REV" ]]; then
INPUT_PUSH='false'
fi
echo "REVISION=${REV}" >>"$GITHUB_ENV"
echo "version=${REV}" >>"$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: ${GITHUB_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://${GITHUB_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."