diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 9f0f755..4e5335f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,115 +6,93 @@ on: - master pull_request: +env: + GO_VERSION: "1.15" + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + jobs: - linux: + build: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go + - name: Checkout + uses: actions/checkout@v2 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} - - name: Build binary - run: make build + - name: Build binary + run: make build - darwin: + test: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go + - name: Checkout + uses: actions/checkout@v2 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} - - name: Build binary - env: - GOOS: darwin - GOARCH: amd64 - run: make build + - name: Run tests + run: make test - freebsd: + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.out + + validate: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go + - name: Checkout + uses: actions/checkout@v2 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} - - name: Build binary - env: - GOOS: freebsd - GOARCH: amd64 - run: make build + - name: Verify dependencies + run: make verify - openbsd: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go + - name: Check formatting + run: make goimports checkfmt - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Run linters + run: make golangci lint - - name: Build binary - env: - GOOS: openbsd - GOARCH: amd64 - run: make build - - windows: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Build binary - env: - GOOS: windows - GOARCH: amd64 - run: make build + - name: Run Staticcheck + run: make staticcheck docker: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - name: Build 'dev' Docker image - if: "!contains(github.ref, 'refs/heads/master')" - run: DOCKER_TAG=${{ github.sha }} make docker + - name: Login to Docker + uses: docker/login-action@v1 + if: env.REGISTRY_USERNAME != '' + with: + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build and push 'edge' Docker image - if: "contains(github.ref, 'refs/heads/master')" - run: | - echo ${REGISTRY_PASSWORD} | docker login -u ${REGISTRY_USERNAME} --password-stdin quay.io - DOCKER_TAG=edge make docker push - env: - REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} - REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + - name: Build 'dev' Docker image + if: "env.REGISTRY_USERNAME != '' && !contains(github.ref, 'refs/heads/master')" + run: make docker + env: + DOCKER_TAG: ${{ github.sha }} + + - name: Build and push 'edge' Docker image + if: env.REGISTRY_USERNAME != '' && contains(github.ref, 'refs/heads/master') + run: make docker push + env: + DOCKER_TAG: edge diff --git a/.github/workflows/prerelease.yaml b/.github/workflows/prerelease.yaml index 8053869..b268ce5 100644 --- a/.github/workflows/prerelease.yaml +++ b/.github/workflows/prerelease.yaml @@ -3,52 +3,67 @@ name: prerelease on: push: tags: - - 'v*.*.*-*' + - "v*.*.*-*" + +env: + GO_VERSION: "1.15" + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} jobs: prerelease: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} - - name: Build binaries for all OS/ARCH platforms - run: | - export PATH=$PATH:$(go env GOPATH)/bin - make gox build-all + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + if: env.REGISTRY_USERNAME != '' + with: + version: latest + args: release --rm-dist --skip-publish --skip-sign - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: bin/terraform-docs-v* - draft: false - prerelease: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: dist/terraform-docs-v* + draft: false + prerelease: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} docker: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 - - name: Set version output - id: vars - run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v' + - name: Set version output + id: vars + run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v' - - name: Build and push Docker image - run: | - echo ${REGISTRY_PASSWORD} | docker login -u ${REGISTRY_USERNAME} --password-stdin quay.io - DOCKER_TAG=${{ steps.vars.outputs.tag }} make docker push - env: - REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} - REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + - name: Login to Docker + uses: docker/login-action@v1 + if: env.REGISTRY_USERNAME != '' + with: + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build and push Docker image + run: make docker push + env: + DOCKER_TAG: ${{ steps.vars.outputs.tag }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index a5903dd..e60d901 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,63 +3,62 @@ name: release on: push: tags: - - 'v*.*.*' - - '!v*.*.*-*' + - "v*.*.*" + - "!v*.*.*-*" + +env: + GO_VERSION: "1.15" + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} jobs: - release: + assets: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} - - name: Build binaries for all OS/ARCH platforms - run: | - export PATH=$PATH:$(go env GOPATH)/bin - make gox build-all + - name: Login to Docker + uses: docker/login-action@v1 + if: env.REGISTRY_USERNAME != '' + with: + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Generate Changelog - run: | - export PATH=$PATH:$(go env GOPATH)/bin - ./scripts/release/release-note.sh + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + if: env.REGISTRY_USERNAME != '' + with: + version: latest + args: release --rm-dist --skip-sign + env: + GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }} - - name: Release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - body_path: CURRENT-RELEASE-CHANGELOG.md - files: bin/terraform-docs-v* - draft: false - prerelease: false - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Set version output + id: vars + run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v' - docker: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v2 + - name: Update Chocolatey package + run: ./scripts/release/update-choco.sh "${{ env.GITHUB_REF }}" - - name: Set version output - id: vars - run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v' - - - name: Build and push Docker image - run: | - echo ${REGISTRY_PASSWORD} | docker login -u ${REGISTRY_USERNAME} --password-stdin quay.io - DOCKER_TAG=${{ steps.vars.outputs.tag }} make docker push - DOCKER_TAG=latest make docker push - env: - REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} - REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + - name: Update Chocolatey package + uses: drud/action-cross-commit@master + with: + source-folder: scripts/release/chocolatey-package + destination-repository: https://${{ secrets.COMMITTER_USERNAME }}:${{ secrets.COMMITTER_TOKEN }}@github.com/terraform-docs/chocolatey-package + destination-folder: . + destination-branch: main + git-user: ${{ secrets.COMMITTER_USERNAME }} + git-user-email: ${{ secrets.COMMITTER_EMAIL }} + git-commit-message: Chocolatey update for terraform-docs version v${{ env.GITHUB_REF }} + excludes: README.md:LICENSE:.git:.github homebrew: runs-on: ubuntu-latest diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml deleted file mode 100644 index 3f39830..0000000 --- a/.github/workflows/validate.yaml +++ /dev/null @@ -1,98 +0,0 @@ -name: validate - -on: - push: - branches: - - master - pull_request: - -jobs: - verify: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Verify 'vendor' dependencies - run: make verify - - checkfmt: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Check formatting of go files - run: | - export PATH=$PATH:$(go env GOPATH)/bin - make goimports checkfmt - - lint: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Run linters - run: | - export PATH=$PATH:$(go env GOPATH)/bin - make golangci lint - - staticcheck: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Run staticcheck - run: make staticcheck - - test: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.15.6 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Run tests - run: make test - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - if: always() - with: - file: ./coverage.out diff --git a/.gitignore b/.gitignore index 2d9fad7..4582eeb 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ coverage.txt # ignore asdf local versions /.tool-versions + +# goreleaser +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..23b6c86 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,89 @@ +project_name: terraform-docs + +builds: + - main: . + env: + - CGO_ENABLED=0 + ldflags: + - -s -w + - -X github.com/terraform-docs/terraform-docs/internal/version.version={{ .Version }} + - -X github.com/terraform-docs/terraform-docs/internal/version.commitHash={{ .ShortCommit }} + - -X github.com/terraform-docs/terraform-docs/internal/version.buildDate={{ .Date }} + goos: + - darwin + - linux + - freebsd + - windows + goarch: + - amd64 + - arm + goarm: + - 7 + ignore: + - goos: darwin + goarch: arm + - goos: windows + goarch: arm + +archives: + - format: tar.gz + name_template: "{{ .Binary }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}" + format_overrides: + - goos: windows + format: zip + files: + - LICENSE + - README.md + - format: binary + id: deprecated + name_template: "{{ .Binary }}-{{ .Tag }}-{{ .Os }}-{{ .Arch }}" + +checksum: + name_template: "{{ .ProjectName }}-{{ .Tag }}.sha256sum" + +snapshot: + name_template: "{{ .Tag }}-dev" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +dockers: + - dockerfile: scripts/release/Dockerfile + image_templates: + - "quay.io/terraform-docs/terraform-docs:latest" + - "quay.io/terraform-docs/terraform-docs:{{ .RawVersion }}" + +brews: + - tap: + owner: terraform-docs + name: homebrew-tap + commit_author: + name: terraform-docs-bot + email: bot@terraform-docs.io + url_template: "https://github.com/terraform-docs/terraform-docs/releases/download/{{ .Tag }}/{{ .ArtifactName }}" + homepage: "https://github.com/terraform-docs/" + description: "Generate documentation from Terraform modules in various output formats" + test: | + system "#{bin}/terraform-docs version" + +scoop: + bucket: + owner: terraform-docs + name: scoop-bucket + commit_author: + name: terraform-docs-bot + email: bot@terraform-docs.io + commit_msg_template: "Scoop update for {{ .ProjectName }} version {{ .Tag }}" + url_template: "https://github.com/terraform-docs/terraform-docs/releases/download/{{ .Tag }}/{{ .ArtifactName }}" + homepage: "https://github.com/terraform-docs/" + description: "Generate documentation from Terraform modules in various output formats" + license: MIT + +# Uncomment these lines if you want to experiment with other +# parts of the release process without releasing new binaries. +# release: +# disable: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a2a1678..6934831 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ us on [Slack]. For releasing: -- [gox] +- [goreleaser] - [git-chlog] You can install all the required tools with `make tools` or individually with @@ -81,7 +81,7 @@ to review and accept. [Go]: https://golang.org/ [goimports]: https://pkg.go.dev/golang.org/x/tools/cmd/goimports [golangci-lint]: https://github.com/golangci/golangci-lint -[gox]: https://github.com/mitchellh/gox +[goreleaser]: https://goreleaser.com/ [git-chlog]: https://github.com/terraform-docs/git-chglog [good git commit hygiene]: https://www.futurelearn.com/info/blog/telling-stories-with-your-git-history [Developer Certificate of Origin]: https://github.com/apps/dco diff --git a/Makefile b/Makefile index fe43835..acf40d0 100644 --- a/Makefile +++ b/Makefile @@ -7,40 +7,36 @@ # the root directory of this source tree. # Project variables -NAME := terraform-docs -VENDOR := terraform-docs -DESCRIPTION := generate documentation from Terraform modules in various output formats -URL := https://github.com/$(VENDOR)/$(NAME) -LICENSE := MIT - -# Repository variables -PACKAGE := github.com/$(VENDOR)/$(NAME) +PROJECT_NAME := terraform-docs +PROJECT_OWNER := terraform-docs +DESCRIPTION := generate documentation from Terraform modules in various output formats +PROJECT_URL := https://github.com/$(PROJECT_OWNER)/$(PROJECT_NAME) +LICENSE := MIT # Build variables BUILD_DIR := bin COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null) BUILD_DATE ?= $(shell date +%FT%T%z) -VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.0-$(COMMIT_HASH)") +CUR_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.0-$(COMMIT_HASH)") COVERAGE_OUT := coverage.out # Go variables +GO_PACKAGE := github.com/$(PROJECT_OWNER)/$(PROJECT_NAME) GOOS ?= $(shell go env GOOS) GOARCH ?= $(shell go env GOARCH) -GOLDFLAGS :=" -GOLDFLAGS += -X $(PACKAGE)/internal/version.version=$(VERSION) -GOLDFLAGS += -X $(PACKAGE)/internal/version.commitHash=$(COMMIT_HASH) -GOLDFLAGS += -X $(PACKAGE)/internal/version.buildDate=$(BUILD_DATE) -GOLDFLAGS +=" +GOLDFLAGS += -X $(GO_PACKAGE)/internal/version.version=$(CUR_VERSION) +GOLDFLAGS += -X $(GO_PACKAGE)/internal/version.commitHash=$(COMMIT_HASH) +GOLDFLAGS += -X $(GO_PACKAGE)/internal/version.buildDate=$(BUILD_DATE) -GOBUILD ?= CGO_ENABLED=0 go build -ldflags $(GOLDFLAGS) +GOBUILD ?= CGO_ENABLED=0 go build -ldflags="$(GOLDFLAGS)" GORUN ?= GOOS=$(GOOS) GOARCH=$(GOARCH) go run GOIMPORTS_LOCAL_ARG := -local github.com/terraform-docs # Docker variables -DEFAULT_TAG ?= $(shell echo "$(VERSION)" | tr -d 'v') -DOCKER_IMAGE := quay.io/$(VENDOR)/$(NAME) +DEFAULT_TAG ?= $(shell echo "$(CUR_VERSION)" | tr -d 'v') +DOCKER_IMAGE := quay.io/$(PROJECT_OWNER)/$(PROJECT_NAME) DOCKER_TAG ?= $(DEFAULT_TAG) # Binary versions @@ -98,14 +94,7 @@ deps: .PHONY: build build: clean ## Build binary for current OS/ARCH @ $(MAKE) --no-print-directory log-$@ - $(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(NAME) - -.PHONY: build-all -build-all: GOOS = linux darwin windows freebsd -build-all: GOARCH = amd64 arm -build-all: clean ## Build binary for all OS/ARCH - @ $(MAKE) --no-print-directory log-$@ - @ ./scripts/build/build-all-osarch.sh "$(BUILD_DIR)" "$(NAME)" "$(VERSION)" "$(GOOS)" "$(GOARCH)" $(GOLDFLAGS) + $(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(PROJECT_NAME) .PHONY: docker docker: ## Build Docker image @@ -131,10 +120,10 @@ PATTERN = # cycle release. For example if latest tag is v0.8.0-rc.2 and v0.8.0 GA needs to get # released the following should be executed: "make release version=0.8.0" .PHONY: release -release: version ?= $(shell echo $(VERSION) | sed 's/^v//' | awk -F'[ .]' '{print $(PATTERN)}') +release: VERSION ?= $(shell echo $(CUR_VERSION) | sed 's/^v//' | awk -F'[ .]' '{print $(PATTERN)}') release: ## Prepare release @ $(MAKE) --no-print-directory log-$@ - @ ./scripts/release/release.sh "$(version)" "$(VERSION)" "1" + @ ./scripts/release/release.sh "$(VERSION)" "$(CUR_VERSION)" "1" .PHONY: patch patch: PATTERN = '\$$1\".\"\$$2\".\"\$$3+1' @@ -182,16 +171,10 @@ ifeq (, $(shell which golangci-lint)) curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION) endif -.PHONY: gox -gox: -ifeq (, $(shell which gox)) - GO111MODULE=off go get -u github.com/mitchellh/gox -endif - .PHONY: tools tools: ## Install required tools @ $(MAKE) --no-print-directory log-$@ - @ $(MAKE) --no-print-directory git-chglog goimports golangci gox + @ $(MAKE) --no-print-directory git-chglog goimports golangci ######################################################################## ## Self-Documenting Makefile Help ## diff --git a/README.md b/README.md index 2b72f9b..144e49f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A utility to generate documentation from Terraform modules in various output formats. -``` bash +```bash terraform-docs asciidoc ./my-terraform-module # generate asciidoc table terraform-docs asciidoc table ./my-terraform-module # generate asciidoc table terraform-docs asciidoc document ./my-terraform-module # generate asciidoc document @@ -27,13 +27,13 @@ terraform-docs yaml ./my-terraform-module # generate yaml ## Documentation - **Users** - - Read the [User Guide](./docs/USER_GUIDE.md) to learn how to use terraform-docs - - Read the [Formats Guide](./docs/FORMATS_GUIDE.md) to learn about different output formats of terraform-docs - - Refer to [Config File Reference](./docs/CONFIG_FILE.md) for all the available configuration options + - Read the [User Guide] to learn how to use terraform-docs + - Read the [Formats Guide] to learn about different output formats of terraform-docs + - Refer to [Config File Reference] for all the available configuration options - **Developers** - - Read [Contributing Guide](CONTRIBUTING.md) before submitting a pull request + - Read [Contributing Guide] before submitting a pull request -Visit [./docs](./docs/) for all documentation. +Visit [docs] folder for all documentation. ## Installation @@ -43,7 +43,8 @@ The latest version can be installed using `go get`: GO111MODULE="on" go get github.com/terraform-docs/terraform-docs@v0.10.1 ``` -**NOTE:** to download any version **before** `v0.9.1` (inclusive) you need to use to old module namespace (`segmentio`): +**NOTE:** to download any version **before** `v0.9.1` (inclusive) you need to use to +old module namespace (`segmentio`): ```bash # only for v0.9.1 and before @@ -52,30 +53,48 @@ GO111MODULE="on" go get github.com/segmentio/terraform-docs@v0.9.1 **NOTE:** please use the latest go to do this, we use 1.15.6 but ideally go 1.14 or greater. -This will put `terraform-docs` in `$(go env GOPATH)/bin`. If you encounter the error `terraform-docs: command not found` after installation then you may need to either add that directory to your `$PATH` as shown [here](https://golang.org/doc/code.html#GOPATH) or do a manual installation by cloning the repo and run `make build` from the repository which will put `terraform-docs` in: +This will put `terraform-docs` in `$(go env GOPATH)/bin`. If you encounter the error +`terraform-docs: command not found` after installation then you may need to either add +that directory to your `$PATH` as shown [here] or do a manual installation by cloning +the repo and run `make build` from the repository which will put `terraform-docs` in: ```bash $(go env GOPATH)/src/github.com/terraform-docs/terraform-docs/bin/$(uname | tr '[:upper:]' '[:lower:]')-amd64/terraform-docs ``` -Stable binaries are also available on the [releases](https://github.com/terraform-docs/terraform-docs/releases) page. To install, download the binary for your platform from "Assets" and place this into your `$PATH`: + +Stable binaries are also available on the [releases] page. To install, download the +binary for your platform from "Assets" and place this into your `$PATH`: ```bash -curl -Lo ./terraform-docs https://github.com/terraform-docs/terraform-docs/releases/download/v0.10.1/terraform-docs-v0.10.1-$(uname | tr '[:upper:]' '[:lower:]')-amd64 +curl -Lo ./terraform-docs https://github.com/terraform-docs/terraform-docs/releases/download/v0.10.1/terraform-docs-v0.10.1-$(uname)-amd64 chmod +x ./terraform-docs mv ./terraform-docs /some-dir-in-your-PATH/terraform-docs ``` **NOTE:** Windows releases are in `EXE` format. -If you are a Mac OS X user, you can use [Homebrew](https://brew.sh): +If you are a Mac OS X user, you can use [Homebrew]: -``` bash +```bash brew install terraform-docs ``` -Windows users can install using [Chocolatey](https://www.chocolatey.org): +or -``` bash +```bash +brew install terraform-docs/tap/terraform-docs +``` + +Windows users can install using [Scoop]: + +```bash +scoop bucket add terraform-docs https://github.com/terraform-docs/scoop-bucket +scoop install terraform-docs +``` + +or [Chocolatey]: + +```bash choco install terraform-docs ``` @@ -85,16 +104,38 @@ Alternatively you also can run `terraform-docs` as a container: docker run quay.io/terraform-docs/terraform-docs:0.10.1 ``` -**NOTE:** Docker tag `latest` refers to _latest_ stable released version and `edge` refers to HEAD of `master` at any given point in time. +**NOTE:** Docker tag `latest` refers to _latest_ stable released version and `edge` +refers to HEAD of `master` at any given point in time. ## Community -- Discuss terraform-docs on [Slack](https://terraform-docs.slack.com/) +- Discuss terraform-docs on [Slack] ## Maintenance -This project was originally developed by [Segment](https://github.com/segmentio/) but now is no longer maintained by them. Instead, [Martin Etmajer](https://github.com/metmajer) from [GetCloudnative](https://github.com/getcloudnative) and [Khosrow Moossavi](https://github.com/khos2ow) from [CloudOps](https://github.com/cloudops) are maintaining the project with help from these awesome [contributors](AUTHORS). Note that maintainers are unaffiliated with Segment. +This project was originally developed by [Segment] but now is no longer maintained +by them. Instead, [Martin Etmajer] from [GetCloudnative] and [Khosrow Moossavi] from +[CloudOps] are maintaining the project with help from these awesome [contributors]. +Note that maintainers are unaffiliated with Segment. ## License MIT License - Copyright (c) 2021 The terraform-docs Authors. + +[User Guide]: ./docs/USER_GUIDE.md +[Formats Guide]: ./docs/FORMATS_GUIDE.md +[Config File Reference]: ./docs/CONFIG_FILE.md +[Contributing Guide]: CONTRIBUTING.md +[docs]: ./docs/ +[here]: https://golang.org/doc/code.html#GOPATH +[releases]: https://github.com/terraform-docs/terraform-docs/releases +[Homebrew]: https://brew.sh +[Scoop]: https://scoop.sh/ +[Chocolatey]: https://www.chocolatey.org +[Slack]: https://terraform-docs.slack.com/ +[Segment]: https://github.com/segmentio/ +[Martin Etmajer]: https://github.com/metmajer +[GetCloudnative]: https://github.com/getcloudnative +[Khosrow Moossavi]: https://github.com/khos2ow +[CloudOps]: https://github.com/cloudops +[contributors]: AUTHORS diff --git a/internal/version/version.go b/internal/version/version.go index 6258d62..66ee398 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -18,7 +18,7 @@ import ( ) // current version -const dev = "v0.10.2-alpha" +const dev = "v0.11.0-alpha" // Provisioned by ldflags var ( diff --git a/scripts/build/build-all-osarch.sh b/scripts/build/build-all-osarch.sh deleted file mode 100755 index d82d855..0000000 --- a/scripts/build/build-all-osarch.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright 2021 The terraform-docs Authors. -# -# Licensed under the MIT license (the "License"); you may not -# use this file except in compliance with the License. -# -# You may obtain a copy of the License at the LICENSE file in -# the root directory of this source tree. - -set -e - -BUILD_DIR="${1:-bin}" -NAME="${2:-terraform-docs}" -VERSION="$3" -GOOS="${4:-"linux darwin windows freebsd"}" -GOARCH="${5:-"amd64 arm"}" -GOLDFLAGS="$6" - -if [ -z "${VERSION}" ]; then - echo "Error: VERSION is missing. e.g. ./compress.sh " - exit 1 -fi -if [ -z "${GOLDFLAGS}" ]; then - echo "Error: GOLDFLAGS is missing. e.g. ./compress.sh " - exit 1 -fi - -PWD=$(cd "$(dirname "$0")" && pwd -P) -BUILD_DIR="${PWD}/../../${BUILD_DIR}" - -CGO_ENABLED=0 gox \ - -verbose \ - -ldflags "${GOLDFLAGS}" \ - -gcflags=-trimpath="$(go env GOPATH)" \ - -os="${GOOS}" \ - -arch="${GOARCH}" \ - -osarch="!darwin/arm" \ - -output="${BUILD_DIR}/{{.OS}}-{{.Arch}}/{{.Dir}}" "${PWD}"/../../ - -printf "\033[36m==> Finalize binary\033[0m\n" - -for platform in $(find "${BUILD_DIR}" -mindepth 1 -maxdepth 1 -type d | sort -u); do - OSARCH=$(basename "${platform}") - FULLNAME="${NAME}-${VERSION}-${OSARCH}" - - case "${OSARCH}" in - "windows"*) - mv "${platform}/${NAME}.exe" "${BUILD_DIR}/${FULLNAME}.exe" - printf -- "--> %15s: bin/%s\n" "${OSARCH}" "${FULLNAME}.exe" - ;; - *) - mv "${platform}/${NAME}" "${BUILD_DIR}/${FULLNAME}" - printf -- "--> %15s: bin/%s\n" "${OSARCH}" "${FULLNAME}" - ;; - esac -done - -cd "${BUILD_DIR}" -touch "${NAME}-${VERSION}.sha256sum" - -for binary in $(find . -mindepth 1 -maxdepth 1 -type f | grep -v "${NAME}-${VERSION}.sha256sum" | sort); do - binary=$(basename "${binary}") - - if command -v sha256sum >/dev/null; then - sha256sum "${binary}" >>"${NAME}-${VERSION}.sha256sum" - elif command -v shasum >/dev/null; then - shasum -a256 "${binary}" >>"${NAME}-${VERSION}.sha256sum" - fi -done - -cd - >/dev/null 2>&1 -printf -- "\n--> %15s: bin/%s\n" "sha256sum" "${NAME}-${VERSION}.sha256sum" diff --git a/scripts/homebrew/README.md b/scripts/homebrew/README.md deleted file mode 100644 index ceccfae..0000000 --- a/scripts/homebrew/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Homebrew Formula - -This formula is kept here only for reference, the [official formula](https://github.com/Homebrew/homebrew-core/blob/master/Formula/terraform-docs.rb) file is located and maintained on the official [homebrew-core](https://github.com/Homebrew/homebrew-core) repository. - -To install `terraform-docs` you can simply use [Homebrew](https://brew.sh): - -``` bash -brew install terraform-docs -``` diff --git a/scripts/homebrew/terraform-docs.rb b/scripts/homebrew/terraform-docs.rb deleted file mode 100644 index 900e917..0000000 --- a/scripts/homebrew/terraform-docs.rb +++ /dev/null @@ -1,61 +0,0 @@ -class TerraformDocs < Formula - desc "Tool to generate documentation from Terraform modules" - homepage "https://github.com/terraform-docs/terraform-docs" - url "https://github.com/terraform-docs/terraform-docs/archive/v0.8.2.tar.gz" - sha256 "005957c5c5d56a27e60ca735128231f68c3f099b433a7041a0f1591bee59fbd0" - - bottle do - cellar :any_skip_relocation - sha256 "07e6bc6850459581f65fc59b0bc1152fbd917c7a760fc2e7203c55bc581bcbc7" => :catalina - sha256 "a91bb362006421c48eb1f6c251b5515bce6930f9611d116469fea0390966531d" => :mojave - sha256 "27b5477a3af7c8cdd53ba80fbf86309a65deeb8668dc010cd88cb0cb872272fb" => :high_sierra - end - - depends_on "go" => :build - - def install - system "make", "build" - bin.install "bin/darwin-amd64/terraform-docs" - prefix.install_metafiles - end - - test do - (testpath/"main.tf").write <<~EOS - /** - * Module usage: - * - * module "foo" { - * source = "github.com/foo/baz" - * subnet_ids = "${join(",", subnet.*.id)}" - * } - */ - - variable "subnet_ids" { - description = "a comma-separated list of subnet IDs" - } - - variable "security_group_ids" { - default = "sg-a, sg-b" - } - - variable "amis" { - default = { - "us-east-1" = "ami-8f7687e2" - "us-west-1" = "ami-bb473cdb" - "us-west-2" = "ami-84b44de4" - "eu-west-1" = "ami-4e6ffe3d" - "eu-central-1" = "ami-b0cc23df" - "ap-northeast-1" = "ami-095dbf68" - "ap-southeast-1" = "ami-cf03d2ac" - "ap-southeast-2" = "ami-697a540a" - } - } - - // The VPC ID. - output "vpc_id" { - value = "vpc-5c1f55fd" - } - EOS - system "#{bin}/terraform-docs", "json", testpath - end -end diff --git a/scripts/release/Dockerfile b/scripts/release/Dockerfile new file mode 100644 index 0000000..c75d66d --- /dev/null +++ b/scripts/release/Dockerfile @@ -0,0 +1,15 @@ +# Copyright 2021 The terraform-docs Authors. +# +# Licensed under the MIT license (the "License"); you may not +# use this file except in compliance with the License. +# +# You may obtain a copy of the License at the LICENSE file in +# the root directory of this source tree. + +FROM alpine:3.12.3 + +RUN apk --no-cache add ca-certificates + +COPY terraform-docs /usr/local/bin/terraform-docs + +ENTRYPOINT ["terraform-docs"] diff --git a/scripts/release/release.sh b/scripts/release/release.sh index 5e62505..3cd5ed9 100755 --- a/scripts/release/release.sh +++ b/scripts/release/release.sh @@ -12,7 +12,8 @@ set -o errexit set -o pipefail CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -if [ -z "${CURRENT_BRANCH}" ] && [ "${CURRENT_BRANCH}" != "master" ]; then + +if [ -z "${CURRENT_BRANCH}" ] || [ "${CURRENT_BRANCH}" != "master" ]; then echo "Error: The current branch is '${CURRENT_BRANCH}', switch to 'master' to do the release." exit 1 fi @@ -30,7 +31,7 @@ if [ -z "${RELEASE_VERSION}" ]; then if [ -z "${FROM_MAKEFILE}" ]; then echo "Error: VERSION is missing. e.g. ./release.sh " else - echo "Error: missing value for 'version'. e.g. 'make release version=x.y.z'" + echo "Error: missing value for 'version'. e.g. 'make release VERSION=x.y.z'" fi exit 1 fi @@ -60,7 +61,7 @@ function getClosestVersion() { fi break done - echo "${tag//^v/}" + echo "${tag//v/}" } CLOSEST_VERSION=$(getClosestVersion) @@ -69,19 +70,17 @@ if [[ $RELEASE_VERSION != *"-alpha"* && $RELEASE_VERSION != *"-beta"* && $RELEAS sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" README.md git add README.md fi + sed -i -E "s|v${RELEASE_VERSION}-alpha|v${RELEASE_VERSION}|g" internal/version/version.go +git add internal/version/version.go # Commit changes printf "\033[36m==> %s\033[0m\n" "Commit changes for release version v${RELEASE_VERSION}" -git add internal/version/version.go git commit -m "Release version v${RELEASE_VERSION}" printf "\033[36m==> %s\033[0m\n" "Push commits for v${RELEASE_VERSION}" git push origin master -# Generate Changelog -make --no-print-directory -f "${PWD}"/../../Makefile changelog NEXT="--next-tag v${RELEASE_VERSION}" - # Tag the release printf "\033[36m==> %s\033[0m\n" "Tag release v${RELEASE_VERSION}" git tag --annotate --message "v${RELEASE_VERSION} Release" "v${RELEASE_VERSION}" diff --git a/scripts/release/update-choco.sh b/scripts/release/update-choco.sh new file mode 100755 index 0000000..d416fe3 --- /dev/null +++ b/scripts/release/update-choco.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# +# Copyright 2021 The terraform-docs Authors. +# +# Licensed under the MIT license (the "License"); you may not +# use this file except in compliance with the License. +# +# You may obtain a copy of the License at the LICENSE file in +# the root directory of this source tree. + +set -o errexit +set -o pipefail + +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + +if [ -z "${CURRENT_BRANCH}" ] || [ "${CURRENT_BRANCH}" != "master" ]; then + echo "Error: The current branch is '${CURRENT_BRANCH}', switch to 'main' to do the release." + exit 1 +fi + +if [ -n "$(git status --short)" ]; then + echo "Error: There are untracked/modified changes, commit or discard them before the release." + exit 1 +fi + +RELEASE_VERSION=$1 + +if [ -z "${RELEASE_VERSION}" ]; then + echo "Error: release version is missing" + exit 1 +fi + +PWD=$(cd "$(dirname "$0")" && pwd -P) + +# get closest GA tag, ignore alpha, beta and rc tags +function getClosestVersion() { + for t in $(git tag --sort=-creatordate); do + tag="$t" + if [[ "$tag" == *"-alpha"* ]] || [[ "$tag" == *"-beta"* ]] || [[ "$tag" == *"-rc"* ]]; then + continue + fi + break + done + echo "${tag//v/}" +} +CLOSEST_VERSION=$(getClosestVersion) + +git clone https://github.com/terraform-docs/chocolatey-package "${PWD}/chocolatey-package" + +# Bump version in terraform-docs.nuspec +sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" "${PWD}/chocolatey-package/terraform-docs.nuspec" + +# Bump version and checksum in tools/chocolateyinstall.ps1 +CHECKSUM=$(grep windows-amd64.exe "${PWD}/../../dist/terraform-docs-v${RELEASE_VERSION}.sha256sum" | awk '{print $1}') + +sed -i -E "s|checksum = '.*$|checksum = '${CHECKSUM}'|g" "${PWD}/chocolatey-package/tools/chocolateyinstall.ps1" +sed -i -E "s|v${CLOSEST_VERSION}|v${RELEASE_VERSION}|g" "${PWD}/chocolatey-package/tools/chocolateyinstall.ps1"