|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +SCRIPTDIR=$(cd $(dirname "$0") && pwd) |
| 4 | + |
| 5 | +# name of the configmap |
| 6 | +CM=codeflare-self-test-config |
| 7 | + |
| 8 | +# we will test the latest **remote** version of the current local |
| 9 | +# org+branch e.g. if your local branch is from org `starpit` and |
| 10 | +# branch `fixing-bug`, then make sure to commit and push your changes |
| 11 | +# to the remote, otherwise any changes you hoped to test will not be |
| 12 | +# picked up |
| 13 | +ORG=${GITHUB_REPOSITORY_OWNER-$(git config remote.$(git config branch.main.remote).url | cut -f2 -d: | cut -f1 -d/)} |
| 14 | +BRANCH=$(git branch --show-current) |
| 15 | +echo "github org=$ORG branch=$BRANCH" |
| 16 | + |
| 17 | +# if you hit ctrl+c, we will tear everything down |
| 18 | +trap cleanup INT |
| 19 | + |
| 20 | +# configure kind if needed |
| 21 | +function kind() { |
| 22 | + if [ -n "$NEEDS_KIND" ]; then |
| 23 | + export KUBECONFIG=$("$SCRIPTDIR"/../../tests/kind/setup.sh) |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +# delete the job and configmap (etc.) |
| 28 | +function cleanup() { |
| 29 | + tput setaf 5 |
| 30 | + kubectl delete cm $CM |
| 31 | + kubectl delete -f "$SCRIPTDIR"/self-test.yaml |
| 32 | + tput sgr0 |
| 33 | +} |
| 34 | + |
| 35 | +# create the job and configmap (etc.) |
| 36 | +function start() { |
| 37 | + # necessary to support cloning when run as a github action; the |
| 38 | + # cloning happens in self-test.sh, inside the running pod (spawned |
| 39 | + # by this apply) |
| 40 | + if [ -n "$GITHUB_ACTOR" ] && [ -n "$GITHUB_TOKEN" ]; then |
| 41 | + GITHUB_ACTOR_PREFIX="$GITHUB_ACTOR:$GITHUB_TOKEN@" |
| 42 | + fi |
| 43 | + |
| 44 | + tput setaf 5 |
| 45 | + kubectl create cm $CM \ |
| 46 | + --from-literal=ORG=$ORG \ |
| 47 | + --from-literal=BRANCH=$BRANCH \ |
| 48 | + --from-literal=VARIANTS=$VARIANTS \ |
| 49 | + --from-literal=GITHUB_ACTOR_PREFIX=$GITHUB_ACTOR_PREFIX \ |
| 50 | + --from-literal=GITHUB_SHA=$GITHUB_SHA \ |
| 51 | + --from-literal=GITHUB_REF=$GITHUB_REF |
| 52 | + |
| 53 | + kubectl apply -f "$SCRIPTDIR"/self-test.yaml |
| 54 | + tput sgr0 |
| 55 | +} |
| 56 | + |
| 57 | +# wait for a pod (of the job) to be ready |
| 58 | +function waitForReady() { |
| 59 | + tput setaf 3 |
| 60 | + echo "Waiting for job to start" |
| 61 | + tput sgr0 |
| 62 | + kubectl wait pod -l job-name=codeflare-self-test --for=condition=Ready |
| 63 | +} |
| 64 | + |
| 65 | +# stream out the logs of our job's pod(s) |
| 66 | +function logs() { |
| 67 | + tput setaf 3 |
| 68 | + echo "Streaming out job logs" |
| 69 | + tput sgr0 |
| 70 | + kubectl logs -l job-name=codeflare-self-test -f |
| 71 | +} |
| 72 | + |
| 73 | +function waitForComplete() { |
| 74 | + tput setaf 3 |
| 75 | + echo "Waiting for job completion" |
| 76 | + tput sgr0 |
| 77 | + kubectl wait pod -l job-name=codeflare-self-test --for=condition=Complete --timeout=-1s |
| 78 | +} |
| 79 | + |
| 80 | +kind |
| 81 | +cleanup |
| 82 | +start |
| 83 | +waitForReady |
| 84 | +logs |
| 85 | +waitForComplete |
0 commit comments