|
| 1 | +name: Testinfra Integration Tests |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +jobs: |
| 8 | + test-ami: |
| 9 | + strategy: |
| 10 | + matrix: |
| 11 | + include: |
| 12 | + - runner: arm-runner |
| 13 | + arch: arm64 |
| 14 | + ubuntu_release: focal |
| 15 | + ubuntu_version: 20.04 |
| 16 | + mcpu: neoverse-n1 |
| 17 | + runs-on: ${{ matrix.runner }} |
| 18 | + timeout-minutes: 150 |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + packages: write |
| 22 | + id-token: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout Repo |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - id: args |
| 29 | + uses: mikefarah/yq@master |
| 30 | + with: |
| 31 | + cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml' |
| 32 | + |
| 33 | + - run: docker context create builders |
| 34 | + |
| 35 | + - uses: docker/setup-buildx-action@v3 |
| 36 | + with: |
| 37 | + endpoint: builders |
| 38 | + |
| 39 | + - name: Build AMI stage 1 |
| 40 | + run: | |
| 41 | + packer init amazon-arm64-nix.pkr.hcl |
| 42 | + GIT_SHA=${{github.sha}} |
| 43 | + packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=" amazon-arm64-nix.pkr.hcl |
| 44 | + |
| 45 | + - name: Build AMI stage 2 |
| 46 | + run: | |
| 47 | + packer init stage2-nix-psql.pkr.hcl |
| 48 | + GIT_SHA=${{github.sha}} |
| 49 | + packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" -var "ansible_arguments=" -var "postgres-version=ci-ami-test" -var "region=ap-southeast-1" -var 'ami_regions=["ap-southeast-1"]' -var "force-deregister=true" stage2-nix-psql.pkr.hcl |
| 50 | + |
| 51 | + - name: Run tests |
| 52 | + timeout-minutes: 10 |
| 53 | + run: | |
| 54 | + # TODO: use poetry for pkg mgmt |
| 55 | + pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests |
| 56 | + pytest -vv -s testinfra/test_ami.py |
| 57 | + - name: Cleanup resources on build cancellation |
| 58 | + if: ${{ cancelled() }} |
| 59 | + run: | |
| 60 | + aws ec2 --region ap-southeast-1 describe-instances --filters "Name=tag:packerExecutionId,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -n 1 -I {} aws ec2 terminate-instances --region ap-southeast-1 --instance-ids {} |
| 61 | + - name: Cleanup resources on build cancellation |
| 62 | + if: ${{ always() }} |
| 63 | + run: | |
| 64 | + aws ec2 --region ap-southeast-1 describe-instances --filters "Name=tag:testinfra-run-id,Values=${GITHUB_RUN_ID}" --query "Reservations[].Instances[].InstanceId" --output text | xargs -n 1 -I {} aws ec2 terminate-instances --region ap-southeast-1 --instance-ids {} || true |
0 commit comments