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