Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/scripts/update-tfdocs.sh
Original file line number Diff line number Diff line change
@@ -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|<version>${CURRENT_VERSION}</version>|<version>${RELEASE_VERSION}</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"
79 changes: 79 additions & 0 deletions .github/workflows/update-tfdocs.yml
Original file line number Diff line number Diff line change
@@ -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 <bot@terraform-docs.io>"