From 99c71057792d4f9fa685f9f3304aac85a8c571f7 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Mon, 6 Feb 2023 16:39:13 -0500 Subject: [PATCH 1/6] Initial workflow testing. --- .github/workflows/acceptance-test-trigger.yml | 19 +++++++ .github/workflows/acceptance-tests.yml | 32 +++++++++++ .github/workflows/test.yml | 54 ------------------- GNUmakefile | 6 +-- 4 files changed, 54 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/acceptance-test-trigger.yml create mode 100644 .github/workflows/acceptance-tests.yml diff --git a/.github/workflows/acceptance-test-trigger.yml b/.github/workflows/acceptance-test-trigger.yml new file mode 100644 index 000000000..b2bc37b7a --- /dev/null +++ b/.github/workflows/acceptance-test-trigger.yml @@ -0,0 +1,19 @@ +name: Acceptance Test Trigger + +on: + issue_comment: + types: [created] + +jobs: + testacc-trigger: + runs-on: ubuntu-latest + + steps: + - name: Slash Command Dispatch + uses: peter-evans/slash-command-dispatch@v1 + with: + token: ${{ secrets.TRIGGER_TOKEN }} + issue-type: pull-request + commands: testacc + named-args: true + permission: write \ No newline at end of file diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml new file mode 100644 index 000000000..4d63b287a --- /dev/null +++ b/.github/workflows/acceptance-tests.yml @@ -0,0 +1,32 @@ +on: + repository_dispatch: + types: [testacc-command] + +name: Acceptance Testing + +jobs: + acceptance: + runs-on: ubuntu-latest + if: + github.event.client_payload.slash_command.sha != '' && + github.event.client_payload.slash_command.pkg != '' && + github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha + concurrency: acceptance_tests + + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + + - name: Checkout PR + uses: actions/checkout@v2 + with: + ref: ${{ github.event.client_payload.slash_command.sha }} + + - run: make PKG_NAME="${{ github.event.client_payload.slash_command.pkg }}" testacc + env: + ACCTEST_PARALLELISM: 10 + DIGITALOCEAN_TOKEN: ${{ secrets.ACCEPTANCE_TESTS_TOKEN }} + SPACES_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} + SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bf152cbae..48a50db79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,57 +35,3 @@ jobs: - name: make test run: make test - - acceptance: - # Runs the acceptance test suite using the `Acceptance Tests` environment. - # The enviroment should be configured to require reviewers approve the - # step. This allows the tests to be added as a check to PRs. - # - # This job has the `continue-on-error` set to true which prevents blocking - # PRs if the tests fail. - needs: unit - runs-on: ubuntu-latest - environment: - name: Acceptance Tests - - concurrency: acceptance_tests - - continue-on-error: true - - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.19.x - - - name: Checkout - uses: actions/checkout@v2 - - - name: make testacc - run: make testacc - env: - TESTARGS: -parallel 20 - DIGITALOCEAN_TOKEN: ${{ secrets.ACCEPTANCE_TESTS_TOKEN }} - SPACES_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} - SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} - - sweep: - runs-on: ubuntu-latest - needs: acceptance - concurrency: acceptance_tests - - steps: - - name: Install Go - uses: actions/setup-go@v2 - with: - go-version: 1.19.x - - - name: Checkout - uses: actions/checkout@v2 - - - name: make sweep - run: make sweep - env: - DIGITALOCEAN_TOKEN: ${{ secrets.ACCEPTANCE_TESTS_TOKEN }} - SPACES_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} - SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} diff --git a/GNUmakefile b/GNUmakefile index 8b045799d..14015b9b5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,8 +1,8 @@ TEST?=$$(go list ./... |grep -v 'vendor') GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor) -PKG_NAME:=digitalocean -ACCTEST_TIMEOUT:=120m -ACCTEST_PARALLELISM:=2 +PKG_NAME?=digitalocean +ACCTEST_TIMEOUT?=120m +ACCTEST_PARALLELISM?=2 default: build From 21c87b8127809ac12f327a9dd426ab68fabc54c2 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Tue, 7 Feb 2023 10:23:17 -0500 Subject: [PATCH 2/6] Allow running tests for multiple packages concurrently. --- .github/workflows/acceptance-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 4d63b287a..7ae61aa46 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -11,7 +11,8 @@ jobs: github.event.client_payload.slash_command.sha != '' && github.event.client_payload.slash_command.pkg != '' && github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha - concurrency: acceptance_tests + + concurrency: ${{ github.workflow }}-${{ github.event.client_payload.slash_command.pkg }}-${{ github.event.client_payload.pull_request.number }} steps: - name: Set up Go From 68d41385977f892ad57b293dc9856a1cbc37186d Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Tue, 7 Feb 2023 11:06:52 -0500 Subject: [PATCH 3/6] Set PR status checks. --- .github/workflows/acceptance-test-pr.yml | 69 ++++++++++++++++++++++++ .github/workflows/acceptance-tests.yml | 33 ------------ 2 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/acceptance-test-pr.yml delete mode 100644 .github/workflows/acceptance-tests.yml diff --git a/.github/workflows/acceptance-test-pr.yml b/.github/workflows/acceptance-test-pr.yml new file mode 100644 index 000000000..06b28e3cb --- /dev/null +++ b/.github/workflows/acceptance-test-pr.yml @@ -0,0 +1,69 @@ +on: + repository_dispatch: + types: [testacc-command] + +name: Acceptance Test PR + +jobs: + acceptance: + runs-on: ubuntu-latest + if: + github.event.client_payload.slash_command.sha != '' && + github.event.client_payload.slash_command.pkg != '' && + github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha + + concurrency: ${{ github.workflow }}-${{ github.event.client_payload.slash_command.pkg }}-${{ github.event.client_payload.pull_request.number }} + + steps: + - name: Set status pending + run: | + gh api --method POST -H "Accept: application/vnd.github+json" \ + /repos/${{ github.repository }}/statuses/${{ github.event.client_payload.pull_request.head.sha }} \ + -f state='pending' \ + -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ + -f description='Running acceptance tests...' \ + -f context='acceptance/${{ github.event.client_payload.slash_command.pkg }}' + env: + GH_TOKEN: ${{ github.token }} + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.19.x + + - name: Checkout PR + uses: actions/checkout@v2 + with: + ref: ${{ github.event.client_payload.slash_command.sha }} + + - name: Run Acceptance Tests + id: run_tests + run: make PKG_NAME="${{ github.event.client_payload.slash_command.pkg }}" testacc + env: + ACCTEST_PARALLELISM: 10 + DIGITALOCEAN_TOKEN: ${{ secrets.ACCEPTANCE_TESTS_TOKEN }} + SPACES_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} + SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} + + - name: Results + if: always() + run: | + if [[ ${{ steps.run_tests.outcome }} == 'success' ]]; then + echo "test_result=success" >> $GITHUB_ENV + echo "check_description=Acceptance tests for ${{ github.event.client_payload.slash_command.pkg }} successful" >> $GITHUB_ENV + else + echo "test_result=failure" >> $GITHUB_ENV + echo "check_description=Acceptance tests for ${{ github.event.client_payload.slash_command.pkg }} failed" >> $GITHUB_ENV + fi + + - name: Update status on PR + if: always() + run: | + gh api --method POST -H "Accept: application/vnd.github+json" \ + /repos/${{ github.repository }}/statuses/${{ github.event.client_payload.pull_request.head.sha }} \ + -f state='${{ env.test_result }}' \ + -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \ + -f description='${{ env.check_description }}' \ + -f context='acceptance/${{ github.event.client_payload.slash_command.pkg }}' + env: + GH_TOKEN: ${{ github.token }} \ No newline at end of file diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml deleted file mode 100644 index 7ae61aa46..000000000 --- a/.github/workflows/acceptance-tests.yml +++ /dev/null @@ -1,33 +0,0 @@ -on: - repository_dispatch: - types: [testacc-command] - -name: Acceptance Testing - -jobs: - acceptance: - runs-on: ubuntu-latest - if: - github.event.client_payload.slash_command.sha != '' && - github.event.client_payload.slash_command.pkg != '' && - github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha - - concurrency: ${{ github.workflow }}-${{ github.event.client_payload.slash_command.pkg }}-${{ github.event.client_payload.pull_request.number }} - - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.19.x - - - name: Checkout PR - uses: actions/checkout@v2 - with: - ref: ${{ github.event.client_payload.slash_command.sha }} - - - run: make PKG_NAME="${{ github.event.client_payload.slash_command.pkg }}" testacc - env: - ACCTEST_PARALLELISM: 10 - DIGITALOCEAN_TOKEN: ${{ secrets.ACCEPTANCE_TESTS_TOKEN }} - SPACES_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} - SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} From f89486e0e4b05bbbd0cfdde9d7fb5d653a026f7c Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Tue, 7 Feb 2023 11:47:24 -0500 Subject: [PATCH 4/6] Cancel pending on new run. --- .github/workflows/acceptance-test-pr.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/acceptance-test-pr.yml b/.github/workflows/acceptance-test-pr.yml index 06b28e3cb..a4065b9f0 100644 --- a/.github/workflows/acceptance-test-pr.yml +++ b/.github/workflows/acceptance-test-pr.yml @@ -12,7 +12,9 @@ jobs: github.event.client_payload.slash_command.pkg != '' && github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.sha - concurrency: ${{ github.workflow }}-${{ github.event.client_payload.slash_command.pkg }}-${{ github.event.client_payload.pull_request.number }} + concurrency: + group: ${{ github.workflow }}-${{ github.event.client_payload.slash_command.pkg }}-${{ github.event.client_payload.pull_request.number }} + cancel-in-progress: true steps: - name: Set status pending From b187e79bb498f459ccbb3329973a2c6d94c984e4 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Tue, 7 Feb 2023 13:39:59 -0500 Subject: [PATCH 5/6] Run schedualed sweeper after acceptance tests complete. --- .github/workflows/acceptance-test-schedule.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/acceptance-test-schedule.yml b/.github/workflows/acceptance-test-schedule.yml index 300d83502..2742f3ad3 100644 --- a/.github/workflows/acceptance-test-schedule.yml +++ b/.github/workflows/acceptance-test-schedule.yml @@ -16,7 +16,7 @@ jobs: - name: Install Go uses: actions/setup-go@v2 with: - go-version: 1.18.x + go-version: 1.19.x - name: Checkout uses: actions/checkout@v2 @@ -30,13 +30,15 @@ jobs: SPACES_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} sweep: + if: ${{ always() }} + needs: acceptance runs-on: ubuntu-latest steps: - name: Install Go uses: actions/setup-go@v2 with: - go-version: 1.18.x + go-version: 1.19.x - name: Checkout uses: actions/checkout@v2 From 678175723fc7138431abd0f9421c33b7a42a5644 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Tue, 7 Feb 2023 18:10:25 -0500 Subject: [PATCH 6/6] Add CONTRIBUTING.md --- CONTRIBUTING.md | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 101 +------------------------------------- 2 files changed, 127 insertions(+), 100 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..16539b2de --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,126 @@ +Developing the Provider +--------------------------- + +If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. + +To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. + +```sh +$ make build +... +$ $GOPATH/bin/terraform-provider-digitalocean +... +``` + +In order to test the provider, you can simply run `make test`. + +```sh +$ make test +``` + +In order to run the full suite of acceptance tests, run `make testacc`. + +*Note:* Acceptance tests create real resources, and often cost money to run. + +```sh +$ make testacc +``` + +In order to run a specific acceptance test, use the `TESTARGS` environment variable. For example, the following command will run `TestAccDigitalOceanDomain_Basic` acceptance test only: + +```sh +$ make testacc TESTARGS='-run=TestAccDigitalOceanDomain_Basic' +``` + +All acceptance tests for a specific package can be run by setting the `PKG_NAME` environment variable. For example: + +```sh +$ make testacc PKG_NAME=digitalocean/account +``` + +In order to check changes you made locally to the provider, you can use the binary you just compiled by adding the following +to your `~/.terraformrc` file. This is valid for Terraform 0.14+. Please see +[Terraform's documentation](https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers) +for more details. + +``` +provider_installation { + + # Use /home/developer/go/bin as an overridden package directory + # for the digitalocean/digitalocean provider. This disables the version and checksum + # verifications for this provider and forces Terraform to look for the + # digitalocean provider plugin in the given directory. + dev_overrides { + "digitalocean/digitalocean" = "/home/developer/go/bin" + } + + # For all other providers, install them directly from their origin provider + # registries as normal. If you omit this, Terraform will _only_ use + # the dev_overrides block, and so no other providers will be available. + direct {} +} +``` + +For information about writing acceptance tests, see the main Terraform [contributing guide](https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md#writing-acceptance-tests). + +Releasing the Provider +---------------------- + +To release the provider: + +1. Use + [github-changelog-generator](https://github.com/digitalocean/github-changelog-generator) + to list the changes since the last release and decide what kind of release + you are doing (bugfix, feature or breaking). +1. Create a new commit that only contains updates to + [CHANGELOG.md](CHANGELOG.md) listing the respective changes for the new + version. Godo follows [semver](https://www.semver.org/) versioning + semantics. +1. Once the CHANGELOG.md commit is merged, create a new tag on that commit with + the new version that will be released (be sure to pull the latest from + git). + + ```bash + git tag -m "release $new_version" -a "$new_version" + ``` + +1. Push the tag: + + ```bash + git push "$origin" tag "$new_version" + ``` + +This repository contains a GitHub Action configured to automatically build and +publish assets for release when a tag is pushed that matches the pattern `v*` +(ie. `v0.1.0`). + +A [Goreleaser](https://goreleaser.com/) configuration is provided that produces +build artifacts matching the [layout required](https://www.terraform.io/docs/registry/providers/publishing.html#manually-preparing-a-release) +to publish the provider in the Terraform Registry. + +Releases will appear as drafts. Once marked as published on the GitHub Releases page, +they will become available via the Terraform Registry. + +Reviewing Pull Requests +----------------------- + +Acceptance tests use the production API and create resources that incur costs. +Running the full suite of acceptance tests can also take quite a long time to run. +In order to prevent misuse, the acceptance tests for a pull request must be manually +triggered by a reviewer with write access to the repository. + +To trigger a run of the acceptance tests for a PR, you may use the `/testacc` in a +comment. The `pkg` and `sha` arguments are required. This allows us to limit the +packages being tested for quick feedback and protect against timing attacks. +For example, to run the acceptance tests for the `droplet` package, the command +may look like: + + /testacc pkg=digitalocean/droplet sha=d358bd2418b4e30d7bdf2b98b4c151e357814c63 + +To run the entire suite, use `pkg=digitalocean`. + +If multiple packages are to be tested, each command must be posted as a separate +comment. Only the first line of the comment is evaluated. + +We leverage the [`peter-evans/slash-command-dispatch`](https://github.com/peter-evans/slash-command-dispatch) +GitHub Action for the command processing. diff --git a/README.md b/README.md index 38de0564b..a03e9b3e9 100644 --- a/README.md +++ b/README.md @@ -34,103 +34,4 @@ See the [DigitalOcean Provider documentation](https://registry.terraform.io/prov Developing the Provider --------------------------- -If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (version 1.11+ is *required*). You'll also need to correctly setup a [GOPATH](http://golang.org/doc/code.html#GOPATH), as well as adding `$GOPATH/bin` to your `$PATH`. - -To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory. - -```sh -$ make build -... -$ $GOPATH/bin/terraform-provider-digitalocean -... -``` - -In order to test the provider, you can simply run `make test`. - -```sh -$ make test -``` - -In order to run the full suite of acceptance tests, run `make testacc`. - -*Note:* Acceptance tests create real resources, and often cost money to run. - -```sh -$ make testacc -``` - -In order to run a specific acceptance test, use the `TESTARGS` environment variable. For example, the following command will run `TestAccDigitalOceanDomain_Basic` acceptance test only: - -```sh -$ make testacc TESTARGS='-run=TestAccDigitalOceanDomain_Basic' -``` - -All acceptance tests for a specific package can be run by setting the `PKG_NAME` environment variable. For example: - -```sh -$ make testacc PKG_NAME=digitalocean/account -``` - -In order to check changes you made locally to the provider, you can use the binary you just compiled by adding the following -to your `~/.terraformrc` file. This is valid for Terraform 0.14+. Please see -[Terraform's documentation](https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers) -for more details. - -``` -provider_installation { - - # Use /home/developer/go/bin as an overridden package directory - # for the digitalocean/digitalocean provider. This disables the version and checksum - # verifications for this provider and forces Terraform to look for the - # digitalocean provider plugin in the given directory. - dev_overrides { - "digitalocean/digitalocean" = "/home/developer/go/bin" - } - - # For all other providers, install them directly from their origin provider - # registries as normal. If you omit this, Terraform will _only_ use - # the dev_overrides block, and so no other providers will be available. - direct {} -} -``` - -For information about writing acceptance tests, see the main Terraform [contributing guide](https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md#writing-acceptance-tests). - -Releasing the Provider ----------------------- - -To release the provider: - -1. Use - [github-changelog-generator](https://github.com/digitalocean/github-changelog-generator) - to list the changes since the last release and decide what kind of release - you are doing (bugfix, feature or breaking). -1. Create a new commit that only contains updates to - [CHANGELOG.md](CHANGELOG.md) listing the respective changes for the new - version. Godo follows [semver](https://www.semver.org/) versioning - semantics. -1. Once the CHANGELOG.md commit is merged, create a new tag on that commit with - the new version that will be released (be sure to pull the latest from - git). - - ```bash - git tag -m "release $new_version" -a "$new_version" - ``` - -1. Push the tag: - - ```bash - git push "$origin" tag "$new_version" - ``` - -This repository contains a GitHub Action configured to automatically build and -publish assets for release when a tag is pushed that matches the pattern `v*` -(ie. `v0.1.0`). - -A [Goreleaser](https://goreleaser.com/) configuration is provided that produces -build artifacts matching the [layout required](https://www.terraform.io/docs/registry/providers/publishing.html#manually-preparing-a-release) -to publish the provider in the Terraform Registry. - -Releases will appear as drafts. Once marked as published on the GitHub Releases page, -they will become available via the Terraform Registry. - +See [CONTRIBUTING.md](./CONTRIBUTING.md) for information about contributing to this project.