ci: enhance release workflows

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
Khosrow Moossavi
2024-06-02 12:03:48 -04:00
parent 8ae3344d97
commit 19194525e4
11 changed files with 355 additions and 217 deletions

66
.github/scripts/Makefile vendored Normal file
View File

@@ -0,0 +1,66 @@
# Copyright 2024 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.
# Project variables
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
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
CUR_VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.0-$(COMMIT_HASH)")
###########
##@ Release
.PHONY: contributors
contributors: OLD_VERSION ?= ""
contributors: NEW_VERSION ?= ""
contributors: ## generate contributors list
@ $(MAKE) --no-print-directory log-$@
@ ./contributors.sh "$(OLD_VERSION)" "$(NEW_VERSION)" "1"
PATTERN =
# if the last relase was alpha, beta or rc, 'release' target has to used with current
# 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 $(CUR_VERSION) | sed 's/^v//' | awk -F'[ .]' '{print $(PATTERN)}')
release: ## Prepare release
@ $(MAKE) --no-print-directory log-$@
@ ./release.sh "$(VERSION)" "$(CUR_VERSION)" "1"
.PHONY: patch
patch: PATTERN = '\$$1\".\"\$$2\".\"\$$3+1'
patch: release ## Prepare Patch release
.PHONY: minor
minor: PATTERN = '\$$1\".\"\$$2+1\".0\"'
minor: release ## Prepare Minor release
.PHONY: major
major: PATTERN = '\$$1+1\".0.0\"'
major: release ## Prepare Major release
########################################################################
## Self-Documenting Makefile Help ##
## https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html ##
########################################################################
########
##@ Help
.PHONY: help
help: ## Display this help
@awk -v "col=\033[36m" -v "nocol=\033[0m" ' BEGIN { FS = ":.*##" ; printf "Usage:\n make %s<target>%s\n", col, nocol } /^[a-zA-Z_-]+:.*?##/ { printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 } /^##@/ { printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol } ' $(MAKEFILE_LIST)
log-%:
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m==> %s\033[0m\n", $$2 }'

75
.github/scripts/contributors.sh vendored Executable file
View File

@@ -0,0 +1,75 @@
#!/usr/bin/env bash
#
# Copyright 2024 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 'master' 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
OLD_VERSION=${1//v/}
NEW_VERSION=${2//v/}
FROM_MAKEFILE=$3
# 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
if [ "$tag" == "v${NEW_VERSION}" ]; then
continue
fi
break
done
echo "${tag//v/}"
}
CLOSEST_VERSION=$(getClosestVersion)
if [ -z "$OLD_VERSION" ]; then
OLD_VERSION="${CLOSEST_VERSION}"
fi
if [ -z "$OLD_VERSION" ] || [ -z "$NEW_VERSION" ]; then
if [ -z "${FROM_MAKEFILE}" ]; then
echo "Error: refs are missing. e.g. contributors <OLD_VERSION> <NEW_VERSION>"
else
echo "Error: refs are missing. e.g. 'make contributors OLD_VERSION=x.y.z NEW_VERSION=a.b.c'"
fi
exit 1
fi
touch contributors.list
git log "v${OLD_VERSION}..v${NEW_VERSION}" |
grep ^Author: |
sed 's/ <.*//; s/^Author: //' |
sort |
uniq |
while read -r line; do
name=$(printf %s "$line" | iconv -f utf-8 -t ascii//translit | jq -sRr @uri)
handle=$(curl -fsSL "https://api.github.com/search/users?q=in:name%20${name}" | jq -r '.items[0].login')
if [ "$handle" == "null" ]; then
echo "- @${name}" >> contributors.list
else
echo "- @${handle}" >> contributors.list
fi
sleep 5
done

View File

@@ -12,7 +12,6 @@ set -o errexit
set -o pipefail
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
if [ -z "${CURRENT_BRANCH}" ] || [ "${CURRENT_BRANCH}" != "master" ]; then
echo "Error: The current branch is '${CURRENT_BRANCH}', switch to 'master' to do the release."
@@ -24,11 +23,11 @@ if [ -n "$(git status --short)" ]; then
exit 1
fi
RELEASE_VERSION=$1
CURRENT_VERSION=$2
RELEASE_FULL_VERSION=${1//v/}
CURRENT_FULL_VERSION=${2//v/}
FROM_MAKEFILE=$3
if [ -z "${RELEASE_VERSION}" ]; then
if [ -z "${RELEASE_FULL_VERSION}" ]; then
if [ -z "${FROM_MAKEFILE}" ]; then
echo "Error: VERSION is missing. e.g. ./release.sh <version>"
else
@@ -37,17 +36,19 @@ if [ -z "${RELEASE_VERSION}" ]; then
exit 1
fi
if [ -z "${CURRENT_VERSION}" ]; then
CURRENT_VERSION=$(git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.1-${COMMIT_HASH}")
if [ -z "${CURRENT_FULL_VERSION}" ]; then
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)
CURRENT_FULL_VERSION=$(git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.1-${COMMIT_HASH}")
fi
CURRENT_FULL_VERSION=${CURRENT_FULL_VERSION//v/}
if [ "v${RELEASE_VERSION}" == "${CURRENT_VERSION}" ]; then
echo "Error: provided version (v${RELEASE_VERSION}) already exists."
if [ "${RELEASE_FULL_VERSION}" == "${CURRENT_FULL_VERSION}" ]; then
echo "Error: provided version (v${RELEASE_FULL_VERSION}) already exists."
exit 1
fi
if [ "$(git describe --tags "v${RELEASE_VERSION}" 2>/dev/null)" ]; then
echo "Error: provided version (v${RELEASE_VERSION}) already exists."
if [ "$(git describe --tags "v${RELEASE_FULL_VERSION}" 2>/dev/null)" ]; then
echo "Error: provided version (v${RELEASE_FULL_VERSION}) already exists."
exit 1
fi
@@ -64,21 +65,27 @@ function getClosestVersion() {
}
CLOSEST_VERSION=$(getClosestVersion)
echo "Release Version: ${RELEASE_VERSION}"
echo "Closest Version: ${CLOSEST_VERSION}"
echo "Release Version: v${RELEASE_FULL_VERSION}"
echo "Closest Version: v${CLOSEST_VERSION}"
# Bump the released version in README and version.go
if [[ $RELEASE_VERSION != *"-alpha"* && $RELEASE_VERSION != *"-beta"* && $RELEASE_VERSION != *"-rc"* ]]; then
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" README.md
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" docs/user-guide/installation.md
RELEASE_VERSION=$(echo $RELEASE_FULL_VERSION | cut -d"-" -f1)
RELEASE_IDENTIFIER=$(echo $RELEASE_FULL_VERSION | cut -d"-" -f2)
if [[ $RELEASE_VERSION == $RELEASE_IDENTIFIER ]]; then
RELEASE_IDENTIFIER=""
fi
# Set the released version in README and installation.md
if [[ $RELEASE_IDENTIFIER == "" ]]; then
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" ../../README.md
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" ../../docs/user-guide/installation.md
echo "Modified: README.md"
echo "Modified: docs/user-guide/installation.md"
git add README.md docs/user-guide/installation.md
fi
sed -i -E "s|coreVersion([[:space:]]*)= \"(.*)\"|coreVersion\1= \"${RELEASE_VERSION}\"|g" internal/version/version.go
sed -i -E "s|prerelease([[:space:]]*)= \"(.*)\"|prerelease\1= \"\"|g" internal/version/version.go
# Set the released version and identifier in version.go
sed -i -E "s|coreVersion([[:space:]]*)= \"(.*)\"|coreVersion\1= \"${RELEASE_VERSION}\"|g" ../../internal/version/version.go
sed -i -E "s|prerelease([[:space:]]*)= \"(.*)\"|prerelease\1= \"${RELEASE_IDENTIFIER}\"|g" ../../internal/version/version.go
echo "Modified: internal/version/version.go"
git add internal/version/version.go

View File

@@ -1,45 +0,0 @@
name: release-cut
on:
workflow_dispatch:
inputs:
version:
description: "The version to be released (without leading v)"
required: true
type: string
jobs:
release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Prepare v${{ inputs.version }} Release
run: |
make release VERSION=${{ inputs.version }}
- name: Push v${{ inputs.version }} Changes
uses: stefanzweifel/git-auto-commit-action@v5
env:
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
with:
file_pattern: "README.md docs/user-guide/installation.md internal/version/version.go"
commit_message: "Release version v${{ inputs.version }}"
commit_user_name: terraform-docs-bot
commit_user_email: bot@terraform-docs.io
commit_author: "terraform-docs-bot <bot@terraform-docs.io>"
- name: Cut v${{ inputs.version }} Release
run: |
git config --global user.name terraform-docs-bot
git config --global user.email bot@terraform-docs.io
git tag --annotate --message "v${{ inputs.version }} Release" "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"

62
.github/workflows/prepare-release.yml vendored Normal file
View File

@@ -0,0 +1,62 @@
name: prepare-release
run-name: prepare release v${{ github.event.inputs.version }}
on:
workflow_dispatch:
inputs:
version:
description: "The version to be released"
required: true
type: string
jobs:
release:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
token: ${{ secrets.COMMITTER_TOKEN }}
- name: Get variables
run: |
release_version="${{ inputs.version }}"
echo "release_version=${release_version//v/}" >> "$GITHUB_ENV"
- name: Prepare v${{ env.release_version }} Release
run: |
make -C .github/scripts release VERSION=${{ env.release_version }}
- name: Generate commit message
id: commit-message
run: |
if [[ ${{ env.release_version }} == *"-alpha"* ]]; then
echo "release_commit_message=chore: bump version to v${{ env.release_version }}" >> "$GITHUB_ENV"
else
echo "release_commit_message=Release version v${{ env.release_version }}" >> "$GITHUB_ENV"
fi
- name: Push v${{ env.release_version }} Changes
uses: stefanzweifel/git-auto-commit-action@v5
env:
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
with:
file_pattern: "README.md docs/user-guide/installation.md internal/version/version.go"
commit_message: "${{ env.release_commit_message }}"
commit_user_name: terraform-docs-bot
commit_user_email: bot@terraform-docs.io
commit_author: "terraform-docs-bot <bot@terraform-docs.io>"
- name: Cut v${{ env.release_version }} Release
if: "!contains(env.release_version, '-alpha')" # skip when starting new release cycle
run: |
git config --global user.name terraform-docs-bot
git config --global user.email bot@terraform-docs.io
git tag --annotate --message "v${{ env.release_version }} Release" "v${{ env.release_version }}"
git push origin "v${{ env.release_version }}"

View File

@@ -28,8 +28,9 @@ jobs:
uses: goreleaser/goreleaser-action@v5
if: env.REGISTRY_USERNAME != ''
with:
version: latest
args: release --rm-dist --skip-publish --skip-sign
distribution: goreleaser
version: 1.26.2
args: release --clean --skip=publish --skip=sign
- name: Release
uses: softprops/action-gh-release@v2
@@ -52,7 +53,7 @@ jobs:
- name: Set version output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v'
run: echo "release_tag=${GITHUB_REF:11}" >> "$GITHUB_ENV" # tag name without leading 'v'
- name: Login to Docker
uses: docker/login-action@v3
@@ -65,6 +66,6 @@ jobs:
- name: Build and push Docker image
run: make docker push
env:
DOCKER_TAG: ${{ steps.vars.outputs.tag }}
DOCKER_TAG: ${{ env.release_tag }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}

View File

@@ -25,6 +25,12 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}
- name: Generate Contributors list
id: contributors
run: |
make -C .github/scripts contributors NEW_VERSION=${GITHUB_REF:11}
echo "contributors_list=$(cat .github/scripts/contributors.list)" >> "$GITHUB_ENV"
- name: Login to Docker
uses: docker/login-action@v3
if: env.REGISTRY_USERNAME != ''
@@ -37,37 +43,77 @@ jobs:
uses: goreleaser/goreleaser-action@v5
if: env.REGISTRY_USERNAME != ''
with:
version: latest
args: release --rm-dist --skip-sign
distribution: goreleaser
version: 1.26.2
args: release --clean --skip=sign
env:
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
- name: Set version output
id: vars
run: echo ::set-output name=tag::${GITHUB_REF:11} # tag name without leading 'v'
- name: Update Chocolatey package
run: ./scripts/release/update-choco.sh "${{ steps.vars.outputs.tag }}"
- 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: terraform-docs-bot
git-user-email: bot@terraform-docs.io
git-commit-message: "Chocolatey update for terraform-docs version v${{ steps.vars.outputs.tag }}"
excludes: README.md:LICENSE:DCO:.git:.github
Contributors: ${{ env.contributors_list }}
homebrew:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [assets]
steps:
- name: Bump Homebrew formula version
uses: dawidd6/action-homebrew-bump-formula@v3.11.0
if: "!contains(github.ref, '-')" # skip prereleases
with:
token: ${{ secrets.COMMITTER_TOKEN }}
formula: terraform-docs
chocolatey:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [assets]
steps:
- name: Update Chocolatey package
run: |
# 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
if [ "$tag" == "${GITHUB_REF:11}" ]; then
continue
fi
break
done
echo "${tag//v/}"
}
CLOSEST_VERSION=$(getClosestVersion)
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.COMMITTER_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/terraform-docs/chocolatey-package/dispatches \
-d "{\
\"event_type\": \"trigger-workflow\", \
\"client_payload\": {\
\"current-version\": \"${CLOSEST_VERSION}\", \
\"release-version\": \"${GITHUB_REF:11}\" \
}\
}"
gh-actions:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
needs: [assets]
steps:
- name: Update GitHub Actions
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.COMMITTER_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/terraform-docs/chocolatey-package/dispatches \
-d "{\
\"event_type\": \"trigger-workflow\", \
\"client_payload\": {\
\"release-version\": \"${GITHUB_REF:11}\" \
}\
}"

3
.gitignore vendored
View File

@@ -35,3 +35,6 @@ dist/
# website
site/
# contributors.list
contributors.list

View File

@@ -38,12 +38,46 @@ checksum:
snapshot:
name_template: "{{ .Tag }}-dev"
release:
github:
owner: terraform-docs
name: terraform-docs
header: |
## Notable Updates
footer: |
## Docker images
- `docker pull quay.io/terraform-docs/terraform-docs:latest`
- `docker pull quay.io/terraform-docs/terraform-docs:{{ .RawVersion }}`
## Contributors
Very special thanks to the contributors.
{{ .Env.Contributors }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^Merge pull request"
groups:
- title: Dependency updates
regexp: '^.*?(.+)\(deps\)!?:.+$'
order: 300
- title: "Features"
regexp: '^.*?feat(\(.+\))??!?:.+$'
order: 100
- title: "Security updates"
regexp: '^.*?sec(\(.+\))??!?:.+$'
order: 150
- title: "Bug Fixes"
regexp: '^.*?(fix|refactor)(\(.+\))??!?:.+$'
order: 200
- title: "Chores"
order: 9999
dockers:
- dockerfile: scripts/release/Dockerfile
@@ -52,7 +86,7 @@ dockers:
- "quay.io/terraform-docs/terraform-docs:{{ .RawVersion }}"
brews:
- tap:
- repository:
owner: terraform-docs
name: homebrew-tap
commit_author:
@@ -64,20 +98,15 @@ brews:
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
scoops:
- repository:
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

View File

@@ -109,32 +109,6 @@ docs: ## Generate document of formatter commands
@ $(MAKE) --no-print-directory log-$@
$(GORUN) ./scripts/docs/generate.go
###########
##@ Release
PATTERN =
# if the last relase was alpha, beta or rc, 'release' target has to used with current
# 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 $(CUR_VERSION) | sed 's/^v//' | awk -F'[ .]' '{print $(PATTERN)}')
release: ## Prepare release
@ $(MAKE) --no-print-directory log-$@
@ ./scripts/release/release.sh "$(VERSION)" "$(CUR_VERSION)" "1"
.PHONY: patch
patch: PATTERN = '\$$1\".\"\$$2\".\"\$$3+1'
patch: release ## Prepare Patch release
.PHONY: minor
minor: PATTERN = '\$$1\".\"\$$2+1\".0\"'
minor: release ## Prepare Minor release
.PHONY: major
major: PATTERN = '\$$1+1\".0.0\"'
major: release ## Prepare Major release
###########
##@ Helpers
@@ -165,27 +139,7 @@ tools: ## Install required tools
.PHONY: help
help: ## Display this help
@awk \
-v "col=\033[36m" -v "nocol=\033[0m" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Usage:\n make %s<target>%s\n", col, nocol \
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol \
} \
' $(MAKEFILE_LIST)
@awk -v "col=\033[36m" -v "nocol=\033[0m" ' BEGIN { FS = ":.*##" ; printf "Usage:\n make %s<target>%s\n", col, nocol } /^[a-zA-Z_-]+:.*?##/ { printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 } /^##@/ { printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol } ' $(MAKEFILE_LIST)
log-%:
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \
awk \
'BEGIN { \
FS = ":.*?## " \
}; \
{ \
printf "\033[36m==> %s\033[0m\n", $$2 \
}'
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m==> %s\033[0m\n", $$2 }'

View File

@@ -1,60 +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 -o errexit
set -o pipefail
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 immediately before the latest one, ignore alpha, beta and rc tags
function getClosestVersion() {
local latest
latest=""
for t in $(git tag --sort=-creatordate); do
tag="$t"
if [[ "$tag" == *"-alpha"* ]] || [[ "$tag" == *"-beta"* ]] || [[ "$tag" == *"-rc"* ]]; then
continue
fi
if [ -z "$latest" ]; then
latest="$t"
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|<version>${CLOSEST_VERSION}</version>|<version>${RELEASE_VERSION}</version>|g" "${PWD}/chocolatey-package/terraform-docs.nuspec"
# Bump version and checksum in tools/chocolateyinstall.ps1
CHECKSUM=$(grep windows-amd64.zip "${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"
pushd "${PWD}/chocolatey-package/"
git diff
popd