Skip to content

GitHub Action: Self-Test #39

GitHub Action: Self-Test

GitHub Action: Self-Test #39

name: "GitHub Action: Self-Test"
# run once a week on Sunday at midnight
on:
schedule:
- cron: "0 0 * * 0"
workflow_dispatch:
jobs:
test-action:
runs-on: ubuntu-latest
environment:
name: ${{ matrix.environment }}
strategy:
matrix:
environment: [
prod,
qa
]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test Action
id: test-action
uses: "./"
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: "us-west-2"
build: "amazon-ebs.ubuntu-example"
instance-type: "t3.micro"
packer-directory: "./example"
subnet-id: ${{ vars.SUBNET_ID }}
vpc-id: ${{ vars.VPC_ID }}
var-file: "./ubuntu-18.04.pkrvars.hcl"
- name: Clean Up AMIs
env:
AMI_ID: ${{ steps.test-action.outputs.ami-id }}
run: |
aws ec2 deregister-image \
--image-id $AMI_ID \
--region us-west-2
test-packer:
runs-on: ubuntu-latest
environment:
name: ${{ matrix.environment }}
strategy:
matrix:
environment: [
prod,
qa
]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Packer
uses: hashicorp/setup-packer@v3.0.0
with:
version: '1.7'
- name: Install Terratest Log Parser
working-directory: ./test
run: |
curl --location --silent --fail --show-error -o terratest_log_parser \
https://github.com/gruntwork-io/terratest/releases/download/v0.13.13/terratest_log_parser_linux_amd64
chmod +x terratest_log_parser
sudo mv terratest_log_parser /usr/local/bin
- name: Test Packer
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: "us-west-2"
SUBNET_ID: ${{ vars.SUBNET_ID }}
VPC_ID: ${{ vars.VPC_ID }}
working-directory: ./test
run: |
echo "Testing Packer..."
# Output the subnet and vpc ids
echo "Subnet ID: $PKR_VAR_subnet_id"
echo "VPC ID: $PKR_VAR_vpc_id"
go test -v -timeout 30m | tee test_output.log
terratest_log_parser -testlog test_output.log -outputdir test_output
- name: Parse Test Logs
working-directory: ./test
run: terratest_log_parser -testlog test_output.log -outputdir test_output
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: test/test_output/**/*.xml