-
Notifications
You must be signed in to change notification settings - Fork 64
142 lines (133 loc) · 6.01 KB
/
trybot_dispatch.yaml
File metadata and controls
142 lines (133 loc) · 6.01 KB
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
139
140
141
142
# Code generated internal/ci/ci_tool.cue; DO NOT EDIT.
name: Dispatch trybot
"on":
repository_dispatch: {}
push:
branches:
- ci/test
env: {}
jobs:
trybot:
defaults:
run:
shell: bash --noprofile --norc -euo pipefail {0}
permissions:
contents: read
runs-on: namespace-profile-linux-amd64;overrides.cache-tag=cue-dispatch-workflow
if: ${{ ((github.ref == 'refs/heads/ci/test') && false) || github.event.client_payload.type == 'trybot' }}
steps:
- name: Write netrc file for cueckoo Gerrithub
run: |-
cat <<EOD > ~/.netrc
machine cue.gerrithub.io
login cueckoo
password ${{ secrets.CUECKOO_GERRITHUB_PASSWORD }}
EOD
chmod 600 ~/.netrc
- name: Write fake payload
id: payload
if: github.repository == 'cue-lang/cuelang.org' && (github.ref == 'refs/heads/ci/test')
run: |-
cat <<EOD >> $GITHUB_OUTPUT
value<<DOE
null
DOE
EOD
- name: Trigger TryBot (fake data)
if: github.event.client_payload.type != 'trybot'
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://cue.gerrithub.io/a/cue-lang/cuelang.org
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
)"
# --no-divider prevents a "---" line from marking the end of the commit message.
# Here, we know that the input is exactly one commit message,
# so don't do weird things if the commit message has a "---" line.
git log -1 --format=%B | git interpret-trailers --no-divider --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/cuelang.org-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
- name: Trigger TryBot (repository_dispatch payload)
if: github.event.client_payload.type == 'trybot'
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://cue.gerrithub.io/a/cue-lang/cuelang.org
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
)"
# --no-divider prevents a "---" line from marking the end of the commit message.
# Here, we know that the input is exactly one commit message,
# so don't do weird things if the commit message has a "---" line.
git log -1 --format=%B | git interpret-trailers --no-divider --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/cuelang.org-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