epochs_update.sh (1977B)
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 # We save the output so that GitHub Actions workflows can find out what got 47 # pushed, as workflows are not triggered by push events caused by another 48 # workflow. We need to pass core.abbrev as actions/checkout only allows refs to 49 # be specified as an object id if they are exactly 40 characters. 50 git -c core.abbrev=40 push --porcelain --tags ${REMOTE} ${ALL_BRANCHES_NAMES} | tee "${RUNNER_TEMP}/git-push-output.txt" 51 } 52 53 cd $WPT_ROOT 54 55 if [ -z "$GITHUB_TOKEN" ]; then 56 echo "GITHUB_TOKEN must be set as an environment variable" 57 exit 1 58 fi 59 60 REMOTE=https://x-access-token:$GITHUB_TOKEN@github.com/web-platform-tests/wpt.git 61 62 main