Skip to content

Commit 43f9c39

Browse files
committed
build: overall improvements to release scripts
Signed-off-by: Khosrow Moossavi <[email protected]>
1 parent e47bfa1 commit 43f9c39

File tree

7 files changed

+206
-100
lines changed

7 files changed

+206
-100
lines changed

.github/scripts/prepare-release.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2021 The terraform-docs Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o pipefail
19+
set -o errtrace
20+
21+
NEW_VERSION=$1
22+
TF_DOCS_VERSION=$2
23+
24+
PWD=$(cd "$(dirname "$0")" && pwd -P)
25+
26+
if [ -z "${NEW_VERSION}" ]; then
27+
NEW_VERSION=$(grep "uses: terraform-docs/gh-actions" "${PWD}"/../../README.md | tr -s ' ' | uniq | cut -d"@" -f2)
28+
fi
29+
if [ -z "${NEW_VERSION}" ]; then
30+
echo "Usage: pre-release.sh <NEW_VERSION> <TF_DOCS_VERSION>"
31+
exit 1
32+
fi
33+
34+
if [ -z "${TF_DOCS_VERSION}" ]; then
35+
TF_DOCS_VERSION=$(grep "FROM quay.io/terraform-docs/terraform-docs" "${PWD}"/../Dockerfile | tr -s ' ' | uniq | cut -d":" -f2)
36+
fi
37+
if [ -z "${TF_DOCS_VERSION}" ]; then
38+
echo "Usage: pre-release.sh <NEW_VERSION> <TF_DOCS_VERSION>"
39+
exit 1
40+
fi
41+
42+
# Update README
43+
VERSION=v${NEW_VERSION//v/} TERRAFORM_DOCS_VERSION=v${TF_DOCS_VERSION//v/} \
44+
gomplate \
45+
-d action="${PWD}"/../../action.yml \
46+
-f "${PWD}"/../../.github/templates/README.tpl \
47+
-o "${PWD}"/../../README.md
48+
49+
# Update Dockerfile
50+
sed -i -E "s|FROM quay.io/terraform-docs/terraform-docs:(.*)|FROM quay.io/terraform-docs/terraform-docs:${TF_DOCS_VERSION//v/}|g" "${PWD}"/../../Dockerfile
51+
52+
# Update action.yml
53+
sed -i -E "s|docker://quay.io/terraform-docs/gh-actions:(.*)\"|docker://quay.io/terraform-docs/gh-actions:${NEW_VERSION//v/}\"|g" "${PWD}"/../../action.yml
54+
55+
if [ "$(git status --porcelain | grep -c 'M README.md')" -eq 1 ]; then
56+
echo "Modified: README.md"
57+
fi
58+
if [ "$(git status --porcelain | grep -c 'M Dockerfile')" -eq 1 ]; then
59+
echo "Modified: Dockerfile"
60+
fi
61+
if [ "$(git status --porcelain | grep -c 'M action.yml')" -eq 1 ]; then
62+
echo "Modified: action.yml"
63+
fi

.github/templates/README.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{{- define "sanatize_value" }}{{ . | strings.ReplaceAll "\n\n" "\\n\\n" | strings.ReplaceAll " \n" "\\n" | strings.ReplaceAll "\n" "\\n" }}{{- end }}
44
{{- $action := (datasource "action") -}}
55
{{- $version := or (getenv "VERSION") "main" -}}
6+
{{- $tfdocsversion := or (getenv "TERRAFORM_DOCS_VERSION") "v0.0.0" -}}
67
# terraform-docs GitHub Actions
78

89
{{ $action.description }}
@@ -13,7 +14,7 @@ branch.
1314

1415
## Version
1516

16-
`{{ $version }}` (uses [terraform-docs] v0.18.0, which is supported and tested on Terraform
17+
`{{ $version }}` (uses [terraform-docs] {{ $tfdocsversion }}, which is supported and tested on Terraform
1718
version 0.11+ and 0.12+ but may work for others.)
1819

1920
{{- if eq $version "main" }}

.github/workflows/release.yml

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,66 @@
11
name: release
2+
run-name: release v${{ github.event.inputs.version }}
23

34
on:
4-
release:
5-
types: [published]
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: "gh-actions version to be released (without leading v)"
9+
required: true
10+
type: string
611

712
env:
13+
GOMPLATE_VERSION: "v3.8.0"
814
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
915

1016
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
20+
permissions:
21+
contents: write
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
ref: main
27+
fetch-depth: 0
28+
token: ${{ secrets.COMMITTER_TOKEN }}
29+
30+
- name: Install gomplate
31+
run: |
32+
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/${{ env.GOMPLATE_VERSION }}/gomplate_linux-amd64
33+
sudo chmod 755 /usr/local/bin/gomplate
34+
35+
- name: Get variables
36+
run: |
37+
release_version="${{ inputs.version }}"
38+
echo "release_version=${release_version//v/}" >> "$GITHUB_ENV"
39+
40+
- name: Prepare v${{ env.release_version }} Release
41+
run: |
42+
./.github/scripts/prepare-release.sh ${{ env.release_version }}
43+
44+
- name: Push v${{ env.release_version }} Changes
45+
uses: stefanzweifel/git-auto-commit-action@v5
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
48+
with:
49+
file_pattern: "README.md action.yml"
50+
commit_message: "chore: prepare release v${{ env.release_version }}"
51+
commit_user_name: terraform-docs-bot
52+
commit_user_email: [email protected]
53+
commit_author: "terraform-docs-bot <[email protected]>"
54+
1155
docker:
1256
runs-on: ubuntu-latest
57+
needs: [release]
1358
steps:
1459
- name: Checkout
1560
uses: actions/checkout@v4
61+
with:
62+
ref: main
63+
fetch-depth: 0
1664

1765
- name: Login to Docker
1866
uses: docker/login-action@v3
@@ -25,19 +73,30 @@ jobs:
2573
- name: Build Docker image
2674
if: env.REGISTRY_USERNAME != ''
2775
run: |
28-
VERSION=$(echo ${{ github.event.release.tag_name }} | sed 's/v//')
29-
docker build --pull --tag quay.io/terraform-docs/gh-actions:"${VERSION}" .
76+
docker build --pull --tag quay.io/terraform-docs/gh-actions:${{ env.release_version }} .
3077
docker build --pull --tag quay.io/terraform-docs/gh-actions:latest .
31-
docker push quay.io/terraform-docs/gh-actions:"${VERSION}"
78+
docker push quay.io/terraform-docs/gh-actions:${{ env.release_version }}
3279
docker push quay.io/terraform-docs/gh-actions:latest
3380
3481
update-tag:
3582
runs-on: ubuntu-latest
83+
needs: [release]
3684
steps:
3785
- name: Checkout
3886
uses: actions/checkout@v4
87+
with:
88+
ref: main
89+
fetch-depth: 0
90+
token: ${{ secrets.COMMITTER_TOKEN }}
91+
92+
- name: Cut v${{ env.release_version }} Release
93+
run: |
94+
git config --global user.name terraform-docs-bot
95+
git config --global user.email [email protected]
96+
97+
git tag "v${{ env.release_version }}"
98+
git push origin "v${{ env.release_version }}"
3999
40-
- run: |
41-
VERSION=$(echo ${{ github.event.release.tag_name }} | cut -d. -f1)
42-
git tag -f "${VERSION}"
43-
git push -f --tags
100+
VERSION=$(echo ${{ env.release_version }} | cut -d. -f1)
101+
git tag -f v${VERSION}
102+
git push -f v${VERSION}

.github/workflows/update-tfdocs.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
release-version:
10+
description: "terraform-docs new release version"
11+
required: true
12+
type: string
13+
14+
env:
15+
GOMPLATE_VERSION: "v3.8.0"
16+
17+
jobs:
18+
prepare:
19+
runs-on: ubuntu-latest
20+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
21+
permissions:
22+
contents: write
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
with:
27+
ref: main
28+
fetch-depth: 0
29+
token: ${{ secrets.COMMITTER_TOKEN }}
30+
31+
- name: Install gomplate
32+
run: |
33+
sudo curl -sSLo /usr/local/bin/gomplate https://github.com/hairyhenderson/gomplate/releases/download/${{ env.GOMPLATE_VERSION }}/gomplate_linux-amd64
34+
sudo chmod 755 /usr/local/bin/gomplate
35+
36+
- name: Get variables
37+
run: |
38+
if [ -n "${{ github.event.client_payload.release-version }}" ]; then
39+
release_version="${{ github.event.client_payload.release-version }}"
40+
else
41+
release_version="${{ inputs.release-version }}"
42+
fi
43+
echo "release_version=${release_version//v/}" >> "$GITHUB_ENV"
44+
45+
- name: Bump to terraform-docs v${{ env.release_version }}
46+
run: |
47+
./.github/scripts/prepare-release.sh "" ${{ env.release_version }}
48+
49+
- name: Push terraform-docs v${{ env.release_version }} Changes
50+
uses: stefanzweifel/git-auto-commit-action@v5
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
53+
with:
54+
file_pattern: "README.md Dockerfile"
55+
commit_message: "chore: bump terraform-docs to v${{ env.release_version }}"
56+
commit_user_name: terraform-docs-bot
57+
commit_user_email: [email protected]
58+
commit_author: "terraform-docs-bot <[email protected]>"

scripts/pre-release.sh

Lines changed: 0 additions & 49 deletions
This file was deleted.

scripts/release.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

scripts/update-readme.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,31 @@ set -o pipefail
1919
set -o errtrace
2020

2121
NEW_VERSION=$1
22+
TF_DOCS_VERSION=$2
2223

2324
PWD=$(cd "$(dirname "$0")" && pwd -P)
2425

2526
if [ -z "${NEW_VERSION}" ]; then
2627
NEW_VERSION=$(grep "uses: terraform-docs/gh-actions" "${PWD}"/../README.md | tr -s ' ' | uniq | cut -d"@" -f2)
2728
fi
28-
2929
if [ -z "${NEW_VERSION}" ]; then
30-
echo "Must have version like: v1.0.1"
30+
echo "Usage: update-readme.sh <NEW_VERSION> <TF_DOCS_VERSION>"
31+
exit 1
32+
fi
33+
34+
if [ -z "${TF_DOCS_VERSION}" ]; then
35+
TF_DOCS_VERSION=$(grep "FROM quay.io/terraform-docs/terraform-docs" "${PWD}"/../Dockerfile | tr -s ' ' | uniq | cut -d":" -f2)
36+
fi
37+
if [ -z "${TF_DOCS_VERSION}" ]; then
38+
echo "Usage: update-readme.sh <NEW_VERSION> <TF_DOCS_VERSION>"
3139
exit 1
3240
fi
3341

3442
# Update the README
35-
VERSION=${NEW_VERSION} gomplate -d action="${PWD}"/../action.yml -f "${PWD}"/../.github/templates/README.tpl -o "${PWD}"/../README.md
43+
VERSION=v${NEW_VERSION//v/} TERRAFORM_DOCS_VERSION=v${TF_DOCS_VERSION//v/} \
44+
gomplate -d \
45+
action="${PWD}"/../action.yml \
46+
-f "${PWD}"/../.github/templates/README.tpl \
47+
-o "${PWD}"/../README.md
3648

3749
echo "README.md updated."

0 commit comments

Comments
 (0)