2024-11-28 19:58:58 +02:00
name : Run Release Tests
on :
workflow_dispatch :
inputs :
codexdockerimage :
description : "Codex Docker image (example: 'codexstorage/nim-codex:0.1.8-dist-tests')"
required : true
type : string
workflow_call :
inputs :
2024-12-04 09:30:31 +02:00
source :
description : Repository with tests (current)
required : false
type : string
branch :
description : Branch with tests (master)
required : false
type : string
2024-11-28 19:58:58 +02:00
codexdockerimage :
description : "Codex Docker image (example: 'codexstorage/nim-codex:0.1.8-dist-tests')"
required : true
type : string
2024-12-03 14:59:28 +02:00
workflow_source :
description : Workflow source
required : false
type : string
default : ''
2024-11-28 19:58:58 +02:00
env :
SOURCE : ${{ format('{0}/{1}', github.server_url, github.repository) }}
BRANCH : ${{ github.ref_name }}
CODEXDOCKERIMAGE : codexstorage/nim-codex:latest-dist-tests
TEST_TYPE : release-tests
NAMEPREFIX : r-tests
NAMESPACE : default
JOB_MANIFEST : docker/job-release-tests.yaml
COMMAND : dotnet test Tests/CodexReleaseTests
KUBE_CONFIG : ${{ secrets.KUBE_CONFIG }}
KUBE_VERSION : v1.30.5
jobs :
run_tests :
name : Run Release Tests
runs-on : ubuntu-latest
steps :
- name : Checkout
uses : actions/checkout@v4
with :
repository : ${{ inputs.workflow_source }}
- name : Variables
run : |
RUNID=$(date +%Y%m%d-%H%M%S)
echo "RUNID=${RUNID}" >> $GITHUB_ENV
echo "TESTID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
[ [ -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"
[ [ -n "${{ inputs.codexdockerimage }}" ] ] && echo "CODEXDOCKERIMAGE=${{ inputs.codexdockerimage }}" >>"$GITHUB_ENV" || echo "CODEXDOCKERIMAGE=${{ env.CODEXDOCKERIMAGE }}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.nameprefix }}" ] ] && NAMEPREFIX="`awk '{ print tolower($0) }' <<< ${{ inputs.nameprefix }}`" || NAMEPREFIX="`awk '{ print tolower($0) }' <<< ${{ env.NAMEPREFIX }}`"
echo "NAMEPREFIX=${NAMEPREFIX}-${RUNID}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.namespace }}" ] ] && echo "NAMESPACE=${{ inputs.namespace }}" >>"$GITHUB_ENV" || echo "NAMESPACE=${{ env.NAMESPACE }}" >>"$GITHUB_ENV"
[ [ -n "${{ inputs.command }}" ] ] && COMMAND="${{ inputs.command }}" || COMMAND="${{ env.COMMAND }}"
echo "COMMAND=$(jq -c 'split(" ")' <<< '"'${COMMAND}'"')" >>"$GITHUB_ENV"
- name : Kubectl - Install ${{ env.KUBE_VERSION }}
uses : azure/setup-kubectl@v4
with :
version : ${{ env.KUBE_VERSION }}
- name : Kubectl - Kubeconfig
run : |
mkdir -p "${HOME}"/.kube
echo "${{ env.KUBE_CONFIG }}" | base64 -d > "${HOME}"/.kube/config
- name : Kubectl - Create Job to run tests
run : |
envsubst < ${{ env.JOB_MANIFEST }} | kubectl apply -f -
- name : Tests Identification
run : |
echo "----"
echo "Repository: ${{ env.SOURCE }}"
echo "Branch: ${{ env.BRANCH }}"
echo "Runner job: ${{ env.NAMEPREFIX }}"
echo "Runner pod: $(kubectl get pod --selector job-name=${{ env.NAMEPREFIX }} -ojsonpath='{.items[0].metadata.name}')"
echo "Runner namespace: ${{ env.NAMESPACE }}"
echo "----"
- name : Show Runner logs
run : |
# Variables
# We need more than 300 seconds because Auto Scaler may take 3 minutes to tun a node
namespace="${{ env.NAMESPACE }}"
2024-12-02 14:59:57 +02:00
pod=$(kubectl get pod --selector job-name=${{ env.NAMEPREFIX }} -o jsonpath='{.items[0].metadata.name}')
2024-11-28 19:58:58 +02:00
# Check Pod status
WAIT=120
SECONDS=0
sleep=1
while (( SECONDS < WAIT )); do
2024-12-02 14:59:57 +02:00
phase=$(kubectl get pod ${pod} -n ${namespace} -o jsonpath='{.status.phase}')
2024-11-29 17:31:30 +02:00
[ [ "${phase}" == "Running" ]] && { echo "Pod $pod is in the $phase state - Get the logs"; break; } || { echo "Pod $pod is in the $phase state - Retry in $sleep second(s) / $((WAIT - SECONDS))"; }
2024-11-28 19:58:58 +02:00
sleep $sleep
done
# Get logs
2024-12-02 16:38:02 +02:00
while [[ $(kubectl get pod ${pod} -n ${namespace} -o jsonpath='{.status.phase}') == "Running" ]]; do
echo "Show ${pod} logs ..."
2024-12-16 15:30:51 +02:00
echo "----"
2024-12-02 16:38:02 +02:00
kubectl logs $pod -n $namespace -f || true
sleep 1
done
2024-12-02 14:59:57 +02:00
- name : Set workflow status from job status
run : |
2024-12-02 17:30:48 +02:00
sleep 5
2024-12-02 15:43:45 +02:00
job_status=$(kubectl get jobs ${{ env.NAMEPREFIX }} -n ${{ env.NAMESPACE }} -o jsonpath='{.status.conditions[0].type}')
2024-12-02 14:59:57 +02:00
echo "Job status: $job_status"
2024-12-02 17:30:48 +02:00
if [[ "${job_status}" != "Complete" ]]; then exit 1; fi