-
Notifications
You must be signed in to change notification settings - Fork 13
94 lines (86 loc) · 4.04 KB
/
trigger-testing.yaml
File metadata and controls
94 lines (86 loc) · 4.04 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
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
name: Trigger Testing
run-name: Dispatch operator PR test for PR #${{ github.event.pull_request.number }}
on:
pull_request_target:
types: [labeled, synchronize, reopened]
jobs:
dispatch:
name: Dispatch operator-pr-test
runs-on: ubuntu-22.04
steps:
- name: Parse testing tag
id: parse
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_REF: ${{ github.event.pull_request.head.ref }}
PR_SHA: ${{ github.event.pull_request.head.sha }}
PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
VALID_TEST_RE='^(kind|k3s|k3sarm|k8s|k8sarm|mk8s|mk8sarm|eks|eksarm|aks|aksarm|gke|gkearm|osh|osharm)-([0-9a-f]{7,40})$'
MATCHING_TAGS=()
while IFS= read -r label; do
[[ -n "$label" ]] || continue
if [[ "$label" =~ $VALID_TEST_RE ]]; then
label_hash="${BASH_REMATCH[2]}"
if [[ "$PR_SHA" == "$label_hash"* ]]; then
MATCHING_TAGS+=("$label")
fi
fi
done < <(jq -r '.pull_request.labels[]?.name // empty' "$GITHUB_EVENT_PATH")
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "pr_ref=$PR_REF" >> "$GITHUB_OUTPUT"
echo "pr_sha=$PR_SHA" >> "$GITHUB_OUTPUT"
echo "repo=$PR_REPO" >> "$GITHUB_OUTPUT"
if [[ "${#MATCHING_TAGS[@]}" -gt 1 ]]; then
echo "Found multiple matching <test>-<hash> tags for PR SHA $PR_SHA:" >&2
printf ' - %s\n' "${MATCHING_TAGS[@]}" >&2
exit 1
fi
if [[ "${#MATCHING_TAGS[@]}" -eq 1 ]]; then
TEST_TAG="${MATCHING_TAGS[0]}"
TEST_NAME="${TEST_TAG%-*}"
TEST_HASH="${TEST_TAG##*-}"
echo "enabled=true" >> "$GITHUB_OUTPUT"
echo "test_tag=$TEST_TAG" >> "$GITHUB_OUTPUT"
echo "test_name=$TEST_NAME" >> "$GITHUB_OUTPUT"
echo "test_hash=$TEST_HASH" >> "$GITHUB_OUTPUT"
echo "reason=Matched testing tag $TEST_TAG for PR SHA $PR_SHA" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
echo "reason=No <test>-<hash> tag found on PR labels for current SHA $PR_SHA" >> "$GITHUB_OUTPUT"
fi
- name: Skip when no matching testing tag is present
if: steps.parse.outputs.enabled != 'true'
run: echo "${{ steps.parse.outputs.reason }}"
- name: Dispatch to testing repo
if: steps.parse.outputs.enabled == 'true'
env:
GH_TOKEN: ${{ secrets.OPENSERVERLESS_TESTING_PAT }}
run: |
gh api repos/${{ github.repository_owner }}/openserverless-testing/dispatches \
-X POST \
-f event_type=operator-pr-test \
-f 'client_payload[pr_number]=${{ steps.parse.outputs.pr_number }}' \
-f 'client_payload[pr_ref]=${{ steps.parse.outputs.pr_ref }}' \
-f 'client_payload[pr_sha]=${{ steps.parse.outputs.pr_sha }}' \
-f 'client_payload[operator_repo]=${{ steps.parse.outputs.repo }}' \
-f 'client_payload[test_tag]=${{ steps.parse.outputs.test_tag }}' \
-f 'client_payload[test_name]=${{ steps.parse.outputs.test_name }}' \
-f 'client_payload[test_hash]=${{ steps.parse.outputs.test_hash }}'