xref: /aosp_15_r20/external/cldr/tools/scripts/ansible/templates/deploy-sh.j2 (revision 912701f9769bb47905792267661f0baf2b85bed5)
1#!/bin/bash
2# Note: this is managed by Ansible, as deploy-sh.j2
3# Don't modify this file unless its name is deploy-sh.j2
4if [[ ${1} = "--repo" ]];
5then
6    shift
7    GITHUB_REPO=$(echo -n "${1}" | tr -c 'A-Za-z0-9_.-/' '-')
8    GIT_PREFETCH=https://github.com/${GITHUB_REPO}.git
9    shift
10else
11    GITHUB_REPO=unicode-org/cldr
12    GIT_PREFETCH=origin
13fi
14
15GITHUB_SHA=$1
16UNLOCK=$2
17WORKDIR=${TMPDIR-/tmp} # keep all random files here
18SERVICE="{{ cldr_openliberty_service }}"
19
20# TODO: "dogit" could be split out as a separate script
21dogit() {
22    git config --global advice.detachedHead false
23    rm -f ${WORKDIR}/git-list.txt
24    if [[ ${GITHUB_SHA} = "main" ]];
25    then
26        echo "changing ${GITHUB_SHA} to 'origin/main' to get the latest"
27        GITHUB_SHA=origin/main
28    fi
29    # There's some risk that if we fetch something that has been rebased,
30    # we might get stuck here
31    # TODO: add a reset mechanism, if fetch fails we should reset the repo and check out again.
32
33    echo "Git fetch: ${GIT_PREFETCH} @ ${GITHUB_SHA}"
34    git fetch -p "${GIT_PREFETCH}" "${GITHUB_SHA}" || exit 1
35    git clean -f -d || echo 'warning: err on cleanup'
36    # what are we deploying?
37
38    echo    "cldr-trunk was at  :" $(git rev-parse --short HEAD)
39    echo -n "you want to move to:"
40    git rev-parse --short "${GITHUB_SHA}" || exit 1 # fail on err
41    if [[ $(git rev-parse --short HEAD) = $(git rev-parse --short "${GITHUB_SHA}") ]];
42    then
43        echo "No checkout needed. Continuing with redeploy."
44    else
45        echo "Deploy will include these new items:"
46        echo "---"
47        (git log --oneline HEAD..${GITHUB_SHA} | tee ${WORKDIR}/git-list.txt) || exit 1
48        echo "---"
49        if [[ ! -s ${WORKDIR}/git-list.txt ]]; # if empty..
50        then
51            echo "Note, ${GITHUB_SHA} is not ahead of HEAD"  $(git rev-parse --short HEAD)
52            echo "Checking for items that would be REVERTED if we proceed:"
53            echo "---"
54            git log --oneline ${GITHUB_SHA}..HEAD
55            echo "---"
56            if [[ "${UNLOCK}" = "--override" ]];
57            then
58                echo ".. continuing anyway! due to " "${UNLOCK}"
59            else
60                echo "STOP. Check the override box if you really want to do this"
61                exit 1
62            fi
63        fi
64        git checkout -f ${GITHUB_SHA}
65        echo "HEAD is now at" $(git rev-parse --short HEAD) "!"
66     fi
67}
68
69# Check git first, before undeploying. Want to exit early
70(cd  {{ cldr_trunk_path }} && dogit ) || exit 1
71#
72# stop server
73sudo -u root /usr/sbin/service ${SERVICE} stop
74# clear cache
75if [[ -d /srv/st/config/.cache ]];
76then
77   echo "Deleting cache /srv/config/.cache"
78   sudo /usr/bin/rm -rf /srv/st/config/.cache
79fi
80rm -fv ${WORKDIR}/cldr-apps.zip ${WORKDIR}/deploystatus
81# copy cldr-apps.zip from action runner to server
82dd bs=1024000 status=progress of=${WORKDIR}/cldr-apps.zip
83# this counts the # of files to make sure it's not too short, but also verifies that unzip is OK
84echo ; echo -n 'Unzip check, # of files in cldr-apps.zip: '
85(unzip -l ${WORKDIR}/cldr-apps.zip | wc -l ) || exit 1
86cd ${WORKDIR} || exit 1
87rm -rf ./deploy || exit 1
88mkdir ./deploy
89cd ./deploy
90unzip ${WORKDIR}/cldr-apps.zip
91if [[ ! -d ./wlp ]];
92then
93    echo "Error, did not get a ./wlp dir from this zip.. stop"
94    exit 1
95fi
96# Now, do the deployment!
97# exclude these two files
98rsync -r --exclude server.env --exclude workarea --exclude bootstrap.properties -v \
99      --delete ./wlp/usr/servers/cldr/* /var/lib/openliberty/usr/servers/cldr/ || exit 1
100# update datadog
101sed -i.old -e "s/DD_GIT_COMMIT_SHA.*/DD_GIT_COMMIT_SHA=${GITHUB_SHA}/g" -e "s%DD_GIT_REPOSITORY_URL.*%DD_GIT_REPOSITORY_URL=github.com/${GITHUB_REPO}%g" /var/lib/openliberty/usr/servers/{{ cldr_openliberty_server }}/server.env
102sudo -u root /usr/sbin/service ${SERVICE} start || exit 1
103