2023-11-06 13:09:51 +00:00
name : Run Continuous Tests
on :
workflow_dispatch :
inputs :
source :
description : Repository with tests (current)
required : false
type : string
2023-11-12 15:07:53 +00:00
branch :
description : Branch with tests (master)
required : false
type : string
2023-11-22 19:04:59 +00:00
codexdockerimage :
description : Codex Docker image (codexstorage/nim-codex:latest-dist-tests)
required : false
type : string
2023-11-06 13:09:51 +00:00
nameprefix :
2023-11-19 19:13:40 +00:00
description : Resources prefix (c-tests)
2023-11-06 13:09:51 +00:00
required : false
type : string
tests_target_duration :
2023-11-19 19:13:40 +00:00
description : Runner target duration (2d)
2023-11-06 13:09:51 +00:00
required : false
type : string
tests_filter :
description : Runner tests filter ("")
required : false
type : string
tests_cleanup :
2023-11-12 15:07:53 +00:00
description : Runner tests cleanup
2023-11-26 19:20:04 +00:00
required : false
2023-11-19 19:13:40 +00:00
type : boolean
2023-11-12 15:07:53 +00:00
default : true
2023-11-19 19:13:40 +00:00
workflow_call :
inputs :
source :
description : Repository with tests (current)
required : false
type : string
branch :
description : Branch with tests (master)
required : false
type : string
2023-11-22 19:04:59 +00:00
codexdockerimage :
2023-11-26 19:20:04 +00:00
description : Codex Docker image (codexstorage/nim-codex:latest-dist-tests)
2023-11-22 19:04:59 +00:00
required : false
type : string
2023-11-19 19:13:40 +00:00
nameprefix :
description : Resources prefix (c-tests)
required : false
type : string
tests_target_duration :
description : Runner target duration (2d)
2023-11-06 13:09:51 +00:00
required : false
type : string
2023-11-19 19:13:40 +00:00
tests_filter :
description : Runner tests filter ("")
required : false
type : string
tests_cleanup :
description : Runner tests cleanup
required : false
type : boolean
2023-11-26 19:20:04 +00:00
default : true
workflow_source :
description : Workflow source
required : false
type : string
default : ''
2023-11-06 13:09:51 +00:00
env :
SOURCE : ${{ format('{0}/{1}', github.server_url, github.repository) }}
2023-11-19 19:13:40 +00:00
BRANCH : ${{ github.ref_name }}
2023-11-22 19:04:59 +00:00
CODEXDOCKERIMAGE : codexstorage/nim-codex:latest-dist-tests
2023-11-19 19:13:40 +00:00
NAMEPREFIX : c-tests
2023-11-06 13:09:51 +00:00
NAMESPACE : default
2023-11-19 19:13:40 +00:00
TESTS_TARGET_DURATION : 2d
2023-11-06 13:09:51 +00:00
TESTS_FILTER : ""
TESTS_CLEANUP : true
JOB_MANIFEST : docker/continuous-tests-job.yaml
KUBE_CONFIG : ${{ secrets.KUBE_CONFIG }}
KUBE_VERSION : v1.28.2
jobs :
run_tests :
2023-11-26 19:20:04 +00:00
name : Run Continuous Tests ${{ inputs.tests_filter }}
2023-11-06 13:09:51 +00:00
runs-on : ubuntu-latest
steps :
- name : Checkout
2024-02-19 11:05:51 +00:00
uses : actions/checkout@v4
2023-11-26 19:20:04 +00:00
with :
repository : ${{ inputs.workflow_source }}
2023-11-06 13:09:51 +00:00
- name : Variables
run : |
2023-11-12 15:07:53 +00:00
RUNID=$(date +%Y%m%d-%H%M%S)
echo "RUNID=${RUNID}" >> $GITHUB_ENV
echo "TESTID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
2023-11-19 19:13:40 +00:00
[ [ -n "${{ inputs.source }}" ] ] && echo "SOURCE=${{ inputs.source }}" >>"$GITHUB_ENV" || echo "SOURCE=${{ env.SOURCE }}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.branch }}" ] ] && echo "BRANCH=${{ inputs.branch }}" >>"$GITHUB_ENV" || echo "BRANCH=${{ env.BRANCH }}" >>"$GITHUB_ENV"
2023-11-22 19:04:59 +00:00
[ [ -n "${{ inputs.codexdockerimage }}" ] ] && echo "CODEXDOCKERIMAGE=${{ inputs.codexdockerimage }}" >>"$GITHUB_ENV" || echo "CODEXDOCKERIMAGE=${{ env.CODEXDOCKERIMAGE }}" >>"$GITHUB_ENV"
2023-11-26 19:20:04 +00:00
[ [ -n "${{ inputs.nameprefix }}" ] ] && NAMEPREFIX="`awk '{ print tolower($0) }' <<< ${{ inputs.nameprefix }}`" || NAMEPREFIX="`awk '{ print tolower($0) }' <<< ${{ env.NAMEPREFIX }}`"
echo "NAMEPREFIX=${NAMEPREFIX}-${RUNID}" >>"$GITHUB_ENV"
echo "DEPLOYMENT_NAMESPACE=${NAMEPREFIX}-${RUNID}" >>"$GITHUB_ENV"
2023-11-19 19:13:40 +00:00
[ [ -n "${{ inputs.namespace }}" ] ] && echo "NAMESPACE=${{ inputs.namespace }}" >>"$GITHUB_ENV" || echo "NAMESPACE=${{ env.NAMESPACE }}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.tests_target_duration }}" ] ] && echo "TESTS_TARGET_DURATION=${{ inputs.tests_target_duration }}" >>"$GITHUB_ENV" || echo "TESTS_TARGET_DURATION=${{ env.TESTS_TARGET_DURATION }}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.tests_filter }}" ] ] && echo "TESTS_FILTER=${{ inputs.tests_filter }}" >>"$GITHUB_ENV" || echo "TESTS_FILTERS=${{ env.TESTS_FILTERS }}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.tests_cleanup }}" ] ] && echo "TESTS_CLEANUP=${{ inputs.tests_cleanup }}" >>"$GITHUB_ENV" || echo "TESTS_CLEANUP=${{ env.TESTS_CLEANUP }}" >>"$GITHUB_ENV"
2023-11-12 15:07:53 +00:00
2023-11-06 13:09:51 +00:00
- name : Kubectl - Install ${{ env.KUBE_VERSION }}
2024-02-19 18:50:42 +00:00
uses : azure/setup-kubectl@releases/v4.0.0
2023-11-06 13:09:51 +00:00
with :
version : ${{ env.KUBE_VERSION }}
- name : Kubectl - Kubeconfig
run : |
mkdir -p "${HOME}"/.kube
echo "${{ env.KUBE_CONFIG }}" | base64 -d > "${HOME}"/.kube/config
2023-11-12 15:07:53 +00:00
2023-11-06 13:09:51 +00:00
- name : Kubectl - Create Job
run : |
envsubst < ${{ env.JOB_MANIFEST }} | kubectl apply -f -
2023-11-12 15:07:53 +00:00
- name : Tests Identification
run : |
echo "----"
echo "Repository: ${{ env.SOURCE }}"
echo "Branch: ${{ env.BRANCH }}"
2023-11-19 19:13:40 +00:00
echo "Runner job: ${{ env.NAMEPREFIX }}"
echo "Runner pod: `kubectl get pod --selector job-name=${{ env.NAMEPREFIX }} -ojsonpath='{.items[0].metadata.name}'`"
2023-11-12 15:07:53 +00:00
echo "Runner namespace: ${{ env.NAMESPACE }}"
echo "----"
2023-11-12 16:35:11 +00:00
echo "Tests runid: ${{ env.RUNID }}"
2023-11-22 19:04:59 +00:00
echo "Tests codexdockerimage: ${{ env.CODEXDOCKERIMAGE }}"
2023-11-12 15:07:53 +00:00
echo "Tests namespace: ${{ env.DEPLOYMENT_NAMESPACE }}"
echo "Tests duration: ${{ env.TESTS_TARGET_DURATION }}"
echo "Tests filter: ${{ env.TESTS_FILTER }}"
echo "Tests cleanup: ${{ env.TESTS_CLEANUP }}"
echo "----"
2023-11-19 19:13:40 +00:00
- name : Show Runner logs
if : false
run : |
# Variables
# We need more than 300 seconds because Auto Scaler may take 3 minutes to tun a node
duration=600
namespace="${{ env.NAMESPACE }}"
pod=$(kubectl get pod --selector job-name=${{ env.NAMEPREFIX }} -o jsonpath="{.items[0].metadata.name}")
# Check Pod status
WAIT=120
SECONDS=0
sleep=1
while (( SECONDS < WAIT )); do
phase=$(kubectl get pod ${pod} -n ${namespace} -o jsonpath="{.status.phase}")
[ [ "${phase}" == "Running" ]] && { echo "Pod $pod is in $phase state - Get the logs"; break; } || { echo "Pod $pod is in $phase state - Retry in $sleep seconds / $((WAIT - SECONDS))"; }
sleep $sleep
done
# Get logs
timeout $duration \
kubectl logs $pod \
-n $namespace \
-f \
--tail=-1 \
--timestamps || true