Skip to content

INTMDB-788: Add Code-health action #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/code-health.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 'Code Health'

on:
push:
branches:
- master
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Build
run: make build
unit-test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Unit Test
env:
MONGODB_ATLAS_TEAMS_IDS: ${{ secrets.MONGODB_ATLAS_TEAMS_IDS }}
run: make test
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: website lint
run: make tools && make website-lint
- name: actionlint
run: make tools && actionlint -verbose -color
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.52.2
args: --timeout 9m0s
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: bewuethr/shellcheck-action@v2

6 changes: 3 additions & 3 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
fetch-depth: 0
# See also: https://github.com/actions/setup-go/pull/62
- run: echo "GO_VERSION=$(cat .go-version)" >> $GITHUB_ENV
- run: echo "GO_VERSION=$(cat .go-version)" >> "${GITHUB_ENV}"
- uses: actions/setup-go@v4
with:
go-version: "1.20"
Expand All @@ -32,8 +32,8 @@ jobs:
- name: override plugin
run: |
# For newer versions
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/mongodbatlas-dev/99.99.99/$(go env GOOS)_$(go env GOARCH)/
cp terraform-plugin-dir/terraform-provider-mongodbatlas-dev_v99.99.99_x5 ~/.terraform.d/plugins/registry.terraform.io/hashicorp/mongodbatlas-dev/99.99.99/$(go env GOOS)_$(go env GOARCH)/
mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/mongodbatlas-dev/99.99.99/"$(go env GOOS)"_"$(go env GOARCH)"/
cp terraform-plugin-dir/terraform-provider-mongodbatlas-dev_v99.99.99_x5 ~/.terraform.d/plugins/registry.terraform.io/hashicorp/mongodbatlas-dev/99.99.99/"$(go env GOOS)"_"$(go env GOARCH)"/
- name: replace names of provider for local development
run: grep --include=\*.tf -rnl './examples' -e 'source = "mongodb/mongodbatlas"' | xargs sed -i s@mongodb/mongodbatlas@hashicorp/mongodbatlas-dev@g
- uses: hashicorp/setup-terraform@v2
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/golangci-lint.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
- name: Set the user terminal
run: export GPG_TTY=$(tty)
run: GPG_TTY="$(tty)" && export GPG_TTY
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
Expand Down
1 change: 1 addition & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ tools: ## Install dev tools
@echo "==> Installing dependencies..."
go install github.com/client9/misspell/cmd/misspell@latest
go install github.com/terraform-linters/[email protected]
go install github.com/rhysd/actionlint/cmd/actionlint@latest
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)

.PHONY: check
Expand Down
8 changes: 4 additions & 4 deletions mongodbatlas/resource_mongodbatlas_serverless_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ func resourceMongoDBAtlasServerlessInstanceRead(ctx context.Context, d *schema.R
if err := d.Set("connection_strings_standard_srv", serverlessInstance.ConnectionStrings.StandardSrv); err != nil {
return diag.Errorf("error setting `connection_strings_standard_srv` for serverless instance (%s): %s", d.Id(), err)
}
if len(serverlessInstance.ConnectionStrings.PrivateEndpoint) > 0 {
if err := d.Set("connection_strings_private_endpoint_srv", flattenSRVConnectionString(serverlessInstance.ConnectionStrings.PrivateEndpoint)); err != nil {
return diag.Errorf("error setting `connection_strings_private_endpoint_srv` for serverless instance (%s): %s", d.Id(), err)
}

if err := d.Set("connection_strings_private_endpoint_srv", flattenSRVConnectionString(serverlessInstance.ConnectionStrings.PrivateEndpoint)); err != nil {
return diag.Errorf("error setting `connection_strings_private_endpoint_srv` for serverless instance (%s): %s", d.Id(), err)
}

if err := d.Set("create_date", serverlessInstance.CreateDate); err != nil {
return diag.Errorf("error setting `create_date` for serverless instance (%s): %s", d.Id(), err)
}
Expand Down
17 changes: 16 additions & 1 deletion mongodbatlas/resource_mongodbatlas_serverless_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestAccClusterRSServerlessInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
resource.TestCheckResourceAttr(resourceName, "name", instanceName),
resource.TestCheckResourceAttr(resourceName, "termination_protection_enabled", "false"),
testAccCheckConnectionStringPrivateEndpointIsPresentWithNoElement(resourceName),
),
},
},
Expand Down Expand Up @@ -114,11 +115,25 @@ func testAccCheckMongoDBAtlasServerlessInstanceImportStateIDFunc(resourceName st
}

ids := decodeStateID(rs.Primary.ID)

return fmt.Sprintf("%s-%s", ids["project_id"], ids["name"]), nil
}
}

func testAccCheckConnectionStringPrivateEndpointIsPresentWithNoElement(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("not found: %s", resourceName)
}

if connectionStringPrivateEndpoint := rs.Primary.Attributes["connection_strings_private_endpoint_srv.#"]; connectionStringPrivateEndpoint == "" {
return fmt.Errorf("expected connection_strings_private_endpoint_srv to be present")
}

return nil
}
}

func testAccMongoDBAtlasServerlessInstanceConfig(projectID, name string, ignoreConnectionStrings bool) string {
lifecycle := ""

Expand Down
2 changes: 1 addition & 1 deletion scripts/changelog-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [[ ! -f CHANGELOG.md ]]; then
exit 1
fi

if [[ `uname` == "Darwin" ]]; then
if [[ $(uname) == "Darwin" ]]; then
echo "Using BSD sed"
SED="sed -i.bak -E -e"
else
Expand Down
8 changes: 4 additions & 4 deletions scripts/websitefmtcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ set -eou pipefail
npm list codedown > /dev/null 2>&1 || npm install --no-save codedown > /dev/null 2>&1

problems=false
for f in $(find website -name '*.markdown'); do
while IFS= read -r -d '' f; do
if [ "${1-}" = "diff" ]; then
echo "$f"
cat "$f" | node_modules/.bin/codedown hcl | terraform fmt -diff=true -
< "$f" node_modules/.bin/codedown hcl | terraform fmt -diff=true -
else
cat "$f" | node_modules/.bin/codedown hcl | terraform fmt -check=true - || problems=true && echo "Formatting errors in $f"
< "$f" node_modules/.bin/codedown hcl | terraform fmt -check=true - || { problems=true && echo "Formatting errors in $f"; }
fi
done
done < <(find website -name '*.markdown' -print0)
Comment on lines +8 to +15
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @martinstibbe, is this script still used? when I run make websitefmtcheck the script says that there are some markdown with formatting errors 😕
Should we run this script as part of the code-health action?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since TF registry website test stopped working as the deprecated the local site document testing if we do not call this one via a GH action may not be used golangci-lint run is in current workflows


if [ "$problems" = true ] ; then
exit 1
Expand Down