Skip to content

Commit 87552fa

Browse files
authored
feat(ci): enable comment-triggered e2e and retire deprecated workflow (#138)
* feat(ci): enable comment-triggered e2e and retire deprecated workflow * trailing newline
1 parent 4752e24 commit 87552fa

File tree

3 files changed

+195
-9
lines changed

3 files changed

+195
-9
lines changed

.github/workflows/e2e.yaml

Lines changed: 181 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,185 @@ on:
44
issue_comment:
55
types: [created]
66

7+
env:
8+
GO_VERSION: "1.23.6"
9+
710
jobs:
8-
e2e:
9-
uses: upbound/uptest/.github/workflows/pr-comment-trigger.yml@main
10-
secrets:
11-
UPTEST_CLOUD_CREDENTIALS: ${{ secrets.UPTEST_CLOUD_CREDENTIALS }}
12-
UPTEST_DATASOURCE: ${{ secrets.UPTEST_DATASOURCE }}
11+
check-permissions:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
permission: ${{ steps.check-permissions.outputs.permission }}
15+
steps:
16+
- name: Get Commenter Permissions
17+
id: check-permissions
18+
run: |
19+
echo "Trigger keyword: '/test-examples'"
20+
echo "Go version: ${{ env.GO_VERSION }}"
21+
22+
REPO=${{ github.repository }}
23+
COMMENTER=${{ github.event.comment.user.login }}
24+
25+
# Fetch the commenter's repo-level permission grant
26+
GRANTED=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
27+
-H "Accept: application/vnd.github.v3+json" \
28+
"https://api.github.com/repos/$REPO/collaborators/$COMMENTER/permission" | jq -r .permission)
29+
30+
# Make it accessible in the workflow via a job output -- cannot use env
31+
echo "User $COMMENTER has $GRANTED permissions"
32+
echo "permission=$GRANTED" >> "$GITHUB_OUTPUT"
33+
34+
get-example-list:
35+
needs: check-permissions
36+
if: ${{ (needs.check-permissions.outputs.permission == 'admin' || needs.check-permissions.outputs.permission == 'write') && github.event.issue.pull_request != null && contains(github.event.comment.body, '/test-examples')}}
37+
runs-on: ubuntu-latest
38+
outputs:
39+
example_list: ${{ steps.get-example-list-name.outputs.example-list }}
40+
example_hash: ${{ steps.get-example-list-name.outputs.example-hash }}
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
45+
with:
46+
submodules: true
47+
48+
- name: Checkout PR
49+
id: checkout-pr
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
gh pr checkout ${{ github.event.issue.number }}
54+
git submodule update --init --recursive
55+
OUTPUT=$(git log -1 --format='%H')
56+
echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT
57+
58+
- name: Prepare The Example List
59+
env:
60+
COMMENT: ${{ github.event.comment.body }}
61+
id: get-example-list-name
62+
run: |
63+
PATHS=$(echo $COMMENT | sed 's/^.*\/test-examples="//g' | cut -d '"' -f 1 | sed 's/,/ /g')
64+
EXAMPLE_LIST=""
65+
for P in $PATHS; do EXAMPLE_LIST="${EXAMPLE_LIST},$(find $P -name '*.yaml' | tr '\n' ',')"; done
66+
67+
sudo apt-get -y install coreutils
68+
COUNT=$(echo ${EXAMPLE_LIST:1} | grep -o ".yaml" | wc -l)
69+
if [ $COUNT -gt 1 ]; then EXAMPLE_HASH=$(echo ${EXAMPLE_LIST} | md5sum | cut -f1 -d" "); else EXAMPLE_HASH=$(echo ${EXAMPLE_LIST:1} | sed 's/.$//'); fi
70+
71+
echo "Examples: ${EXAMPLE_LIST:1}"
72+
echo "Example Hash: ${EXAMPLE_HASH}"
73+
74+
echo "example-list=${EXAMPLE_LIST:1}" >> $GITHUB_OUTPUT
75+
echo "example-hash=${EXAMPLE_HASH}" >> $GITHUB_OUTPUT
76+
77+
- name: Create Pending Status Check
78+
env:
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
run: |
81+
gh api \
82+
--method POST \
83+
-H "Accept: application/vnd.github+json" \
84+
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \
85+
-f state='pending' \
86+
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
87+
-f description='Running...' \
88+
-f context="Uptest-${{ steps.get-example-list-name.outputs.example-hash }}"
89+
90+
uptest:
91+
needs:
92+
- check-permissions
93+
- get-example-list
94+
if: ${{ (needs.check-permissions.outputs.permission == 'admin' || needs.check-permissions.outputs.permission == 'write') && github.event.issue.pull_request != null && contains(github.event.comment.body, '/test-examples')}}
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Cleanup Disk
98+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
99+
with:
100+
large-packages: false
101+
swap-storage: false
102+
103+
- name: Setup QEMU
104+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
105+
with:
106+
platforms: all
107+
108+
- name: Checkout
109+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110+
with:
111+
submodules: true
112+
113+
- name: Setup Go
114+
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
115+
with:
116+
go-version: ${{ env.GO_VERSION }}
117+
118+
- name: Checkout PR
119+
id: checkout-pr
120+
env:
121+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
run: |
123+
gh pr checkout ${{ github.event.issue.number }}
124+
git submodule update --init --recursive
125+
OUTPUT=$(git log -1 --format='%H')
126+
echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT
127+
128+
- name: Vendor Dependencies
129+
run: make vendor vendor.check
130+
131+
- name: Run Uptest
132+
id: run-uptest
133+
env:
134+
UPTEST_CLOUD_CREDENTIALS: ${{ secrets.UPTEST_CLOUD_CREDENTIALS }}
135+
UPTEST_EXAMPLE_LIST: ${{ needs.get-example-list.outputs.example_list }}
136+
UPTEST_TEST_DIR: ./_output/controlplane-dump
137+
UPTEST_DATASOURCE_PATH: .work/uptest-datasource.yaml
138+
UPTEST_UPDATE_PARAMETER: ""
139+
run: |
140+
mkdir -p .work && echo "${{ secrets.UPTEST_DATASOURCE }}" > .work/uptest-datasource.yaml
141+
make e2e
142+
143+
- name: Create Successful Status Check
144+
env:
145+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146+
EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }}
147+
run: |
148+
gh api \
149+
--method POST \
150+
-H "Accept: application/vnd.github+json" \
151+
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \
152+
-f state='success' \
153+
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
154+
-f description='Passed' \
155+
-f context="Uptest-${EXAMPLE_HASH}"
156+
157+
- name: Collect Cluster Dump
158+
if: always()
159+
run: |
160+
make controlplane.dump
161+
162+
- name: Upload Cluster Dump
163+
if: always()
164+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
165+
with:
166+
name: controlplane-dump
167+
path: ./_output/controlplane-dump
168+
169+
- name: Cleanup
170+
if: always()
171+
run: |
172+
eval $(make --no-print-directory build.vars)
173+
${KUBECTL} delete managed --all || true
174+
175+
- name: Create Unsuccessful Status Check
176+
if: failure()
177+
env:
178+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179+
EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }}
180+
run: |
181+
gh api \
182+
--method POST \
183+
-H "Accept: application/vnd.github+json" \
184+
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \
185+
-f state='failure' \
186+
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
187+
-f description='Failed' \
188+
-f context="Uptest-${EXAMPLE_HASH}"

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,20 @@ GO_SUBDIRS += cmd internal apis
5151
KIND_VERSION = v0.23.0
5252
UP_VERSION = v0.31.0
5353
UP_CHANNEL = stable
54-
UPTEST_VERSION = v0.12.0
54+
UPTEST_LOCAL_VERSION ?= v0.13.0
55+
UPTEST_LOCAL_CHANNEL ?= stable
5556
-include build/makelib/k8s_tools.mk
5657
CROSSPLANE_VERSION = 1.16.0
5758

