diff --git a/.github/workflows/cut-release.yml b/.github/workflows/cut-release.yml new file mode 100644 index 0000000..d83976f --- /dev/null +++ b/.github/workflows/cut-release.yml @@ -0,0 +1,45 @@ +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 " + + - 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 }}" diff --git a/scripts/release/release.sh b/scripts/release/release.sh index 401b48c..b497b08 100755 --- a/scripts/release/release.sh +++ b/scripts/release/release.sh @@ -12,6 +12,7 @@ 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." @@ -37,7 +38,7 @@ if [ -z "${RELEASE_VERSION}" ]; then 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)") + CURRENT_VERSION=$(git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.1-${COMMIT_HASH}") fi if [ "v${RELEASE_VERSION}" == "${CURRENT_VERSION}" ]; then @@ -50,8 +51,6 @@ if [ "$(git describe --tags "v${RELEASE_VERSION}" 2>/dev/null)" ]; then 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 @@ -65,27 +64,21 @@ function getClosestVersion() { } CLOSEST_VERSION=$(getClosestVersion) +echo "Release Version: ${RELEASE_VERSION}" +echo "Closest Version: ${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 + + 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 + +echo "Modified: 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 commit -m "Release version v${RELEASE_VERSION}" - -printf "\033[36m==> %s\033[0m\n" "Push commits for v${RELEASE_VERSION}" -git push origin master - -# 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}" - -printf "\033[36m==> %s\033[0m\n" "Push tag release v${RELEASE_VERSION}" -git push origin "v${RELEASE_VERSION}"