From: Anil Belur Date: Tue, 13 Jun 2023 01:25:17 +0000 (+1000) Subject: CI: Add GHA packer validation job X-Git-Tag: v0.13.0~4 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F29%2F71829%2F1;p=releng%2Fcommon-packer.git CI: Add GHA packer validation job Issue: RELENG-4761 Change-Id: I48283360f553d4c4f1fd902e8868f6d7a86a4bd7 Signed-off-by: Anil Belur --- diff --git a/.github/workflows/gerrit-verify.yaml b/.github/workflows/gerrit-verify.yaml index 3698dfa..33cde2a 100644 --- a/.github/workflows/gerrit-verify.yaml +++ b/.github/workflows/gerrit-verify.yaml @@ -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 index 0000000..248bbf2 --- /dev/null +++ b/releasenotes/notes/add-gha-packer-validation-fcf8cef0a2110080.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add GHA packer validation job to common-packer.