Skip to content

Commit a7b4ca2

Browse files
committed
GITHUB_APP_TOKEN
1 parent 00a065d commit a7b4ca2

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

entrypoint.sh

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ download_translations() {
7979
}
8080

8181
create_pull_request() {
82-
BRANCH="${1}"
82+
[ -z "${GITHUB_TOKEN}" ] && [ -z "${GITHUB_APP_TOKEN}" ] && {
83+
echo "ERROR: Either 'GITHUB_TOKEN' or 'GITHUB_APP_TOKEN' must be set in the environment variables!"
84+
exit 1
85+
}
8386

84-
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
87+
AUTH_TOKEN="${GITHUB_TOKEN}"
88+
if [ -n "${GITHUB_APP_TOKEN}" ]; then
89+
AUTH_TOKEN="${GITHUB_APP_TOKEN}"
90+
fi
91+
92+
AUTH_HEADER="Authorization: token ${AUTH_TOKEN}"
8593
HEADER="Accept: application/vnd.github.v3+json; application/vnd.github.antiope-preview+json; application/vnd.github.shadow-cat-preview+json"
8694

8795
if [ -n "$INPUT_GITHUB_API_BASE_URL" ]; then
@@ -95,14 +103,16 @@ create_pull_request() {
95103

96104
auth_status=$(curl -sL --write-out '%{http_code}' --output /dev/null -H "${AUTH_HEADER}" -H "${HEADER}" "${PULLS_URL}")
97105
if [[ $auth_status -eq 403 || "$auth_status" -eq 401 ]] ; then
98-
echo "FAILED TO AUTHENTICATE USING 'GITHUB_TOKEN' CHECK TOKEN IS VALID"
106+
echo "FAILED TO AUTHENTICATE WITH GITHUB. PLEASE CHECK YOUR GITHUB TOKEN"
99107
echo "pull_request_url=" >> $GITHUB_OUTPUT
100108
echo "pull_request_number=" >> $GITHUB_OUTPUT
101109
exit 1
102110
fi
103111

104112
echo "CHECK IF PULL REQUEST ALREADY EXIST"
105113

114+
BRANCH="${1}"
115+
106116
if [ -n "$INPUT_PULL_REQUEST_BASE_BRANCH_NAME" ]; then
107117
BASE_BRANCH="$INPUT_PULL_REQUEST_BASE_BRANCH_NAME"
108118
else
@@ -233,9 +243,18 @@ create_pull_request() {
233243
}
234244

235245
push_to_branch() {
236-
BRANCH=${INPUT_LOCALIZATION_BRANCH_NAME}
246+
[ -z "${GITHUB_TOKEN}" ] && [ -z "${GITHUB_APP_TOKEN}" ] && {
247+
echo "ERROR: Either 'GITHUB_TOKEN' or 'GITHUB_APP_TOKEN' must be set in the environment variables!"
248+
exit 1
249+
}
237250

238-
REPO_URL="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_GITHUB_BASE_URL}/${GITHUB_REPOSITORY}.git"
251+
AUTH_TOKEN="${GITHUB_TOKEN}"
252+
if [ -n "${GITHUB_APP_TOKEN}" ]; then
253+
AUTH_TOKEN="${GITHUB_APP_TOKEN}"
254+
fi
255+
256+
BRANCH=${INPUT_LOCALIZATION_BRANCH_NAME}
257+
REPO_URL="https://${GITHUB_ACTOR}:${AUTH_TOKEN}@${INPUT_GITHUB_BASE_URL}/${GITHUB_REPOSITORY}.git"
239258

240259
echo "CONFIGURING GIT USER"
241260
git config --global user.email "${INPUT_GITHUB_USER_EMAIL}"
@@ -389,11 +408,6 @@ if [ "$INPUT_DOWNLOAD_SOURCES" = true ]; then
389408
download_sources "$@"
390409

391410
if [ "$INPUT_PUSH_SOURCES" = true ]; then
392-
[ -z "${GITHUB_TOKEN}" ] && {
393-
echo "CAN NOT FIND 'GITHUB_TOKEN' IN ENVIRONMENT VARIABLES"
394-
exit 1
395-
}
396-
397411
[ -n "${INPUT_GPG_PRIVATE_KEY}" ] && {
398412
setup_commit_signing
399413
}
@@ -406,11 +420,6 @@ if [ "$INPUT_DOWNLOAD_TRANSLATIONS" = true ]; then
406420
download_translations "$@"
407421

408422
if [ "$INPUT_PUSH_TRANSLATIONS" = true ]; then
409-
[ -z "${GITHUB_TOKEN}" ] && {
410-
echo "CAN NOT FIND 'GITHUB_TOKEN' IN ENVIRONMENT VARIABLES"
411-
exit 1
412-
}
413-
414423
[ -n "${INPUT_GPG_PRIVATE_KEY}" ] && {
415424
setup_commit_signing
416425
}
@@ -425,11 +434,6 @@ if [ "$INPUT_DOWNLOAD_BUNDLE" ]; then
425434
crowdin bundle download $INPUT_DOWNLOAD_BUNDLE $DOWNLOAD_BUNDLE_ARGS
426435

427436
if [ "$INPUT_PUSH_TRANSLATIONS" = true ]; then
428-
[ -z "${GITHUB_TOKEN}" ] && {
429-
echo "CAN NOT FIND 'GITHUB_TOKEN' IN ENVIRONMENT VARIABLES"
430-
exit 1
431-
}
432-
433437
[ -n "${INPUT_GPG_PRIVATE_KEY}" ] && {
434438
setup_commit_signing
435439
}

0 commit comments

Comments
 (0)