Make package-translations build fail when it fails

Includes:
- Take `git status` command out of condition so failure is detected
- Guards in the `sync-strings.sh` script so it can run locally
- Dockerfile change for better cache usage when iterating locally

test plan
- `export SSH_KEY_FILE=./nonexistent`
- Run the script
  `build/new-jenkins/package-translations/sync-translations.sh`
- Verify that the value of `$?` is non-zero

Alternatively, observe the differences between these two builds
 - https://jenkins.inst-ci.net/job/Canvas/job/package-translations/1166/
   run against the master branch
 - https://jenkins.inst-ci.net/job/Canvas/job/package-translations/1167/
   run against this PS

Change-Id: Ifa74770f2ff1ac7526577587abfc1e5a128fbde0
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/303133
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Aaron Ogata <aogata@instructure.com>
Build-Review: Aaron Ogata <aogata@instructure.com>
QA-Review: Joe Hernandez <joe.hernandez@instructure.com>
Product-Review: Jon Scheiding <jon.scheiding@instructure.com>
This commit is contained in:
Jon Scheiding 2022-10-12 14:55:02 -04:00
parent 3f92d08a65
commit 3f10c924f7
2 changed files with 23 additions and 17 deletions

View File

@ -19,7 +19,6 @@ COPY --chown=docker:docker package.json yarn.lock /usr/src/app/
COPY --chown=docker:docker packages/ /usr/src/app/packages/
COPY --chown=docker:docker script/install_hooks /usr/src/app/script/
COPY --chown=docker:docker script/fix_inst_esm.js /usr/src/app/script/fix_inst_esm.js
COPY --chown=docker:docker build/new-jenkins/package-translations/ /usr/src/app/package-translations
USER docker
@ -28,4 +27,6 @@ RUN yarn install --network-concurrency 1 \
yarn-private --network-concurrency 1 -W \
add @inst/sync-format-message-translations
COPY --chown=docker:docker build/new-jenkins/package-translations/ /usr/src/app/package-translations
CMD ["tail", "-f", "/dev/null"]

View File

@ -8,12 +8,14 @@ set -x -o errexit -o errtrace -o nounset -o pipefail
# to the repo.
##
export AWS_ROLE_ARN="arn:aws:iam::307761260553:role/translations-jenkins"
export GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i /usr/src/sshkeyfile -l $SSH_USERNAME"
if [ ! -z "${SSH_USERNAME-}" ]; then
export AWS_ROLE_ARN="arn:aws:iam::307761260553:role/translations-jenkins"
export GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=no -i /usr/src/sshkeyfile -l $SSH_USERNAME"
"$(yarn bin)/sync-translations" --ignore-jira --config ./package-translations/sync-config.json
"$(yarn bin)/sync-translations" --ignore-jira --config ./package-translations/sync-config.json
"$(yarn bin)/sync-translations" --ignore-jira --config ./package-translations/sync-config-crowd.json
"$(yarn bin)/sync-translations" --ignore-jira --config ./package-translations/sync-config-crowd.json
fi
# Remove empty/missing strings from catalogs.
for file in packages/translations/lib/*.json; do
@ -22,7 +24,8 @@ for file in packages/translations/lib/*.json; do
done
# If there are no changes to commit, bail out
if [[ -z $(git status --porcelain | grep 'packages/translations/lib') ]]; then
GIT_STATUS=$(git status --porcelain)
if [[ -z $(echo $GIT_STATUS | grep 'packages/translations/lib') ]]; then
echo "No new translations to commit"
exit 0
fi
@ -37,16 +40,18 @@ popd
yarn wsrun --exclude-missing installTranslations
git config --global user.name "Jenkins"
git config --global user.email "svc.cloudjenkins@instructure.com"
if [ ! -z "${SSH_USERNAME-}" ]; then
git config --global user.name "Jenkins"
git config --global user.email "svc.cloudjenkins@instructure.com"
gitdir=$(git rev-parse --git-dir); scp -o StrictHostKeyChecking=no -i /usr/src/sshkeyfile -p -P 29418 "${SSH_USERNAME}@gerrit.instructure.com:hooks/commit-msg" "${gitdir}/hooks/"
# Commit any changes into a temp branch then push to gerrit
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git checkout -B sync-translations-tmp && \
git add -A packages/translations/lib && \
git commit -m "[i18n] Update package translations" && \
git push origin sync-translations-tmp:refs/for/master%submit,l=Verified+1 && \
git checkout "$CURRENT_BRANCH"
gitdir=$(git rev-parse --git-dir); scp -o StrictHostKeyChecking=no -i /usr/src/sshkeyfile -p -P 29418 "${SSH_USERNAME}@gerrit.instructure.com:hooks/commit-msg" "${gitdir}/hooks/"
# Commit any changes into a temp branch then push to gerrit
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git checkout -B sync-translations-tmp && \
git add -A packages/translations/lib && \
git commit -m "[i18n] Update package translations" && \
git push origin sync-translations-tmp:refs/for/master%submit,l=Verified+1 && \
git checkout "$CURRENT_BRANCH"
yarn wsrun --exclude-missing commitTranslations
yarn wsrun --exclude-missing commitTranslations
fi