From a89f32f407fc5d3a1a23d46afdb91a30c28566f8 Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Tue, 29 Oct 2024 12:05:39 -0500 Subject: [PATCH 1/2] chore: remove unused function (#807) --- equinix/provider_test.go | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/equinix/provider_test.go b/equinix/provider_test.go index a539aca3d..768ae1e3e 100644 --- a/equinix/provider_test.go +++ b/equinix/provider_test.go @@ -119,24 +119,6 @@ func TestProvider_isEmpty(t *testing.T) { } } -func TestProvider_setSchemaValueIfNotEmpty(t *testing.T) { - // given - key := "test" - s := map[string]*schema.Schema{ - key: { - Type: schema.TypeString, - Optional: true, - }, - } - var b *int = nil - d := schema.TestResourceDataRaw(t, s, make(map[string]interface{})) - // when - setSchemaValueIfNotEmpty(key, b, d) - // then - _, ok := d.GetOk(key) - assert.False(t, ok, "Key was not set") -} - // Deprecated test moved to internal/comparissons/comparisons_test.go func TestProvider_slicesMatch(t *testing.T) { // given @@ -250,10 +232,3 @@ func copyMap(source map[string]interface{}) map[string]interface{} { } return target } - -func setSchemaValueIfNotEmpty(key string, value interface{}, d *schema.ResourceData) error { - if !isEmpty(value) { - return d.Set(key, value) - } - return nil -} From fe0d4f809d47dcb588e163a36ffd884d81e316a4 Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Wed, 30 Oct 2024 09:42:51 -0500 Subject: [PATCH 2/2] chore: prevent new Go files from being added to equinix package (#808) To ensure that we continue to make progress on #106, this updates the `Validate PR` GitHub Actions Workflow to check if new Go files have been added to the `equinix/` directory. The workflow only checks for [files with `"added"` status](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files) that are directly under the `equinix/` directory. This leaves room for renaming/copying files and for adding new packages in `equinix//`. --- .github/workflows/validate_pr.yml | 65 ++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validate_pr.yml b/.github/workflows/validate_pr.yml index a10a0e2ed..4cbd74a83 100644 --- a/.github/workflows/validate_pr.yml +++ b/.github/workflows/validate_pr.yml @@ -11,7 +11,7 @@ permissions: pull-requests: write jobs: - main: + check-pr-title: name: Validate PR title runs-on: ubuntu-latest steps: @@ -43,3 +43,66 @@ jobs: with: header: pr-title-lint-error delete: true + + enforce-packages: + name: Prevent new files in `equinix` package + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + id: check_added_files + with: + result-encoding: string + retries: 3 + script: | + const files = await github.paginate(github.rest.pulls.listFiles,{ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + }) + + const blockedFiles = [] + + for (const file of files) { + if (file.status === "added" && file.filename.match(/equinix\/[^\/]*\.go/)) { + blockedFiles.push("- " + file.filename) + } + } + + var errorMessage = "" + + if (blockedFiles.length > 0) { + errorMessage = `The following files were added to the \`equinix\` package and must be moved somewhere else: + ${blockedFiles.join("\n")} + ` + core.setFailed(errorMessage) + } + + return errorMessage + + - uses: marocchino/sticky-pull-request-comment@v2 + # When the previous steps fails, the workflow would stop. By adding this + # condition you can continue the execution with the populated error message. + if: always() && (steps.check_added_files.outputs.result != '') + with: + header: files-added-to-equinix-error + message: | + We are actively working to reduce the amount of code in the `equinix` + package to avoid unintentional code sharing. + + New files should be added in an isolated package instead of adding + more code to the `equinix` package. You may need to refactor and/or + temporarily duplicate existing code in order to move your new code + to an isolated package. + + Details: + + ``` + ${{ steps.check_added_files.outputs.result }} + ``` + + # Delete a previous comment when the issue has been resolved + - if: steps.check_added_files.outputs.result == '' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: files-added-to-equinix-error + delete: true