enable tests #591
This file contains 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
# This GitHub action runs your tests for each commit push and/or PR. Optionally | |
# you can turn it on using a cron schedule for regular testing. | |
# | |
name: CI | |
permissions: read-all | |
on: | |
pull_request: | |
branches: | |
- main | |
- "hotfix/**" | |
paths-ignore: | |
- 'README.md' | |
push: | |
paths-ignore: | |
- 'README.md' | |
branches: | |
- main | |
- fix/read-dns-profiles | |
# Ensures only 1 action runs per PR and previous is canceled on new trigger | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
id: go | |
- name: go env | |
run: echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Build | |
run: | | |
make build | |
generate: | |
name: Test docs up-to-date | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
- run: make docs | |
- name: git diff | |
run: | | |
git diff --compact-summary --exit-code || \ | |
(echo; echo "Unexpected difference in directories after code generation. Run 'go generate ./...' command and commit."; exit 1) | |
tests-unit: | |
name: Unit Tests | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
id: go | |
- name: go env | |
run: echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Check formatting | |
timeout-minutes: 10 | |
run: | | |
make fmtcheck | |
- name: Run golangci-lint | |
timeout-minutes: 10 | |
run: | | |
make lint | |
- name: Run gosec | |
run: | | |
make sec | |
- name: Tests | |
timeout-minutes: 10 | |
run: | | |
make test | |
- name: Send coverage | |
uses: shogo82148/actions-goveralls@v1 | |
with: | |
path-to-profile: "./test_results/coverage.out" | |
flag-name: tests | |
parallel: true | |
tests-acceptance: | |
name: Matrix Acceptance Tests | |
needs: build | |
runs-on: ubuntu-latest | |
if: "!github.event.pull_request.head.repo.fork" | |
timeout-minutes: 15 | |
strategy: | |
max-parallel: 2 | |
fail-fast: false | |
matrix: | |
terraform: | |
- '1.8.*' | |
- '1.9.*' | |
- 'latest' | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
id: go | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: ${{ matrix.terraform }} | |
terraform_wrapper: false | |
- name: go env | |
run: echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Acceptance tests | |
timeout-minutes: 10 | |
env: | |
TWINGATE_URL: ${{ secrets.TWINGATE_URL }} | |
TWINGATE_NETWORK: ${{ secrets.TWINGATE_NETWORK }} | |
TWINGATE_API_TOKEN: ${{ secrets.TWINGATE_API_TOKEN }} | |
TEST_UNIQUE_VALUE: ${{ github.run_id }}-${{ github.run_number }}-${{ matrix.terraform }} | |
run: | | |
make testacc | |
- name: Send coverage | |
uses: shogo82148/actions-goveralls@v1 | |
with: | |
path-to-profile: "./test_results/coverage.out" | |
flag-name: tests-acc-${{ matrix.terraform }} | |
parallel: true | |
tests-acceptance-opentofu: | |
name: OpenTofu Matrix Acceptance Tests | |
needs: build | |
runs-on: ubuntu-latest | |
if: "!github.event.pull_request.head.repo.fork" | |
timeout-minutes: 15 | |
strategy: | |
max-parallel: 2 | |
fail-fast: false | |
matrix: | |
tofu: | |
- '1.6.*' | |
- 'latest' | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
id: go | |
- uses: opentofu/setup-opentofu@v1 | |
with: | |
tofu_version: ${{ matrix.tofu }} | |
tofu_wrapper: false | |
- name: go env | |
run: echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Acceptance tests | |
timeout-minutes: 10 | |
env: | |
TF_ACC_PROVIDER_NAMESPACE: "hashicorp" | |
TF_ACC_PROVIDER_HOST: "registry.opentofu.org" | |
TWINGATE_URL: ${{ secrets.TWINGATE_URL }} | |
TWINGATE_NETWORK: ${{ secrets.TWINGATE_NETWORK }} | |
TWINGATE_API_TOKEN: ${{ secrets.TWINGATE_API_TOKEN }} | |
TEST_UNIQUE_VALUE: ${{ github.run_id }}-${{ github.run_number }}-opentofu-${{ matrix.tofu }} | |
run: | | |
tofu version | |
export TF_ACC_TERRAFORM_PATH=$(which tofu) | |
make testacc | |
cleanup: | |
name: Cleanup | |
if: "!github.event.pull_request.head.repo.fork" | |
needs: [tests-acceptance, tests-acceptance-opentofu] | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
id: go | |
- name: go env | |
run: echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_ENV | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Run sweepers | |
timeout-minutes: 10 | |
env: | |
TWINGATE_URL: ${{ secrets.TWINGATE_URL }} | |
TWINGATE_NETWORK: ${{ secrets.TWINGATE_NETWORK }} | |
TWINGATE_API_TOKEN: ${{ secrets.TWINGATE_API_TOKEN }} | |
TEST_UNIQUE_VALUE: ${{ github.run_id }}-${{ github.run_number }} | |
run: | | |
make sweep | |
# notifies that all test jobs are finished. | |
finish: | |
name: "CI Finished" | |
needs: [tests-unit, tests-acceptance, tests-acceptance-opentofu, cleanup] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: shogo82148/actions-goveralls@v1 | |
with: | |
parallel-finished: true |