Debian Codegraph @

testing/web-platform/tests/tools/ci/epochs_update.sh

raw
1 #!/bin/bash
2 set -eux -o pipefail
3
4 SCRIPT_DIR=$(cd $(dirname "$0") && pwd -P)
5 WPT_ROOT=$SCRIPT_DIR/../..
6
7 EPOCHS=(
8 epochs/three_hourly::3h
9 epochs/six_hourly::6h
10 epochs/twelve_hourly::12h
11 epochs/daily::1d
12 epochs/weekly::1w
13 )
14
15 function get_epoch_branch_name () {
16 echo ${1} | awk -F '::' '{print $1}'
17 }
18
19 function get_epoch_timeval () {
20 echo ${1} | awk -F '::' '{print $2}'
21 }
22
23 main () {
24 ALL_BRANCHES_NAMES=""
25 for e in "${EPOCHS[@]}";
26 do
27 EPOCH=$(get_epoch_timeval ${e})
28 EPOCH_BRANCH_NAME=$(get_epoch_branch_name ${e})
29 EPOCH_SHA=$(./wpt rev-list --epoch ${EPOCH})
30 if [ "${EPOCH_SHA}" = "" ]; then
31 echo "ERROR: Empty SHA returned from ./wpt rev-list"
32 exit 1
33 fi
34 git branch "${EPOCH_BRANCH_NAME}" "${EPOCH_SHA}"
35
36 # Only set epoch tag if is not already tagged from a previous run.
37 if ! git tag --points-at "${EPOCH_SHA}" | grep "${EPOCH_BRANCH_NAME}"; then
38 EPOCH_STAMP="$(date +%Y-%m-%d_%HH)"
39 git tag "${EPOCH_BRANCH_NAME}/${EPOCH_STAMP}" "${EPOCH_SHA}"
40 fi
41
42 ALL_BRANCHES_NAMES="${ALL_BRANCHES_NAMES} ${EPOCH_BRANCH_NAME}"
43 done
44 # This is safe because `git push` will by default fail for a non-fast-forward
45 # push, for example if the remote branch is ahead of the local branch.
46 git push --porcelain --tags ${REMOTE} ${ALL_BRANCHES_NAMES} | tee "${RUNNER_TEMP}/git-push-output.txt"
47 }
48
49 cd $WPT_ROOT
50
51 if [ -z "$GITHUB_TOKEN" ]; then
52 echo "GITHUB_TOKEN must be set as an environment variable"
53 exit 1
54 fi
55
56 REMOTE=https://x-access-token:[email protected]/web-platform-tests/wpt.git
57
58 main