-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from turkenh/main
Add reusable workflows and Guide for end to end testing with Uptest
- Loading branch information
Showing
6 changed files
with
403 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
name: Run Uptest | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
trigger-keyword: | ||
description: 'Keyword to trigger the workflow, defaults to /test-examples' | ||
default: '/test-examples' | ||
required: false | ||
type: string | ||
go-version: | ||
description: 'Go version to use if building needs to be done' | ||
default: '1.19' | ||
required: false | ||
type: string | ||
secrets: | ||
UPTEST_CLOUD_CREDENTIALS: | ||
description: 'Uptest cloud credentials to be passed to the uptest target as environment variable' | ||
required: true | ||
UPTEST_DATASOURCE: | ||
description: 'A set of key-value pairs to be injected into the uptest' | ||
required: true | ||
|
||
jobs: | ||
debug: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Debug | ||
run: | | ||
echo "Trigger keyword: ${{ inputs.trigger-keyword }}" | ||
echo "Go version: ${{ inputs.go-version }}" | ||
echo "github.event.comment.author_association: ${{ github.event.comment.author_association }}" | ||
echo "github.event.comment.body: ${{ github.event.comment.body }}" | ||
get-example-list: | ||
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' ) && | ||
github.event.issue.pull_request && | ||
contains(github.event.comment.body, inputs.trigger-keyword ) }} | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
example_list: ${{ steps.get-example-list-name.outputs.example-list }} | ||
example_hash: ${{ steps.get-example-list-name.outputs.example-hash }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: true | ||
|
||
- name: Checkout PR | ||
id: checkout-pr | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh pr checkout ${{ github.event.issue.number }} | ||
git submodule update --init --recursive | ||
OUTPUT=$(git log -1 --format='%H') | ||
echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT | ||
- name: Prepare The Example List | ||
env: | ||
COMMENT: ${{ github.event.comment.body }} | ||
id: get-example-list-name | ||
run: | | ||
PATHS=$(echo $COMMENT | sed 's/^.*\${{ inputs.trigger-keyword }}="//g' | cut -d '"' -f 1 | sed 's/,/ /g') | ||
EXAMPLE_LIST="" | ||
for P in $PATHS; do EXAMPLE_LIST="${EXAMPLE_LIST},$(find $P -name *.yaml | tr '\n' ',')"; done | ||
sudo apt-get -y install coreutils | ||
EXAMPLE_HASH=$(echo ${EXAMPLE_LIST} | md5sum | cut -f1 -d" ") | ||
echo "Examples: ${EXAMPLE_LIST:1}" | ||
echo "Example Hash: ${EXAMPLE_HASH}" | ||
echo "example-list=${EXAMPLE_LIST:1}" >> $GITHUB_OUTPUT | ||
echo "example-hash=${EXAMPLE_HASH}" >> $GITHUB_OUTPUT | ||
- name: Create Pending Status Check | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh api \ | ||
--method POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \ | ||
-f state='pending' \ | ||
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ | ||
-f description='Running...' \ | ||
-f context="Uptest-${{ steps.get-example-list-name.outputs.example-hash }}" | ||
uptest: | ||
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' ) && | ||
github.event.issue.pull_request && | ||
contains(github.event.comment.body, inputs.trigger-keyword ) }} | ||
runs-on: ubuntu-22.04 | ||
needs: get-example-list | ||
|
||
steps: | ||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
with: | ||
platforms: all | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
submodules: true | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ inputs.go-version }} | ||
|
||
- name: Checkout PR | ||
id: checkout-pr | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh pr checkout ${{ github.event.issue.number }} | ||
git submodule update --init --recursive | ||
OUTPUT=$(git log -1 --format='%H') | ||
echo "commit-sha=$OUTPUT" >> $GITHUB_OUTPUT | ||
- name: Run Uptest | ||
id: run-uptest | ||
env: | ||
UPTEST_CLOUD_CREDENTIALS: ${{ secrets.UPTEST_CLOUD_CREDENTIALS }} | ||
UPTEST_EXAMPLE_LIST: ${{ needs.get-example-list.outputs.example_list }} | ||
UPTEST_TEST_DIR: ./_output/controlplane-dump | ||
UPTEST_DATASOURCE_PATH: .work/uptest-datasource.yaml | ||
run: | | ||
mkdir -p .work && echo ${{ secrets.UPTEST_DATASOURCE }} > .work/uptest-datasource.yaml | ||
make e2e | ||
- name: Create Successful Status Check | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }} | ||
run: | | ||
gh api \ | ||
--method POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \ | ||
-f state='success' \ | ||
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ | ||
-f description='Passed' \ | ||
-f context="Uptest-${EXAMPLE_HASH}" | ||
- name: Collect Cluster Dump | ||
if: always() | ||
run: | | ||
make controlplane.dump | ||
- name: Upload Cluster Dump | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: controlplane-dump | ||
path: ./_output/controlplane-dump | ||
|
||
- name: Cleanup | ||
if: always() | ||
run: | | ||
eval $(make --no-print-directory build.vars) | ||
${KUBECTL} delete managed --all || true | ||
- name: Create Unsuccessful Status Check | ||
if: failure() | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
EXAMPLE_HASH: ${{ needs.get-example-list.outputs.example_hash }} | ||
run: | | ||
gh api \ | ||
--method POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
/repos/${{ github.repository }}/statuses/${{ steps.checkout-pr.outputs.commit-sha }} \ | ||
-f state='failure' \ | ||
-f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ | ||
-f description='Failed' \ | ||
-f context="Uptest-${EXAMPLE_HASH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule build
updated
5 files
+10 −3 | makelib/common.mk | |
+35 −0 | makelib/controlplane.mk | |
+10 −2 | makelib/docs.mk | |
+12 −1 | makelib/k8s_tools.mk | |
+37 −0 | makelib/local.xpkg.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.