Skip to content

Commit 668b63a

Browse files
committed
[ci skip] ci: enhance release scripts
Signed-off-by: Khosrow <khos2ow@gmail.com>
1 parent 8bfd363 commit 668b63a

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

.github/scripts/update-tfdocs.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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"

.github/workflows/update-tfdocs.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: update-terraform-docs
2+
run-name: update terraform-docs version
3+
4+
on:
5+
repository_dispatch:
6+
types: [trigger-workflow]
7+
workflow_dispatch:
8+
inputs:
9+
current-version:
10+
description: "terraform-docs current version"
11+
required: true
12+
type: string
13+
release-version:
14+
description: "terraform-docs new release version"
15+
required: true
16+
type: string
17+
release-checksum:
18+
description: "terraform-docs sha256 checksum"
19+
required: true
20+
type: string
21+
22+
jobs:
23+
update:
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
permissions:
27+
contents: write
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
ref: main
33+
fetch-depth: 0
34+
token: ${{ secrets.COMMITTER_TOKEN }}
35+
36+
- name: Get variables
37+
run: |
38+
###################
39+
# current version #
40+
###################
41+
if [ -n "${{ github.event.client_payload.current-version }}" ]; then
42+
current_version="${{ github.event.client_payload.current-version }}"
43+
else
44+
current_version="${{ inputs.current-version }}"
45+
fi
46+
echo "current_version=${current_version//v/}" >> "$GITHUB_ENV"
47+
48+
###################
49+
# release version #
50+
###################
51+
if [ -n "${{ github.event.client_payload.release-version }}" ]; then
52+
release_version="${{ github.event.client_payload.release-version }}"
53+
else
54+
release_version="${{ inputs.release-version }}"
55+
fi
56+
echo "release_version=${release_version//v/}" >> "$GITHUB_ENV"
57+
58+
####################
59+
# release checksum #
60+
####################
61+
if [ -n "${{ github.event.client_payload.release-checksum }}" ]; then
62+
echo "checksum=${{ github.event.client_payload.release-checksum }}" >> "$GITHUB_ENV"
63+
else
64+
echo "checksum=${{ inputs.release-checksum }}" >> "$GITHUB_ENV"
65+
fi
66+
67+
- name: Update to terraform-docs v${{ env.release_version }}
68+
run: ./.github/scripts/update-tfdocs.sh "${{ env.current_version }}" "${{ env.release_version }}" "${{ env.checksum }}"
69+
70+
- name: Push terraform-docs v${{ inputs.release_version }} Changes
71+
uses: stefanzweifel/git-auto-commit-action@v5
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
74+
with:
75+
file_pattern: "terraform-docs.nuspec tools/chocolateyinstall.ps1"
76+
commit_message: "Chocolatey update for terraform-docs version v${{ env.release_version }}"
77+
commit_user_name: terraform-docs-bot
78+
commit_user_email: bot@terraform-docs.io
79+
commit_author: "terraform-docs-bot <bot@terraform-docs.io>"

0 commit comments

Comments
 (0)