|
| 1 | +#!/bin/bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +if ! git config --get alias.update-cache > /dev/null; then |
| 20 | + printf '\e[36m%s\n\n %s\n\e[0m\n' \ |
| 21 | + 'Hint: you can create a Git alias to execute this script. Example:' \ |
| 22 | + "git config alias.update-cache '!bash $(realpath "$0")'" |
| 23 | +fi |
| 24 | + |
| 25 | +key="$( |
| 26 | + gh cache list \ |
| 27 | + --key 'gradle-home-v1|Linux-X64|test' \ |
| 28 | + --sort 'created_at' \ |
| 29 | + --limit 1 \ |
| 30 | + --json 'key' \ |
| 31 | + --jq '.[].key' |
| 32 | +)" |
| 33 | + |
| 34 | +sha="$(cut -d '-' -f 5 <<< "$key")" |
| 35 | + |
| 36 | +if ! git show "$sha" &> /dev/null; then |
| 37 | + printf '\e[33m%s\n%s\e[0m\n' \ |
| 38 | + "Cannot update 'trunk-cached' because SHA $sha" \ |
| 39 | + "does not exist locally. Please update your remote and try again." |
| 40 | +else |
| 41 | + if git branch -f trunk-cached "$sha" &> /dev/null; then |
| 42 | + rel_date="$(git show --no-patch $sha --date=relative --pretty=format:'%cr')" |
| 43 | + printf '%s\n' "Local branch 'trunk-cached' successfully updated to $(head -c 10 <<< "$sha") (from $rel_date)." |
| 44 | + else |
| 45 | + printf '\e[31m%s\e[0m\n' "Failed to update ref for 'trunk-cached' and commit $(head -c 10 <<< "$sha")." |
| 46 | + fi |
| 47 | +fi |
0 commit comments