governance - test #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: governance - test | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| CONTAINER_IMAGE: avm:test | |
| jobs: | |
| build-image: | |
| runs-on: ubuntu-latest | |
| # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | |
| permissions: | |
| contents: read | |
| environment: avm | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - uses: juliangruber/read-file-action@02bbba9876a8f870efd4ad64e3b9088d3fb94d4b # v1.1.6 | |
| id: readenv | |
| with: | |
| path: ./container/version.env | |
| - name: Create GitHub App Token | |
| id: app-token | |
| uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0 | |
| with: | |
| app-id: ${{ secrets.AVM_APP_CLIENT_ID }} | |
| private-key: ${{ secrets.AVM_APP_PRIVATE_KEY }} | |
| # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | |
| - name: Extract metadata (tags, labels) | |
| id: meta | |
| uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 | |
| with: | |
| images: | | |
| avm | |
| tags: | | |
| type=raw,value=test | |
| - name: Set up Buildx | |
| uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 | |
| with: | |
| version: latest | |
| # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | |
| # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository. | |
| # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | |
| - name: Build image | |
| id: push | |
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | |
| with: | |
| context: ./container | |
| push: false | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| ${{ steps.readenv.outputs.content }} | |
| outputs: type=docker | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| github-token: ${{ steps.app-token.outputs.token }} | |
| - name: Export image | |
| run: | | |
| echo "Exporting image to file..." | |
| docker image save --output ${{ runner.temp }}/test.tar ${{ env.CONTAINER_IMAGE }} | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: image | |
| path: ${{ runner.temp }}/test.tar | |
| retention-days: 2 | |
| - name: Run Trivy vulnerability scanner | |
| uses: aquasecurity/trivy-action@76071ef0d7ec797419534a183b498b4d6366cf37 # 0.31.0 | |
| with: | |
| image-ref: ${{ env.CONTAINER_IMAGE }} | |
| exit-code: '1' | |
| ignore-unfixed: true | |
| scanners: vuln | |
| continue-on-error: true | |
| test-governance: | |
| runs-on: ubuntu-latest | |
| needs: build-image | |
| environment: avm | |
| env: | |
| CONTAINER_PULL_POLICY: never | |
| defaults: | |
| run: | |
| working-directory: ${{ matrix.module }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| module: | |
| - tests/mock-module-azapi | |
| - tests/mock-module-azurerm | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: Download artifact | |
| uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | |
| with: | |
| name: image | |
| path: ${{ runner.temp }} | |
| - name: Load image | |
| run: | | |
| docker image load --input ${{ runner.temp }}/test.tar | |
| - name: Set env vars | |
| run: | | |
| REF=${{ github.sha }} | |
| echo "GREPT_URL=git::https://github.com/Azure/avm-terraform-governance.git//grept-policies?ref=${REF}" >> $GITHUB_ENV | |
| echo "MAKEFILE_REF=${REF}" >> $GITHUB_ENV | |
| echo "MPTF_URL=git::https://github.com/Azure/avm-terraform-governance.git//mapotf-configs?ref=${REF}" >> $GITHUB_ENV | |
| echo "PORCH_REF=${REF}" >> $GITHUB_ENV | |
| echo "TFLINT_CONFIG_URL=https://raw.githubusercontent.com/Azure/avm-terraform-governance/${REF}/tflint-configs" >> $GITHUB_ENV | |
| - name: pre-commit | |
| run: | | |
| ./avm pre-commit | |
| git status --porcelain | |
| - name: commit | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "github-actions@github.com" | |
| git checkout -b avm-test${{ github.run_id }} | |
| git add . | |
| git commit -m "avm test run ${{ github.run_id }}" | |
| - name: pr-check | |
| run: | | |
| ./avm pr-check | |
| git status --porcelain |