-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·139 lines (110 loc) · 4.52 KB
/
entrypoint.sh
File metadata and controls
executable file
·139 lines (110 loc) · 4.52 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
#!/bin/bash
# exit when any command fails
set -e
if [[ $INPUT_DEBUG ]] ; then
set -x
fi
echo "STARTING TRANSIFEX ACTION..."
CURRENT_BRANCH=${INPUT_CURRENT_BRANCH:-$GITHUB_HEAD_REF}
MASTER_BRANCH=${INPUT_MASTER_BRANCH:-master}
REMOTE=${INPUT_REMOTE:-origin}
TRANSLATIONS_FOLDER=${INPUT_TRANSLATIONS_FOLDER}
SKIP_PUSH_COMMIT=${INPUT_SKIP_PUSH_COMMIT}
COMMITER_EMAIL=${INPUT_COMMITER_EMAIL:-'git-action@transifex.com'}
COMMITTER_NAME=${INPUT_COMMITTER_NAME:-'Transifex Github action'}
export TX_TOKEN=${INPUT_TX_TOKEN:-$TX_TOKEN}
# Because transifex overrides whatever is in remote with what's currently in
# our branch, we will do the following:
# 1 - Checkout master (or whatever base branch)
# 2 - Get what's in transifex
# 3 - Use commit to the staging area
# 4 - Use git merge with fast-forward only so we merge the differences
# 5 - Push the merge result to transifex
args=()
common_args=()
if [[ "$INPUT_PARALLEL" = true ]] ; then
common_args+=( "--parallel" )
fi
if [[ $INPUT_MINIMUM_PERC -ne 0 ]] ; then
args+=( "--minimum-perc=$INPUT_MINIMUM_PERC" )
fi
if [[ "$INPUT_DISABLE_OVERRIDE" = true ]] ; then
args+=( "--disable-overwrite" )
fi
if [[ "$INPUT_PULL_SOURCES" = true ]] ; then
args+=( "-s" )
fi
if [[ "$INPUT_PULL_TRANSLATIONS" = true ]] ; then
args+=( "-a" )
fi
if [[ "$INPUT_GIT_FLOW" = true ]] ; then
echo "USING GIT MERGE FLOW"
[[ -z "${INPUT_GITHUB_TOKEN}" ]] && {
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".';
exit 1;
};
echo "Setting up git repo"
git config --global user.email "${COMMITTER_EMAIL}"
git config --global user.name "${COMMITTER_NAME}"
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
if [[ "$INPUT_GIT_UNSHALLOW" != false ]] ; then
# Git checkout action does a shallow clone. That prevents us to
# access common history of branches.
git fetch --unshallow
fi
git checkout origin/${MASTER_BRANCH}
TRANSLATIONS_MERGE_BRANCH="${MASTER_BRANCH}-translations-$(date +%s)"
git checkout -b ${TRANSLATIONS_MERGE_BRANCH}
if [[ "$INPUT_PULL_SOURCES" = true ]] || [[ "$INPUT_PULL_TRANSLATIONS" = true ]] ; then
echo "Pulling most up to date sources and translations"
# Unfortunately we need to use force because transifex thinks the checked out
# files are newer than in Transifex, so they get ignored. See issue:
# https://github.com/transifex/transifex-client/issues/22
tx pull --no-interactive --force "${common_args[@]}" "${args[@]}"
else
echo "WARNING - NOT PULLING ANY STRINGS FROM TRANSIFEX - PUSHING WILL RESULT IN OVERRIDING THE STRINGS IN TRANSIFEX"
fi
# Commits latest transifex tranlsations to our local branch
git add $(echo ${TRANSLATIONS_FOLDER})
git diff --staged
# Stashes all of the non needed changes (eg. sometines .tx/config is changed)
git diff --staged --quiet || git commit -m "Update translations" && git stash && git merge --no-edit origin/$CURRENT_BRANCH
# and let's push the merged version upstream
if [[ "$INPUT_PUSH_SOURCES" = true ]] ; then
tx push -s --no-interactive "${common_args[@]}"
fi
if [[ "$INPUT_PUSH_TRANSLATIONS" = true ]] ; then
tx push -t --no-interactive "${common_args[@]}"
fi
if [[ "$INPUT_COMMIT_TO_PR" = true ]] ; then
# Stashes all of the non needed changes (eg. sometines .tx/config is changed)
git stash
git checkout $CURRENT_BRANCH
git checkout ${TRANSLATIONS_MERGE_BRANCH} -- $TRANSLATIONS_FOLDER
git add $(echo ${TRANSLATIONS_FOLDER})
git diff --staged --quiet || git commit -m "Update translations from Transifex"
if [[ "$SKIP_PUSH_COMMIT" = true ]] ; then
echo "SKIPPING PUSH!"
else
git push "${remote_repo}" HEAD:${CURRENT_BRANCH}
fi
fi
else
echo "USING OVERRIDE FLOW"
if [[ "$INPUT_PULL_SOURCES" = true ]] ; then
echo "PULLING SOURCES"
tx pull -s --force --no-interactive "${common_args[@]}"
fi
if [[ "$INPUT_PULL_TRANSLATIONS" = true ]] ; then
echo "PULLING TRANSLATIONS (with args: $args)"
tx pull -a --force --no-interactive "${args[@]}" "${common_args[@]}"
fi
if [[ "$INPUT_PUSH_SOURCES" = true ]] ; then
echo "PUSHING SOURCES"
tx push -s --no-interactive "${common_args[@]}"
fi
if [[ "$INPUT_PUSH_TRANSLATIONS" = true ]] ; then
echo "PUSHING TRANSLATIONS"
tx push -t --no-interactive "${common_args[@]}"
fi
fi