-
Notifications
You must be signed in to change notification settings - Fork 294
133 lines (124 loc) · 5.35 KB
/
trybot_dispatch.yaml
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
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
name: Dispatch trybot
"on":
repository_dispatch: {}
push:
branches:
- ci/test
jobs:
trybot:
runs-on: ubuntu-22.04
if: ${{ ((github.ref == 'refs/heads/ci/test') && false) || github.event.client_payload.type == 'trybot' }}
defaults:
run:
shell: bash
steps:
- name: Write netrc file for cueckoo Gerrithub
run: |-
cat <<EOD > ~/.netrc
machine review.gerrithub.io
login cueckoo
password ${{ secrets.CUECKOO_GERRITHUB_PASSWORD }}
EOD
chmod 600 ~/.netrc
- id: payload
if: github.repository == 'cue-lang/cue' && (github.ref == 'refs/heads/ci/test')
name: Write fake payload
run: |-
cat <<EOD >> $GITHUB_OUTPUT
value<<DOE
null
DOE
EOD
- if: github.event.client_payload.type != 'trybot'
name: Trigger TryBot (fake data)
run: |-
mkdir tmpgit
cd tmpgit
git init -b initialbranch
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 origin https://review.gerrithub.io/a/cue-lang/cue
git fetch origin ${{ fromJSON(steps.payload.outputs.value).ref }}
git checkout -b local_${{ fromJSON(steps.payload.outputs.value).targetBranch }} FETCH_HEAD
# Error if we already have dispatchTrailer according to git log logic.
# See earlier check for GitHub expression logic check.
x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')"
if [[ "$x" != "" ]]
then
echo "Ref ${{ fromJSON(steps.payload.outputs.value).ref }} already has a Dispatch-Trailer"
exit 1
fi
# Add the trailer because we don't have it yet. GitHub expressions do not have a
# substitute or quote capability. So we do that in shell. We also strip out the
# indenting added by toJSON. We ensure that the type field is first in order
# that we can safely check for specific types of dispatch trailer.
#
# Use bash heredoc so that JSON's use of double quotes does
# not get interpreted as shell.
trailer="$(cat <<EOD | jq -r -c '{type} + .'
${{ toJSON(fromJSON(steps.payload.outputs.value)) }}
EOD
)"
git log -1 --format=%B | git interpret-trailers --trailer "Dispatch-Trailer: $trailer" | git commit --amend -F -
git log -1
success=false
for try in {1..20}; do
echo "Push to trybot try $try"
if git push -f https://github.com/cue-lang/cue-trybot local_${{ fromJSON(steps.payload.outputs.value).targetBranch }}:${{ fromJSON(steps.payload.outputs.value).targetBranch }}; then
success=true
break
fi
sleep 1
done
if ! $success; then
echo "Giving up"
exit 1
fi
- if: github.event.client_payload.type == 'trybot'
name: Trigger TryBot (repository_dispatch payload)
run: |-
mkdir tmpgit
cd tmpgit
git init -b initialbranch
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 origin https://review.gerrithub.io/a/cue-lang/cue
git fetch origin ${{ github.event.client_payload.ref }}
git checkout -b local_${{ github.event.client_payload.targetBranch }} FETCH_HEAD
# Error if we already have dispatchTrailer according to git log logic.
# See earlier check for GitHub expression logic check.
x="$(git log -1 --pretty='%(trailers:key=Dispatch-Trailer,valueonly)')"
if [[ "$x" != "" ]]
then
echo "Ref ${{ github.event.client_payload.ref }} already has a Dispatch-Trailer"
exit 1
fi
# Add the trailer because we don't have it yet. GitHub expressions do not have a
# substitute or quote capability. So we do that in shell. We also strip out the
# indenting added by toJSON. We ensure that the type field is first in order
# that we can safely check for specific types of dispatch trailer.
#
# Use bash heredoc so that JSON's use of double quotes does
# not get interpreted as shell.
trailer="$(cat <<EOD | jq -r -c '{type} + .'
${{ toJSON(github.event.client_payload) }}
EOD
)"
git log -1 --format=%B | git interpret-trailers --trailer "Dispatch-Trailer: $trailer" | git commit --amend -F -
git log -1
success=false
for try in {1..20}; do
echo "Push to trybot try $try"
if git push -f https://github.com/cue-lang/cue-trybot local_${{ github.event.client_payload.targetBranch }}:${{ github.event.client_payload.targetBranch }}; then
success=true
break
fi
sleep 1
done
if ! $success; then
echo "Giving up"
exit 1
fi