diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml index d04d0c9..e8a5ca7 100644 --- a/.github/workflows/issues.yml +++ b/.github/workflows/issues.yml @@ -1,7 +1,6 @@ --- - name: Create JIRA ticket for new issues + name: JIRA Tickets for GH Issues - # Creates and updates jira tickets that sync with GitHub Issues events. on: issues: types: [opened, reopened, closed] diff --git a/.github/workflows/pull-request-lint.yml b/.github/workflows/pull-request-lint.yml index 3b45b59..ab2c34b 100644 --- a/.github/workflows/pull-request-lint.yml +++ b/.github/workflows/pull-request-lint.yml @@ -1,4 +1,4 @@ -name: pull-request-lint +name: PR Linters # Run validations over pull request titles while also adding appropriate labels. on: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dd9b682..b705a61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,59 @@ name: 'New Release' +run-name: 'Release ${{ inputs.version_number }}' on: workflow_dispatch: + inputs: + version_number: + description: 'Version number (e.g. v1.0.0, v1.0.0-pre, v1.0.0-pre1)' + required: true jobs: - release: + + validate-inputs: runs-on: ubuntu-latest permissions: {} steps: - - run: echo "WIP - Placeholder for release GHA" + - name: Validation of version format + run: echo "${{ inputs.version_number }}" | grep -P '^v\d+\.\d+\.\d+(-pre[A-Za-z0-9-]*)?$' + + create-tag: + needs: validate-inputs + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Get the latest commit SHA + id: get-sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + - name: Create release tag + uses: rickstaa/action-create-tag@a1c7777fcb2fee4f19b0f283ba888afa11678b72 + with: + tag: ${{ inputs.version_number }} + commit_sha: ${{ steps.get-sha.outputs.sha }} + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg_passphrase: ${{ secrets.PASSPHRASE }} + + release: + needs: create-tag + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + ref: ${{ inputs.version_number }} + fetch-depth: 0 + - name: Generate manifest files + env: + GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} + GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }} + VERSION: ${{ inputs.version_number }} + run: make generate-all-manifests + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf + with: + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index d6e4cb9..a14b41a 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,7 +1,6 @@ --- -name: 'Stale issues and PRs handler' +name: 'Stale PRs & Issues' -# Handles stale github issues and pull requests. on: workflow_dispatch: schedule: diff --git a/.gitignore b/.gitignore index ba077a4..a9d0947 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin +bin-plugin diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..d1829af --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +project_name: atlas-cli-plugin-terraform + +version: 2 + +builds: + - id: "atlas-cli-plugin-terraform" + main: ./cmd/plugin/main.go + binary: ./binary + +archives: + - files: + - src: './bin/manifest{{ if eq .Os "windows" }}.windows{{end}}.yml' + dst: ./manifest.yml + +release: + prerelease: auto diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e4dc21b..109a7bd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,11 @@ -# Contributing to Atlas CLI plugin for MongoDB Atlas Provider +# Contributing to the Atlas CLI plugin for Terraform's MongoDB Atlas Provider WIP + +## Building + +You can build the binary plugin by running `make build`. You'll need to have Go installed. Then you can run directly the generated binary `./bin/binary terraform [command]` to test your changes. + +## Using the plugin from the CLI + +You can also use the plugin with your changes from the CLI by running: `make local` and following the instructions displayed. diff --git a/GNUmakefile b/GNUmakefile deleted file mode 100644 index 7bec63d..0000000 --- a/GNUmakefile +++ /dev/null @@ -1,18 +0,0 @@ -CLI_SOURCE_FILES?=./cmd/plugin -CLI_BINARY_NAME?=binary -CLI_DESTINATION=./bin/$(CLI_BINARY_NAME) - -GOLANGCI_VERSION=v1.63.4 # Also update golangci-lint GH action in code-health.yml when updating this version - -.PHONY: build -build: - @echo "==> Building plugin binary: $(CLI_BINARY_NAME)" - go build -o $(CLI_DESTINATION) $(CLI_SOURCE_FILES) - -.PHONY: tools -tools: - @echo "==> Installing dev tools..." - go telemetry off # disable sending telemetry data, more info: https://go.dev/doc/telemetry - go install github.com/rhysd/actionlint/cmd/actionlint@latest - go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a21a543 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +CLI_SOURCE_FILES?=./cmd/plugin +CLI_BINARY_NAME?=binary +CLI_DESTINATION=./bin/$(CLI_BINARY_NAME) +MANIFEST_FILE?=./bin/manifest.yml +WIN_MANIFEST_FILE?=./bin/manifest.windows.yml + +GOLANGCI_VERSION=v1.63.4 # Also update golangci-lint GH action in code-health.yml when updating this version + +.PHONY: build +build: ## Generate the binary in ./bin + @echo "==> Building plugin binary: $(CLI_BINARY_NAME)" + go build -o $(CLI_DESTINATION) $(CLI_SOURCE_FILES) + +.PHONY: tools +tools: ## Install the dev tools (dependencies) + @echo "==> Installing dev tools..." + go telemetry off # disable sending telemetry data, more info: https://go.dev/doc/telemetry + go install github.com/rhysd/actionlint/cmd/actionlint@latest + go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION) + +.PHONY: clean +clean: ## Clean binary folders + rm -rf ./bin ./bin-plugin + +.PHONY: local +local: clean build ## Allow to run the plugin locally + @echo "==> Configuring plugin locally" + VERSION=0.0.1-local GITHUB_REPOSITORY_OWNER=owner GITHUB_REPOSITORY_NAME=repo $(MAKE) generate-manifest + @mkdir -p ./bin-plugin + cp -r ./bin ./bin-plugin/atlas-cli-plugin-terraform + @echo + @echo "==> Plugin is ready to be used locally" + @echo "run: export ATLAS_CLI_EXTRA_PLUGIN_DIRECTORY=./bin-plugin" + @echo "then this command should show the plugin: atlas plugin list" + +.PHONY: generate-all-manifests +generate-all-manifests: generate-manifest generate-manifest-windows ## Generate all the manifest files + +.PHONY: generate-manifest +generate-manifest: ## Generate the manifest file for non-windows OSes + @echo "==> Generating non-windows manifest file" + @mkdir -p ./bin + BINARY=$(CLI_BINARY_NAME) envsubst < manifest.template.yml > $(MANIFEST_FILE) + +.PHONY: generate-manifest-windows +generate-manifest-windows: ## Generate the manifest file for windows OSes + @echo "==> Generating windows manifest file" + CLI_BINARY_NAME="${CLI_BINARY_NAME}.exe" MANIFEST_FILE="$(WIN_MANIFEST_FILE)" $(MAKE) generate-manifest + +.PHONY: help +.DEFAULT_GOAL := help +help: + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | sort + diff --git a/README.md b/README.md index 9616989..84f05ed 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,27 @@ -# Atlas CLI plugin for MongoDB Atlas Provider +# Atlas CLI plugin for Terraform's MongoDB Atlas Provider [![Code Health](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/actions/workflows/code-health.yml/badge.svg)](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/actions/workflows/code-health.yml) -This repository contains the Atlas CLI plugin for MongoDB Atlas Provider. +This repository contains the Atlas CLI plugin for Terraform's MongoDB Atlas Provider. WIP + +## Installing + +Install the [Atlas CLI](https://github.com/mongodb/mongodb-atlas-cli) if you haven't done it yet. + +Install the plugin by running: +```bash +atlas plugin install github.com/mongodb-labs/atlas-cli-plugin-terraform +``` + +## Usage + + +## Contributing + +See our [CONTRIBUTING.md](CONTRIBUTING.md) guide. + +## License + +MongoDB Atlas CLI is released under the Apache 2.0 license. See [LICENSE.md](LICENSE.md) diff --git a/cmd/plugin/main.go b/cmd/plugin/main.go index 6d54162..048d0a7 100644 --- a/cmd/plugin/main.go +++ b/cmd/plugin/main.go @@ -1,7 +1,40 @@ package main -import "fmt" +import ( + "fmt" + "os" + + "github.com/mongodb-labs/atlas-cli-plugin-terraform/internal/cli/hello" + "github.com/spf13/cobra" +) func main() { - fmt.Println("WIP - Placeholder for CLI plugin entrypoint") + terraformCmd := &cobra.Command{ + Use: "terraform", + Short: "Utilities for Terraform's MongoDB Atlas Provider", + Aliases: []string{"tf"}, + } + + terraformCmd.AddCommand( + hello.Builder(), + ) + + completionOption := &cobra.CompletionOptions{ + DisableDefaultCmd: true, + DisableNoDescFlag: true, + DisableDescriptions: true, + HiddenDefaultCmd: true, + } + rootCmd := &cobra.Command{ + DisableFlagParsing: true, + DisableAutoGenTag: true, + DisableSuggestions: true, + CompletionOptions: *completionOption, + } + rootCmd.AddCommand(terraformCmd) + + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } } diff --git a/go.mod b/go.mod index 1698ba9..2010e5f 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module github.com/mongodb-labs/atlas-cli-plugin-terraform go 1.23.4 + +require github.com/spf13/cobra v1.8.1 + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..912390a --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/cli/hello/hello.go b/internal/cli/hello/hello.go new file mode 100644 index 0000000..7019f51 --- /dev/null +++ b/internal/cli/hello/hello.go @@ -0,0 +1,17 @@ +package hello + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func Builder() *cobra.Command { + return &cobra.Command{ + Use: "hello", + Short: "The Hello World command", + Run: func(_ *cobra.Command, _ []string) { + fmt.Println("Hello World, Terraform! This command will be eventually deleted.") + }, + } +} diff --git a/manifest.template.yml b/manifest.template.yml new file mode 100644 index 0000000..5406fb9 --- /dev/null +++ b/manifest.template.yml @@ -0,0 +1,12 @@ +name: atlas-cli-plugin-terraform +description: Utilities for Terraform's MongoDB Atlas Provider +version: $VERSION +github: + owner: $GITHUB_REPOSITORY_OWNER + name: $GITHUB_REPOSITORY_NAME +binary: $BINARY +commands: + terraform: + description: Utilities for Terraform's MongoDB Atlas Provider + tf: + description: Alias for the terraform command