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