|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright 2021 The terraform-docs Authors. |
| 4 | +# |
| 5 | +# Licensed under the MIT license (the "License"); you may not |
| 6 | +# use this file except in compliance with the License. |
| 7 | +# |
| 8 | +# You may obtain a copy of the License at the LICENSE file in |
| 9 | +# the root directory of this source tree. |
| 10 | + |
| 11 | +set -o errexit |
| 12 | +set -o pipefail |
| 13 | + |
| 14 | +CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
| 15 | + |
| 16 | +if [ -z "${CURRENT_BRANCH}" ] || [ "${CURRENT_BRANCH}" != "master" ]; then |
| 17 | + echo "Error: The current branch is '${CURRENT_BRANCH}', switch to 'master' to do the release." |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +if [ -n "$(git status --short)" ]; then |
| 22 | + echo "Error: There are untracked/modified changes, commit or discard them before the release." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +CURRENT_VERSION=${1//v/} |
| 27 | +RELEASE_VERSION=${2//v/} |
| 28 | +RELEASE_CHECKSUM=$3 |
| 29 | + |
| 30 | +if [ -z "${CURRENT_VERSION}" ]; then |
| 31 | + echo "Error: current version is missing" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | +if [ -z "${RELEASE_VERSION}" ]; then |
| 35 | + echo "Error: release version is missing" |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +if [ -z "${RELEASE_CHECKSUM}" ]; then |
| 40 | + RELEASE_CHECKSUM=$(curl -sSL https://terraform-docs.io/dl/v${RELEASE_VERSION}/terraform-docs-v${RELEASE_VERSION}.sha256sum | grep terraform-docs-v${RELEASE_VERSION}-windows-amd64.zip | awk '{print $1}') |
| 41 | +fi |
| 42 | +if [ -z "${RELEASE_CHECKSUM}" ]; then |
| 43 | + echo "Error: release checksum is missing" |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +PWD=$(cd "$(dirname "$0")" && pwd -P) |
| 48 | + |
| 49 | +echo "Current Version: v${CURRENT_VERSION}" |
| 50 | +echo "Release Version: v${RELEASE_VERSION}" |
| 51 | + |
| 52 | +# Bump version in terraform-docs.nuspec |
| 53 | +sed -i -E "s|<version>${CURRENT_VERSION}</version>|<version>${RELEASE_VERSION}</version>|g" "${PWD}/../../terraform-docs.nuspec" |
| 54 | + |
| 55 | +# Bump version and checksum in tools/chocolateyinstall.ps1 |
| 56 | +sed -i -E "s|checksum = '.*$|checksum = '${RELEASE_CHECKSUM}'|g" "${PWD}/../../tools/chocolateyinstall.ps1" |
| 57 | +sed -i -E "s|v${CURRENT_VERSION}|v${RELEASE_VERSION}|g" "${PWD}/../../tools/chocolateyinstall.ps1" |
| 58 | + |
| 59 | +echo "Modified: terraform-docs.nuspec" |
| 60 | +echo "Modified: tools/chocolateyinstall.ps1" |
0 commit comments