From 668b63a1f456d3afd2252bca3e494a6cbaf2a805 Mon Sep 17 00:00:00 2001 From: Khosrow Date: Mon, 3 Jun 2024 16:05:09 -0400 Subject: [PATCH] [ci skip] ci: enhance release scripts Signed-off-by: Khosrow --- .github/scripts/update-tfdocs.sh | 60 ++++++++++++++++++++++ .github/workflows/update-tfdocs.yml | 79 +++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100755 .github/scripts/update-tfdocs.sh create mode 100644 .github/workflows/update-tfdocs.yml diff --git a/.github/scripts/update-tfdocs.sh b/.github/scripts/update-tfdocs.sh new file mode 100755 index 0000000..5dea34e --- /dev/null +++ b/.github/scripts/update-tfdocs.sh @@ -0,0 +1,60 @@ +#!/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 '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 + +CURRENT_VERSION=${1//v/} +RELEASE_VERSION=${2//v/} +RELEASE_CHECKSUM=$3 + +if [ -z "${CURRENT_VERSION}" ]; then + echo "Error: current version is missing" + exit 1 +fi +if [ -z "${RELEASE_VERSION}" ]; then + echo "Error: release version is missing" + exit 1 +fi + +if [ -z "${RELEASE_CHECKSUM}" ]; then + 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}') +fi +if [ -z "${RELEASE_CHECKSUM}" ]; then + echo "Error: release checksum is missing" + exit 1 +fi + +PWD=$(cd "$(dirname "$0")" && pwd -P) + +echo "Current Version: v${CURRENT_VERSION}" +echo "Release Version: v${RELEASE_VERSION}" + +# Bump version in terraform-docs.nuspec +sed -i -E "s|${CURRENT_VERSION}|${RELEASE_VERSION}|g" "${PWD}/../../terraform-docs.nuspec" + +# Bump version and checksum in tools/chocolateyinstall.ps1 +sed -i -E "s|checksum = '.*$|checksum = '${RELEASE_CHECKSUM}'|g" "${PWD}/../../tools/chocolateyinstall.ps1" +sed -i -E "s|v${CURRENT_VERSION}|v${RELEASE_VERSION}|g" "${PWD}/../../tools/chocolateyinstall.ps1" + +echo "Modified: terraform-docs.nuspec" +echo "Modified: tools/chocolateyinstall.ps1" diff --git a/.github/workflows/update-tfdocs.yml b/.github/workflows/update-tfdocs.yml new file mode 100644 index 0000000..27eae10 --- /dev/null +++ b/.github/workflows/update-tfdocs.yml @@ -0,0 +1,79 @@ +name: update-terraform-docs +run-name: update terraform-docs version + +on: + repository_dispatch: + types: [trigger-workflow] + workflow_dispatch: + inputs: + current-version: + description: "terraform-docs current version" + required: true + type: string + release-version: + description: "terraform-docs new release version" + required: true + type: string + release-checksum: + description: "terraform-docs sha256 checksum" + required: true + type: string + +jobs: + update: + 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: main + fetch-depth: 0 + token: ${{ secrets.COMMITTER_TOKEN }} + + - name: Get variables + run: | + ################### + # current version # + ################### + if [ -n "${{ github.event.client_payload.current-version }}" ]; then + current_version="${{ github.event.client_payload.current-version }}" + else + current_version="${{ inputs.current-version }}" + fi + echo "current_version=${current_version//v/}" >> "$GITHUB_ENV" + + ################### + # release version # + ################### + if [ -n "${{ github.event.client_payload.release-version }}" ]; then + release_version="${{ github.event.client_payload.release-version }}" + else + release_version="${{ inputs.release-version }}" + fi + echo "release_version=${release_version//v/}" >> "$GITHUB_ENV" + + #################### + # release checksum # + #################### + if [ -n "${{ github.event.client_payload.release-checksum }}" ]; then + echo "checksum=${{ github.event.client_payload.release-checksum }}" >> "$GITHUB_ENV" + else + echo "checksum=${{ inputs.release-checksum }}" >> "$GITHUB_ENV" + fi + + - name: Update to terraform-docs v${{ env.release_version }} + run: ./.github/scripts/update-tfdocs.sh "${{ env.current_version }}" "${{ env.release_version }}" "${{ env.checksum }}" + + - name: Push terraform-docs v${{ inputs.release_version }} Changes + uses: stefanzweifel/git-auto-commit-action@v5 + env: + GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }} + with: + file_pattern: "terraform-docs.nuspec tools/chocolateyinstall.ps1" + commit_message: "Chocolatey update for terraform-docs version v${{ env.release_version }}" + commit_user_name: terraform-docs-bot + commit_user_email: bot@terraform-docs.io + commit_author: "terraform-docs-bot "