cuelang.org/go@v0.10.1/.github/workflows/evict_caches.yml (about) 1 # Code generated internal/ci/ci_tool.cue; DO NOT EDIT. 2 3 name: Evict caches 4 "on": 5 schedule: 6 - cron: 0 2 * * * 7 jobs: 8 test: 9 if: ${{github.repository == 'cue-lang/cue'}} 10 runs-on: ubuntu-22.04 11 defaults: 12 run: 13 shell: bash 14 steps: 15 - name: Checkout code 16 uses: actions/checkout@v4 17 with: 18 ref: ${{ github.event.pull_request.head.sha }} 19 fetch-depth: 0 20 - name: Reset git directory modification times 21 run: touch -t 202211302355 $(find * -type d) 22 - name: Restore git file modification times 23 uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe 24 - id: DispatchTrailer 25 name: Try to extract Dispatch-Trailer 26 run: |- 27 x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')" 28 if [[ "$x" == "" ]] 29 then 30 # Some steps rely on the presence or otherwise of the Dispatch-Trailer. 31 # We know that we don't have a Dispatch-Trailer in this situation, 32 # hence we use the JSON value null in order to represent that state. 33 # This means that GitHub expressions can determine whether a Dispatch-Trailer 34 # is present or not by checking whether the fromJSON() result of the 35 # output from this step is the JSON value null or not. 36 x=null 37 fi 38 echo "value<<EOD" >> $GITHUB_OUTPUT 39 echo "$x" >> $GITHUB_OUTPUT 40 echo "EOD" >> $GITHUB_OUTPUT 41 - if: |- 42 ((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, ' 43 Dispatch-Trailer: {"type":"')))) && (contains(github.event.head_commit.message, ' 44 Dispatch-Trailer: {"type":"')) 45 name: Check we don't have Dispatch-Trailer on a protected branch 46 run: |- 47 echo "github.event.head_commit.message contains Dispatch-Trailer but we are on a protected branch" 48 false 49 - name: Delete caches 50 run: |- 51 set -x 52 53 echo ${{ secrets.CUECKOO_GITHUB_PAT }} | gh auth login --with-token 54 gh extension install actions/gh-actions-cache 55 for i in https://github.com/cue-lang/cue https://github.com/cue-lang/cue-trybot 56 do 57 echo "Evicting caches for $i" 58 cd $(mktemp -d) 59 git init -b initialbranch 60 git remote add origin $i 61 for j in $(gh actions-cache list -L 100 | grep refs/ | awk '{print $1}') 62 do 63 gh actions-cache delete --confirm $j 64 done 65 done 66 - name: Trigger workflow runs to repopulate caches 67 run: |- 68 # Prepare git for pushes to trybot repo. Note 69 # because we have already checked out code we don't 70 # need origin. Fetch origin default branch for later use 71 git config user.name cueckoo 72 git config user.email cueckoo@gmail.com 73 git config http.https://github.com/.extraheader "AUTHORIZATION: basic $(echo -n cueckoo:${{ secrets.CUECKOO_GITHUB_PAT }} | base64)" 74 git remote add trybot https://github.com/cue-lang/cue-trybot 75 76 # Now trigger the most recent workflow run on each of the default branches. 77 # We do this by listing all the branches on the main repo and finding those 78 # which match the protected branch patterns (globs). 79 for j in $(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" -f https://api.github.com/repos/cue-lang/cue/branches | jq -r '.[] | .name') 80 do 81 for i in master release-branch.* 82 do 83 if [[ "$j" != $i ]]; then 84 continue 85 fi 86 87 echo Branch: $j 88 sha=$(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" "https://api.github.com/repos/cue-lang/cue/commits/$j" | jq -r '.sha') 89 echo Latest commit: $sha 90 91 echo "Trigger workflow on cue-lang/cue" 92 curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue/actions/workflows/trybot.yml/dispatches -d "{\"ref\":\"$j\"}" 93 94 # Ensure that the trybot repo has the latest commit for 95 # this branch. If the force-push results in a commit 96 # being pushed, that will trigger the trybot workflows 97 # so we don't need to do anything, otherwise we need to 98 # trigger the most recent commit on that branch 99 git remote -v 100 git fetch origin refs/heads/$j 101 git log -1 FETCH_HEAD 102 103 success=false 104 for try in {1..20}; do 105 echo "Push to trybot try $try" 106 exitCode=0; push="$(git push -f trybot FETCH_HEAD:$j 2>&1)" || exitCode=$? 107 echo "$push" 108 if [[ $exitCode -eq 0 ]]; then 109 success=true 110 break 111 fi 112 sleep 1 113 done 114 if ! $success; then 115 echo "Giving up" 116 exit 1 117 fi 118 119 if echo "$push" | grep up-to-date 120 then 121 # We are up-to-date, i.e. the push did nothing, hence we need to trigger a workflow_dispatch 122 # in the trybot repo. 123 echo "Trigger workflow on cue-lang/cue-trybot" 124 curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ secrets.CUECKOO_GITHUB_PAT }}" -H "X-GitHub-Api-Version: 2022-11-28" --fail-with-body -X POST https://api.github.com/repos/cue-lang/cue-trybot/actions/workflows/trybot.yml/dispatches -d "{\"ref\":\"$j\"}" 125 else 126 echo "Force-push to cue-lang/cue-trybot did work; nothing to do" 127 fi 128 done 129 done