Run Tests #5501
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
name: Run Tests | |
on: | |
pull_request: | |
branches: | |
- master | |
schedule: | |
- cron: "0 1 * * *" | |
push: | |
branches: | |
- mq-working-branch-master-** | |
concurrency: | |
group: ${{ github.head_ref || github.run_id }}-test | |
cancel-in-progress: true | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
if: (github.event.action != 'closed' && github.event.pull_request.merged != true) || github.event_name == 'schedule' | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install pre-commit | |
run: python -m pip install pre-commit | |
- name: set PY | |
run: echo "PY=$(python -c 'import platform;print(platform.python_version())')" >> $GITHUB_ENV | |
- uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pre-commit | |
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} | |
- name: Run pre-commit | |
run: pre-commit run --all-files --show-diff-on-failure --color=always | |
linter-checks: | |
runs-on: ubuntu-latest | |
steps: | |
# if we don't do this, `gofmt` will want to rewrite all Go files due to bad line endings, | |
# because Git will convert all line endings to CRLF when cloning on windows | |
- name: Set Git to use Linux-style line endings | |
run: | | |
git config --global core.autocrlf false | |
git config --global core.eol lf | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.23" | |
cache: true | |
- name: Vet | |
run: make vet | |
- name: License Check | |
run: make license-check | |
- name: Check Docs Are Up To Date | |
run: make check-docs | |
test: | |
strategy: | |
matrix: | |
terraform_version: | |
- "0.14.11" | |
- "0.15.5" | |
- "1.1.2" | |
- "1.5.3" | |
platform: [ubuntu-latest] | |
runs-on: ${{ matrix.platform }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.23" | |
cache: true | |
- name: Setup terraform CLI | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_version: ${{ matrix.terraform_version }} | |
terraform_wrapper: false | |
- name: Set TF_ACC_TERRAFORM_PATH env var | |
run: echo "TF_ACC_TERRAFORM_PATH=$(which terraform)" >> $GITHUB_ENV | |
- name: Set regex for tests to run | |
shell: bash | |
run: | | |
test_re=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- datadog/*.go datadog/*/*.go datadog/internal/* go.mod go.sum | \ | |
sed 's/.*_datadog_\(.*\).*.go/\1/' | sed 's/.*\/.*\/\(.*\).*.go/\1/' | \ | |
sed -E 's+test|_++g' | \ | |
sed -e "s/\(.*\)/\\(?i\\)\1/" | \ | |
xargs | sed -e 's/ /|/g') | |
if [[ "$test_re" =~ go.mod|go.sum|provider ]] || [[ "${{ github.head_ref }}" = release/* ]] || [[ "${{ github.event_name }}" == "schedule" ]]; then | |
echo TESTARGS="-run \".*\"" >> $GITHUB_ENV | |
elif [[ ! -z "$test_re" ]]; then | |
echo TESTARGS="-run \"${test_re}\"" >> $GITHUB_ENV | |
fi | |
- name: Test | |
shell: bash | |
run: | | |
[[ -z "${TESTARGS}" ]] && echo "Skipping tests" || make testall | |
env: | |
RECORD: false | |
test-tofu: | |
runs-on: [ubuntu-latest] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.23" | |
cache: true | |
- uses: opentofu/setup-opentofu@v1 | |
with: | |
tofu_version: 1.6.1 | |
tofu_wrapper: false | |
- name: Set Terraform env vars | |
run: | | |
echo "TF_ACC_TERRAFORM_PATH=$(which tofu)" >> $GITHUB_ENV | |
echo "TF_ACC_PROVIDER_HOST=registry.opentofu.org" >> $GITHUB_ENV | |
- name: Set regex for tests to run | |
shell: bash | |
run: | | |
test_re=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -- datadog/*.go datadog/*/*.go datadog/internal/* go.mod go.sum | \ | |
sed 's/.*_datadog_\(.*\).*.go/\1/' | sed 's/.*\/.*\/\(.*\).*.go/\1/' | \ | |
sed -E 's+test|_++g' | \ | |
sed -e "s/\(.*\)/\\(?i\\)\1/" | \ | |
xargs | sed -e 's/ /|/g') | |
if [[ "$test_re" =~ go.mod|go.sum|provider ]] || [[ "${{ github.head_ref }}" = release/* ]] || [[ "${{ github.event_name }}" == "schedule" ]]; then | |
echo TESTARGS="-run \".*\"" >> $GITHUB_ENV | |
elif [[ ! -z "$test_re" ]]; then | |
echo TESTARGS="-run \"${test_re}\"" >> $GITHUB_ENV | |
fi | |
- name: Test | |
shell: bash | |
run: | | |
[[ -z "${TESTARGS}" ]] && echo "Skipping tests" || make testall | |
env: | |
RECORD: false |