Skip to content

Commit

Permalink
test: Improve GitHub Actions workflow for Terraform testing
Browse files Browse the repository at this point in the history
Major changes:
- Change from pull_request_target to pull_request to ensure tests run with PR's workflow version
- Update checkout action from v2.3.3 to v4 for better security and performance
- Add max-parallel: 1 to matrix strategy to run Terraform version tests sequentially
- Update Terraform versions to test against:
 - Remove '0.13.7'
 - Add '0.14.11' and '1.5.3'
- Clean up workflow structure and naming for better clarity
 - Rename job from "Matrix Test" to "Test Terraform {version}"
 - Remove redundant comments
 - Consistent formatting throughout the file

These changes ensure tests run sequentially for each Terraform version while
maintaining the ability to easily add/remove versions through the matrix config.
The workflow now runs more reliably and uses the correct version from PR branches.
  • Loading branch information
Shani Erman authored and Shani Erman committed Feb 12, 2025
1 parent 6a848ce commit f501591
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
name: Tests
on:
pull_request_target:
pull_request:
types: [labeled]
paths-ignore:
- 'README.md'
Expand All @@ -17,22 +17,20 @@ on:
# schedule:
# - cron: '0 13 * * *'
jobs:
# ensure the code builds...
build:
if: contains(github.event.pull_request.labels.*.name, 'safe_to_test')
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
steps:

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.18'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2.3.3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

Expand All @@ -44,46 +42,47 @@ jobs:
run: |
go build -v .
# run acceptance tests in a matrix with Terraform core versions
test:
if: contains(github.event.pull_request.labels.*.name, 'safe_to_test')
name: Matrix Test
needs: build
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
max-parallel: 1 # This makes jobs run sequentially
fail-fast: false
matrix:
# list whatever Terraform versions here you would like to support
terraform:
- '0.15.5'
- '0.13.7'
- '1.1.2'
terraform: [
'0.15.5',
'0.14.11',
'1.1.2',
'1.5.3'
]
name: Test Terraform ${{ matrix.terraform }}
steps:

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.18'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2.3.3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Get dependencies
run: |
go mod download
- name: TF acceptance tests
- name: Run TF acceptance tests
uses: nick-fields/retry@v2
with:
max_attempts: 2
timeout_minutes: 15
command: go test -v -cover ./aquasec/ -timeout 15m
env:
TF_ACC: "1"
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }}
AQUA_URL: ${{ secrets.AQUA_URL }}
AQUA_USER: ${{ secrets.AQUA_USER }}
AQUA_PASSWORD: ${{ secrets.AQUA_PASSWORD }}
with:
max_attempts: 2
timeout_minutes: 15
command: go test -v -cover ./aquasec/ -timeout 15m
Binary file removed terraform-provider-aquasec
Binary file not shown.

0 comments on commit f501591

Please sign in to comment.