name: open-vmdk CI on: [push, workflow_dispatch] env: POI_REGISTRY: poi-registry:5000 POI_IMAGE_BASE: poi-registry:5000/photon/installer:latest GITHUB_BRANCH: master jobs: build-container: runs-on: self-hosted steps: - name: Checkout code uses: actions/checkout@v3 - name: Build Docker image run: | set -e POI_IMAGE_NAME=${POI_REGISTRY}/photon/installer:open-vmdk-${GITHUB_SHA::7} cd docker docker build -t ${POI_IMAGE_NAME} --build-context open-vmdk=$(realpath $(pwd)/..) --build-arg POI_IMAGE=$POI_IMAGE_BASE -f Dockerfile-open-vmdk-tot . docker push ${POI_IMAGE_NAME} docker system prune -f cayman_poi: runs-on: self-hosted steps: - name: Checkout Cayman POI uses: actions/checkout@master with: repository: vcf/cayman-poi ref: vmware-master path: ./cayman-poi submodules: "true" fetch-depth: 0 ssh-key: ${{ secrets.POI_CICD_SSH_KEY }} ssh-strict: "false" - name: create branch and push run: | cd ./cayman-poi BRANCH_NAME=test/openvmdk-submodule/${GITHUB_SHA::7} if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then echo "Branch $BRANCH_NAME already exists locally, switching to it" git checkout "$BRANCH_NAME" elif git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then echo "Branch $BRANCH_NAME exists remotely, checking it out" git checkout -b "$BRANCH_NAME" "origin/$BRANCH_NAME" else echo "Branch $BRANCH_NAME does not exist, creating it" git checkout -b "$BRANCH_NAME" fi pushd poi/open-vmdk git fetch git checkout ${GITHUB_SHA::7} popd git add poi/open-vmdk git config --global user.email "poi-cicd@broadcom.com" git config --global user.name "POI CI/CD" # Only commit if there are changes if git diff --cached --quiet; then echo "No changes to commit, skipping commit step" else git commit -m "update poi/open-vmdk to ${GITHUB_SHA::7} for testing branch ${{ github.ref_name }}" fi git push origin ${BRANCH_NAME} - name: Wait for and monitor cayman-poi workflow env: GITHUB_TOKEN: ${{ secrets.PAT_POI_CICD_RO }} run: | BRANCH_NAME="test/openvmdk-submodule/${GITHUB_SHA::7}" echo "Monitoring branch: $BRANCH_NAME" # Function to get workflow runs for the branch get_workflow_runs() { curl -s \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs?branch=$BRANCH_NAME" \ | jq -r '.workflow_runs[] | select(.head_branch == "'$BRANCH_NAME'") | "\(.id) \(.status) \(.conclusion // "null") \(.created_at)"' } # Wait for workflow to start (up to 5 minutes) echo "Waiting for workflow to start on branch $BRANCH_NAME..." timeout=300 interval=30 elapsed=0 while [ $elapsed -lt $timeout ]; do runs=$(get_workflow_runs) if [ -n "$runs" ]; then echo "Workflow detected:" echo "$runs" break fi echo "No workflow found yet, waiting ${interval}s..." sleep $interval elapsed=$((elapsed + interval)) done if [ $elapsed -ge $timeout ]; then echo "ERROR: No workflow was triggered within $timeout seconds" exit 1 fi # Get the workflow run ID (first field from the output) run_id=$(echo "$runs" | head -1 | cut -d' ' -f1) echo "Monitoring workflow run ID: $run_id" # Monitor workflow status (up to 1 hour) timeout=3600 interval=30 elapsed=0 while [ $elapsed -lt $timeout ]; do run_info=$(curl -s \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs/$run_id") status=$(echo "$run_info" | jq -r '.status') conclusion=$(echo "$run_info" | jq -r '.conclusion // "null"') url=$(echo "$run_info" | jq -r '.html_url') echo "Workflow status: $status, conclusion: $conclusion" if [ "$status" = "completed" ]; then echo "Workflow completed with conclusion: $conclusion" echo "Workflow URL: $url" if [ "$conclusion" = "success" ]; then echo "✅ Cayman POI workflow succeeded!" exit 0 elif [ "$conclusion" = "null" ]; then echo "❌ Cayman POI workflow completed but conclusion is null" echo "Check the workflow at: $url" exit 1 else echo "❌ Cayman POI workflow failed with conclusion: $conclusion" echo "Check the workflow at: $url" exit 1 fi fi sleep $interval elapsed=$((elapsed + interval)) done echo "ERROR: Workflow did not complete within $timeout seconds" echo "Workflow URL: $url" exit 1 pytest: runs-on: self-hosted steps: - name: Checkout code uses: actions/checkout@v3 - name: pytest run: | set -e make pytest-3 pytest/ poi-harness: runs-on: - self-hosted - docker:root needs: build-container steps: - name: Checkout code uses: actions/checkout@master - name: Checkout POI Harness uses: actions/checkout@master with: repository: vcf/photon-os-installer-harness ref: main path: ./poi-harness ssh-key: ${{ secrets.POI_CICD_SSH_KEY }} ssh-strict: false - name: Build OVA run: | set -e VM_NAME=poi-open-vmdk-test-${GITHUB_SHA::7} POI_IMAGE_NAME=${POI_REGISTRY}/photon/installer:open-vmdk-${GITHUB_SHA::7} PHOTON_RELEASE="5.0" # used by pytest export VC_IP=${{ vars.VC_IP }} export VC_USER=${{ vars.VC_USER }} export VC_PASSWORD=${{ secrets.VC_PASSWORD }} mkdir harness cp pytest/ks/*.yaml pytest/configs/{photon*.yaml,EULA.txt} harness/ cd harness docker run --rm --privileged -v/dev:/dev -v$(pwd):/workdir ${POI_IMAGE_NAME} create-image --repo-paths 'https://packages.vmware.com/photon/$releasever/photon_updates_$releasever_$basearch' -c ova_ks.yaml -v ${PHOTON_RELEASE} docker run --rm -v$(pwd):/workdir -w/workdir ${POI_IMAGE_NAME} create-ova --ovf --vmdk --installer-config ova_ks.yaml --ova-config photon.yaml --ova-name photon # POI harness will deploy OVF on a VC and run tests pytest ../poi-harness/ci/pytest/ -rs --deploy --ovf photon.ovf --name ${VM_NAME} --ks_config ova_ks.yaml --ova_config photon.yaml # create OVF using photon_configurations.yaml, re-use the vmdk: docker run --rm -v$(pwd):/workdir -w/workdir ${POI_IMAGE_NAME} create-ova --ovf --installer-config ova_ks.yaml --ova-config photon_configurations.yaml --ova-name photon_configurations for option in tall grande venti ; do pytest ../poi-harness/ci/pytest/ -rs \ --deploy --ovf photon_configurations.ovf --name ${VM_NAME}-${option} \ --ks_config ova_ks.yaml --ova_config photon_configurations.yaml --deployment_option=${option}; done sudo chown -R $(id -u -n):$(id -g -n) . build-rpms: runs-on: - self-hosted - docker:rootless steps: - name: checkout code uses: actions/checkout@v3 - name: create tarball working-directory: ${{ github.workspace }} run: | VERSION=$(cat open-vmdk.spec | grep Version | awk '{print $2}') FULL_NAME=open-vmdk-${VERSION} tar zcf v${VERSION}.tar.gz --transform "s,^,${FULL_NAME}/," $(git ls-files) - name: build RPMs working-directory: ${{ github.workspace }} run: | PWD=$(pwd) mkdir -p photon docker run --privileged --rm \ -v${PWD}/photon:/usr/src/photon \ -v${PWD}:/usr/src/photon/SOURCES \ photon/installer \ create-pkg \ -v 5.0 open-vmdk --skip-checksum -o - name: copy artifacts and create repo run: | rm -rf photon/RPMS/repodata mkdir -p ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7} cp -r photon/RPMS/ ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7}/ cp -r photon/SRPMS/ ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7}/ cd ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7} && createrepo . - name: set symlink for master run: | if [[ "${{ github.ref_name }}" == "master" ]] ; then cd ${HOME}/artifacts/open-vmdk/ && rm -f master && ln -fs ${GITHUB_SHA::7} ./master fi github-public: runs-on: self-hosted needs: - cayman_poi - poi-harness if: github.ref_name == 'master' steps: - name: Checkout code uses: actions/checkout@master with: fetch-depth: 0 - name: push to public GitHub run: | # token needs "repo, workflow" permissions git remote add github https://gerrit-photon:${{ secrets.GERRIT_PHOTON_GITHUB_TOKEN }}@github.com/vmware/open-vmdk.git || true git push github