59+
UPTEST_LOCAL := $(TOOLS_HOST_DIR)/uptest-$(UPTEST_LOCAL_VERSION)
60+
61+
$(UPTEST_LOCAL):
62+
@$(INFO) installing uptest $(UPTEST_LOCAL)
63+
@mkdir -p $(TOOLS_HOST_DIR)
64+
@curl -fsSLo $(UPTEST_LOCAL) https://s3.us-west-2.amazonaws.com/crossplane.uptest.releases/$(UPTEST_LOCAL_CHANNEL)/$(UPTEST_LOCAL_VERSION)/bin/$(SAFEHOST_PLATFORM)/uptest || $(FAIL)
65+
@chmod +x $(UPTEST_LOCAL)
66+
@$(OK) installing uptest $(UPTEST_LOCAL)
67+
5868
# ====================================================================================
5969
# Setup Images
6070

@@ -165,9 +175,9 @@ CROSSPLANE_NAMESPACE = upbound-system
165175
-include build/makelib/local.xpkg.mk
166176
-include build/makelib/controlplane.mk
167177

168-
uptest: $(UPTEST) $(KUBECTL) $(KUTTL)
178+
uptest: $(UPTEST_LOCAL) $(KUBECTL) $(KUTTL)
169179
@$(INFO) running automated tests
170-
@KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST) e2e "${UPTEST_EXAMPLE_LIST}" --setup-script=cluster/test/setup.sh || $(FAIL)
180+
@CROSSPLANE_NAMESPACE=$(CROSSPLANE_NAMESPACE) KUBECTL=$(KUBECTL) KUTTL=$(KUTTL) $(UPTEST_LOCAL) e2e "${UPTEST_EXAMPLE_LIST}" --setup-script=cluster/test/setup.sh || $(FAIL)
171181
@$(OK) running automated tests
172182

173183
local-deploy: build controlplane.up local.xpkg.deploy.provider.$(PROJECT_NAME)

cluster/test/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -aeuo pipefail
33

44
echo "Running setup.sh"
55
echo "Creating cloud credential secret..."
6-
${KUBECTL} -n upbound-system create secret generic provider-secret --from-literal=credentials="{\"token\":\"${UPTEST_CLOUD_CREDENTIALS}\"}" --dry-run=client -o yaml | ${KUBECTL} apply -f -
6+
${KUBECTL} -n upbound-system create secret generic provider-secret --from-literal=credentials="${UPTEST_CLOUD_CREDENTIALS}" --dry-run=client -o yaml | ${KUBECTL} apply -f -
77

88
echo "Waiting until provider is healthy..."
99
${KUBECTL} wait provider.pkg --all --for condition=Healthy --timeout 5m

0 commit comments

Comments
 (0)