| 1 | name: open-vmdk CI |
| 2 | |
| 3 | on: [push, workflow_dispatch] |
| 4 | |
| 5 | env: |
| 6 | POI_REGISTRY: poi-registry:5000 |
| 7 | POI_IMAGE_BASE: poi-registry:5000/photon/installer:latest |
| 8 | GITHUB_BRANCH: master |
| 9 | |
| 10 | jobs: |
| 11 | build-container: |
| 12 | runs-on: self-hosted |
| 13 | steps: |
| 14 | - name: Checkout code |
| 15 | uses: actions/checkout@v3 |
| 16 | |
| 17 | - name: Build Docker image |
| 18 | run: | |
| 19 | set -e |
| 20 | POI_IMAGE_NAME=${POI_REGISTRY}/photon/installer:open-vmdk-${GITHUB_SHA::7} |
| 21 | cd docker |
| 22 | docker build -t ${POI_IMAGE_NAME} --build-context open-vmdk=$(realpath $(pwd)/..) --build-arg POI_IMAGE=$POI_IMAGE_BASE -f Dockerfile-open-vmdk-tot . |
| 23 | docker push ${POI_IMAGE_NAME} |
| 24 | docker system prune -f |
| 25 | |
| 26 | cayman_poi: |
| 27 | runs-on: self-hosted |
| 28 | steps: |
| 29 | - name: Checkout Cayman POI |
| 30 | uses: actions/checkout@master |
| 31 | with: |
| 32 | repository: vcf/cayman-poi |
| 33 | ref: vmware-master |
| 34 | path: ./cayman-poi |
| 35 | submodules: "true" |
| 36 | fetch-depth: 0 |
| 37 | ssh-key: ${{ secrets.POI_CICD_SSH_KEY }} |
| 38 | ssh-strict: "false" |
| 39 | |
| 40 | - name: create branch and push |
| 41 | run: | |
| 42 | cd ./cayman-poi |
| 43 | BRANCH_NAME=test/openvmdk-submodule/${GITHUB_SHA::7} |
| 44 | |
| 45 | if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then |
| 46 | echo "Branch $BRANCH_NAME already exists locally, switching to it" |
| 47 | git checkout "$BRANCH_NAME" |
| 48 | elif git show-ref --verify --quiet "refs/remotes/origin/$BRANCH_NAME"; then |
| 49 | echo "Branch $BRANCH_NAME exists remotely, checking it out" |
| 50 | git checkout -b "$BRANCH_NAME" "origin/$BRANCH_NAME" |
| 51 | else |
| 52 | echo "Branch $BRANCH_NAME does not exist, creating it" |
| 53 | git checkout -b "$BRANCH_NAME" |
| 54 | fi |
| 55 | |
| 56 | pushd poi/open-vmdk |
| 57 | git fetch |
| 58 | git checkout ${GITHUB_SHA::7} |
| 59 | popd |
| 60 | git add poi/open-vmdk |
| 61 | git config --global user.email "[email protected]" |
| 62 | git config --global user.name "POI CI/CD" |
| 63 | |
| 64 | # Only commit if there are changes |
| 65 | if git diff --cached --quiet; then |
| 66 | echo "No changes to commit, skipping commit step" |
| 67 | else |
| 68 | git commit -m "update poi/open-vmdk to ${GITHUB_SHA::7} for testing branch ${{ github.ref_name }}" |
| 69 | fi |
| 70 | |
| 71 | git push origin ${BRANCH_NAME} |
| 72 | |
| 73 | - name: Wait for and monitor cayman-poi workflow |
| 74 | env: |
| 75 | GITHUB_TOKEN: ${{ secrets.PAT_POI_CICD_RO }} |
| 76 | run: | |
| 77 | BRANCH_NAME="test/openvmdk-submodule/${GITHUB_SHA::7}" |
| 78 | echo "Monitoring branch: $BRANCH_NAME" |
| 79 | |
| 80 | # Function to get workflow runs for the branch |
| 81 | get_workflow_runs() { |
| 82 | curl -s \ |
| 83 | -H "Accept: application/vnd.github+json" \ |
| 84 | -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 85 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 86 | "https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs?branch=$BRANCH_NAME" \ |
| 87 | | jq -r '.workflow_runs[] | select(.head_branch == "'$BRANCH_NAME'") | "\(.id) \(.status) \(.conclusion // "null") \(.created_at)"' |
| 88 | } |
| 89 | |
| 90 | # Wait for workflow to start (up to 5 minutes) |
| 91 | echo "Waiting for workflow to start on branch $BRANCH_NAME..." |
| 92 | timeout=300 |
| 93 | interval=30 |
| 94 | elapsed=0 |
| 95 | |
| 96 | while [ $elapsed -lt $timeout ]; do |
| 97 | runs=$(get_workflow_runs) |
| 98 | if [ -n "$runs" ]; then |
| 99 | echo "Workflow detected:" |
| 100 | echo "$runs" |
| 101 | break |
| 102 | fi |
| 103 | echo "No workflow found yet, waiting ${interval}s..." |
| 104 | sleep $interval |
| 105 | elapsed=$((elapsed + interval)) |
| 106 | done |
| 107 | |
| 108 | if [ $elapsed -ge $timeout ]; then |
| 109 | echo "ERROR: No workflow was triggered within $timeout seconds" |
| 110 | exit 1 |
| 111 | fi |
| 112 | |
| 113 | # Get the workflow run ID (first field from the output) |
| 114 | run_id=$(echo "$runs" | head -1 | cut -d' ' -f1) |
| 115 | echo "Monitoring workflow run ID: $run_id" |
| 116 | |
| 117 | # Monitor workflow status (up to 1 hour) |
| 118 | timeout=3600 |
| 119 | interval=30 |
| 120 | elapsed=0 |
| 121 | |
| 122 | while [ $elapsed -lt $timeout ]; do |
| 123 | run_info=$(curl -s \ |
| 124 | -H "Accept: application/vnd.github+json" \ |
| 125 | -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 126 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 127 | "https://github-vcf.devops.broadcom.net/api/v3/repos/vcf/cayman-poi/actions/runs/$run_id") |
| 128 | |
| 129 | status=$(echo "$run_info" | jq -r '.status') |
| 130 | conclusion=$(echo "$run_info" | jq -r '.conclusion // "null"') |
| 131 | url=$(echo "$run_info" | jq -r '.html_url') |
| 132 | |
| 133 | echo "Workflow status: $status, conclusion: $conclusion" |
| 134 | |
| 135 | if [ "$status" = "completed" ]; then |
| 136 | echo "Workflow completed with conclusion: $conclusion" |
| 137 | echo "Workflow URL: $url" |
| 138 | |
| 139 | if [ "$conclusion" = "success" ]; then |
| 140 | echo "✅ Cayman POI workflow succeeded!" |
| 141 | exit 0 |
| 142 | elif [ "$conclusion" = "null" ]; then |
| 143 | echo "❌ Cayman POI workflow completed but conclusion is null" |
| 144 | echo "Check the workflow at: $url" |
| 145 | exit 1 |
| 146 | else |
| 147 | echo "❌ Cayman POI workflow failed with conclusion: $conclusion" |
| 148 | echo "Check the workflow at: $url" |
| 149 | exit 1 |
| 150 | fi |
| 151 | fi |
| 152 | |
| 153 | sleep $interval |
| 154 | elapsed=$((elapsed + interval)) |
| 155 | done |
| 156 | |
| 157 | echo "ERROR: Workflow did not complete within $timeout seconds" |
| 158 | echo "Workflow URL: $url" |
| 159 | exit 1 |
| 160 | |
| 161 | pytest: |
| 162 | runs-on: self-hosted |
| 163 | steps: |
| 164 | - name: Checkout code |
| 165 | uses: actions/checkout@v3 |
| 166 | |
| 167 | - name: pytest |
| 168 | run: | |
| 169 | set -e |
| 170 | make |
| 171 | pytest-3 pytest/ |
| 172 | |
| 173 | poi-harness: |
| 174 | runs-on: |
| 175 | - self-hosted |
| 176 | - docker:root |
| 177 | needs: build-container |
| 178 | |
| 179 | steps: |
| 180 | - name: Checkout code |
| 181 | uses: actions/checkout@master |
| 182 | |
| 183 | - name: Checkout POI Harness |
| 184 | uses: actions/checkout@master |
| 185 | with: |
| 186 | repository: vcf/photon-os-installer-harness |
| 187 | ref: main |
| 188 | path: ./poi-harness |
| 189 | ssh-key: ${{ secrets.POI_CICD_SSH_KEY }} |
| 190 | ssh-strict: false |
| 191 | |
| 192 | - name: Build OVA |
| 193 | run: | |
| 194 | set -e |
| 195 | VM_NAME=poi-open-vmdk-test-${GITHUB_SHA::7} |
| 196 | POI_IMAGE_NAME=${POI_REGISTRY}/photon/installer:open-vmdk-${GITHUB_SHA::7} |
| 197 | PHOTON_RELEASE="5.0" |
| 198 | # used by pytest |
| 199 | export VC_IP=${{ vars.VC_IP }} |
| 200 | export VC_USER=${{ vars.VC_USER }} |
| 201 | export VC_PASSWORD=${{ secrets.VC_PASSWORD }} |
| 202 | |
| 203 | mkdir harness |
| 204 | cp pytest/ks/*.yaml pytest/configs/{photon*.yaml,EULA.txt} harness/ |
| 205 | |
| 206 | cd harness |
| 207 | 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} |
| 208 | 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 |
| 209 | |
| 210 | # POI harness will deploy OVF on a VC and run tests |
| 211 | pytest ../poi-harness/ci/pytest/ -rs --deploy --ovf photon.ovf --name ${VM_NAME} --ks_config ova_ks.yaml --ova_config photon.yaml |
| 212 | |
| 213 | # create OVF using photon_configurations.yaml, re-use the vmdk: |
| 214 | 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 |
| 215 | for option in tall grande venti ; do |
| 216 | pytest ../poi-harness/ci/pytest/ -rs \ |
| 217 | --deploy --ovf photon_configurations.ovf --name ${VM_NAME}-${option} \ |
| 218 | --ks_config ova_ks.yaml --ova_config photon_configurations.yaml --deployment_option=${option}; |
| 219 | done |
| 220 | |
| 221 | sudo chown -R $(id -u -n):$(id -g -n) . |
| 222 | |
| 223 | build-rpms: |
| 224 | runs-on: |
| 225 | - self-hosted |
| 226 | - docker:rootless |
| 227 | steps: |
| 228 | - name: checkout code |
| 229 | uses: actions/checkout@v3 |
| 230 | |
| 231 | - name: create tarball |
| 232 | working-directory: ${{ github.workspace }} |
| 233 | run: | |
| 234 | VERSION=$(cat open-vmdk.spec | grep Version | awk '{print $2}') |
| 235 | FULL_NAME=open-vmdk-${VERSION} |
| 236 | tar zcf v${VERSION}.tar.gz --transform "s,^,${FULL_NAME}/," $(git ls-files) |
| 237 | |
| 238 | - name: build RPMs |
| 239 | working-directory: ${{ github.workspace }} |
| 240 | run: | |
| 241 | PWD=$(pwd) |
| 242 | mkdir -p photon |
| 243 | docker run --privileged --rm \ |
| 244 | -v${PWD}/photon:/usr/src/photon \ |
| 245 | -v${PWD}:/usr/src/photon/SOURCES \ |
| 246 | photon/installer \ |
| 247 | create-pkg \ |
| 248 | -v 5.0 open-vmdk --skip-checksum -o |
| 249 | |
| 250 | - name: copy artifacts and create repo |
| 251 | run: | |
| 252 | rm -rf photon/RPMS/repodata |
| 253 | mkdir -p ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7} |
| 254 | cp -r photon/RPMS/ ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7}/ |
| 255 | cp -r photon/SRPMS/ ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7}/ |
| 256 | cd ${HOME}/artifacts/open-vmdk/${GITHUB_SHA::7} && createrepo . |
| 257 | |
| 258 | - name: set symlink for master |
| 259 | run: | |
| 260 | if [[ "${{ github.ref_name }}" == "master" ]] ; then |
| 261 | cd ${HOME}/artifacts/open-vmdk/ && rm -f master && ln -fs ${GITHUB_SHA::7} ./master |
| 262 | fi |
| 263 | |
| 264 | github-public: |
| 265 | runs-on: self-hosted |
| 266 | needs: |
| 267 | - cayman_poi |
| 268 | - poi-harness |
| 269 | if: github.ref_name == 'master' |
| 270 | steps: |
| 271 | - name: Checkout code |
| 272 | uses: actions/checkout@master |
| 273 | with: |
| 274 | fetch-depth: 0 |
| 275 | - name: push to public GitHub |
| 276 | run: | |
| 277 | # token needs "repo, workflow" permissions |
| 278 | git remote add github https://gerrit-photon:${{ secrets.GERRIT_PHOTON_GITHUB_TOKEN }}@github.com/vmware/open-vmdk.git || true |
| 279 | git push github |