CI: Add GHA packer validation job 29/71829/1
authorAnil Belur <abelur@linuxfoundation.org>
Tue, 13 Jun 2023 01:25:17 +0000 (11:25 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 13 Jun 2023 01:28:07 +0000 (11:28 +1000)
Issue: RELENG-4761
Change-Id: I48283360f553d4c4f1fd902e8868f6d7a86a4bd7
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
.github/workflows/gerrit-verify.yaml
releasenotes/notes/add-gha-packer-validation-fcf8cef0a2110080.yaml [new file with mode: 0644]

index 3698dfa..33cde2a 100644 (file)
@@ -99,9 +99,68 @@ jobs:
         run: >-
           TOX_SKIP_ENV=pre-commit pipx run tox
 
+  packer-validation:
+    needs: prepare
+    runs-on: ubuntu-latest
+    steps:
+      - uses: lfit/checkout-gerrit-change-action@v0.3
+        with:
+          gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
+          delay: "0s"
+      - name: Setup packer
+        uses: hashicorp/setup-packer@main
+        id: setup
+        env:
+          AUTH_URL: ${{ secrets.cloud_auth_url }}
+          CLOUD_ENV: "packer/cloud-env.json"
+        with:
+          cloud_auth_url: "https://auth.vexxhost.net/v3/"
+          cloud_tenant: ${{ secrets.cloud_tenant }}
+          cloud_user: ${{ secrets.cloud_user }}
+          cloud_network: ${{ secrets.cloud_network }}
+          version: ${{ env.PACKER_VERSION }}
+          cloud_pass: ${{ secrets.cloud_pass }}
+          dicrectory: packer
+          file_name: cloud-env.json
+          fail_on_empty: true
+      - name: Clone git submodules
+        run: git submodule update --init
+      - uses: dorny/paths-filter@v2
+        id: changes
+        with:
+          filters: |
+            src:
+              - '**'
+      - if: steps.changes.outputs.src == 'true'
+        run: |
+          cd packer
+          varfiles=(vars/*.json common-packer/vars/*.json)
+          templates=(templates/*.json)
+
+          for varfile in "${varfiles[@]}"; do
+              # cloud-env.json is a file containing credentials which is pulled in via
+              # CLOUDENV variable so skip it here. Also handle the case where a project
+              # has not vars/*.json file.
+              if [[ "$varfile" == *"cloud-env.json"* ]] || [[ "$varfile" == 'vars/*.json' ]]; then
+                  continue
+              fi
+
+              echo "-----> Testing varfile: $varfile"
+              for template in "${templates[@]}"; do
+                  export PACKER_LOG="yes"
+                  export PACKER_LOG_PATH="$PACKER_LOGS_DIR/packer-validate-${varfile##*/}-${template##*/}.log"
+                  if output=$(packer validate -var-file="$CLOUDENV" -var-file="$varfile" "$template"); then
+                      echo "$template: $output"
+                  else
+                      echo "$template: $output"
+                      exit 1
+                  fi
+              done
+          done
+
   vote:
     if: ${{ always() }}
-    needs: [prepare, pre-commit, tox]
+    needs: [prepare, pre-commit, tox, packer-validation]
     runs-on: ubuntu-latest
     steps:
       - name: Get workflow conclusion
diff --git a/releasenotes/notes/add-gha-packer-validation-fcf8cef0a2110080.yaml b/releasenotes/notes/add-gha-packer-validation-fcf8cef0a2110080.yaml
new file mode 100644 (file)
index 0000000..248bbf2
--- /dev/null
@@ -0,0 +1,4 @@
+---
+features:
+  - |
+    Add GHA packer validation job to common-packer.