From bcd14b2314b28f8142295f305afa0a81975d7dbd Mon Sep 17 00:00:00 2001 From: Vipin Vijaykumar Date: Wed, 24 Apr 2024 21:25:53 +0530 Subject: [PATCH] chore: Workflow & Devcontainer - Add test workflow - Update devcontainer - Update Release template --- .devcontainer/default/devcontainer.json | 2 +- .devcontainer/withenvfile/devcontainer.json | 2 +- .github/release.yml | 22 +++++ .github/workflows/test.yml | 103 ++++++++++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 .github/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.devcontainer/default/devcontainer.json b/.devcontainer/default/devcontainer.json index c249519..c3b7641 100644 --- a/.devcontainer/default/devcontainer.json +++ b/.devcontainer/default/devcontainer.json @@ -1,6 +1,6 @@ { "name": "Terraform provider for Cloud Foundry - Development", - "image": "mcr.microsoft.com/devcontainers/go:1.21-bullseye", + "image": "mcr.microsoft.com/devcontainers/go:1.22-bullseye", // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/terraform:1": {}, diff --git a/.devcontainer/withenvfile/devcontainer.json b/.devcontainer/withenvfile/devcontainer.json index 26d6c50..1e02d14 100644 --- a/.devcontainer/withenvfile/devcontainer.json +++ b/.devcontainer/withenvfile/devcontainer.json @@ -1,6 +1,6 @@ { "name": "Terraform provider for Cloud Foundry - Development (with env file)", - "image": "mcr.microsoft.com/devcontainers/go:1.21-bullseye", + "image": "mcr.microsoft.com/devcontainers/go:1.22-bullseye", // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/terraform:1": {}, diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..20aafa9 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,22 @@ +changelog: + exclude: + labels: + - ignore-for-release + - github_actions + authors: + - dependabot + categories: + - title: Breaking Changes 🛠 + labels: + - Semver-Major + - breaking-change + - title: Exciting New Features 🚀 + labels: + - Semver-Minor + - enhancement + - title: Bug Fixes 🐞 + labels: + - bug + - title: Other Changes 🔩 + labels: + - "*" \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c08f51e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,103 @@ +# Terraform Provider testing workflow. +name: Terraform Provider Build Tests + +# This GitHub action runs your tests for each pull request and push. +# Optionally, you can turn it on using a schedule for regular testing. +on: + # pull_request: + # types: + # - opened + # - reopened + # - synchronize + # - ready_for_review + # paths-ignore: + # - '*.md' + # push: + # branches: + # - main + # paths-ignore: + # - '*.md' + workflow_dispatch: + workflow_call: + +# Testing only needs permissions to read the repository contents. +permissions: + contents: read + +# Define the latest Terraform version to use for upload of coverage report +env: + LATEST_VERSION: 1.8.* + +jobs: + # Ensure project builds before running testing matrix + build: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 # v4.0.0 + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version-file: 'go.mod' + cache: true + - run: go mod download + - run: go build -v . + - name: Run linters + uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v3.7.1 + with: + version: latest + + generate: + if: github.event.pull_request.draft == false + name: Docu Generation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 # v4.0.0 + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version-file: 'go.mod' + cache: true + - run: go generate ./... + - 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) + + # Run acceptance tests in a matrix with Terraform CLI versions + test_with_terraform_versions: + if: github.event.pull_request.draft == false + name: Terraform Provider Acceptance Tests + needs: build + runs-on: ubuntu-latest + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + # list whatever Terraform versions here you would like to support + terraform: + - '1.5.*' #end of security support under MPL 31 Dec 2023 + - '1.6.*' #end of security support under BSL 31 Dec 2025 + - '1.7.*' #end of security support under BSL 31 Dec 2026 + - '1.8.*' #end of security support under BSL 31 Dec 2026 + steps: + - uses: actions/checkout@v4 # v4.0.0 + - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version-file: 'go.mod' + cache: true + - uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36 # v3.0.0 + with: + terraform_version: ${{ matrix.terraform }} + terraform_wrapper: false + - run: go mod download + - env: + TF_ACC: "1" + run: go test -v -cover -coverprofile=cover.out -timeout=900s -parallel=4 ./... + timeout-minutes: 20 + - run: echo "CURRENT_TF_VERSION=${{ matrix.terraform }}" >> $GITHUB_ENV + # Upload coverage report for latest Terraform version only to avoid nameing issues in upload (see also https://github.com/actions/upload-artifact/tree/v4/?tab=readme-ov-file#breaking-changes) + - uses: actions/upload-artifact@v4 + if: ${{ env.CURRENT_TF_VERSION == env.LATEST_VERSION}} + with: + name: coverage-report + path: cover.out \ No newline at end of file