-
Notifications
You must be signed in to change notification settings - Fork 1
chore: Initial plugin command #7
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
Changes from all commits
2e4ba72
0a904be
11463cd
9d23433
6c8259d
515759b
230137a
29462a9
ec30261
0e0d334
501fceb
4c33e17
8764e63
cec28f0
8a38100
48a88d1
89ae61b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
bin | ||
bin-plugin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
jeroenvervaeke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dst: ./manifest.yml | ||
|
||
release: | ||
prerelease: auto |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
EspenAlbert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## 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. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
CLI_SOURCE_FILES?=./cmd/plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using Makefile instead of GNUmakefile as we don't need specific features |
||
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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. local make target |
||
.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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
# Atlas CLI plugin for MongoDB Atlas Provider | ||
# Atlas CLI plugin for Terraform's MongoDB Atlas Provider | ||
|
||
[](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 | ||
|
||
EspenAlbert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## 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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why these options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using the same defaults as in example and kubernetes plugins |
||
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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
}, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: atlas-cli-plugin-terraform | ||
description: Utilities for Terraform's MongoDB Atlas Provider | ||
version: $VERSION | ||
github: | ||
owner: $GITHUB_REPOSITORY_OWNER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice usage of env-vars |
||
name: $GITHUB_REPOSITORY_NAME | ||
binary: $BINARY | ||
commands: | ||
terraform: | ||
description: Utilities for Terraform's MongoDB Atlas Provider | ||
tf: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love the shorthand option |
||
description: Alias for the terraform command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common naming convention for GH actions