Skip to content

Commit

Permalink
build: overall improvements to release scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
  • Loading branch information
khos2ow committed Jun 3, 2024
1 parent e47bfa1 commit 120e327
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 98 deletions.
53 changes: 53 additions & 0 deletions .github/scripts/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
# Copyright 2021 The terraform-docs Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o pipefail
set -o errtrace

NEW_VERSION=$1
TF_DOCS_VERSION=$2

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

if [ -z "${NEW_VERSION}" ]; then
NEW_VERSION=$(grep "uses: terraform-docs/gh-actions" "${PWD}"/../../README.md | tr -s ' ' | uniq | cut -d"@" -f2)
fi
if [ -z "${NEW_VERSION}" ]; then
echo "Usage: pre-release.sh <NEW_VERSION> <TF_DOCS_VERSION>"
exit 1
fi

if [ -z "${TF_DOCS_VERSION}" ]; then
TF_DOCS_VERSION=$(grep "FROM quay.io/terraform-docs/terraform-docs" "${PWD}"/../Dockerfile | tr -s ' ' | uniq | cut -d":" -f2)
fi
if [ -z "${TF_DOCS_VERSION}" ]; then
echo "Usage: pre-release.sh <NEW_VERSION> <TF_DOCS_VERSION>"
exit 1
fi

# Update README
VERSION=v${NEW_VERSION//v/} TERRAFORM_DOCS_VERSION=v${TF_DOCS_VERSION//v/} \
gomplate \
-d action="${PWD}"/../../action.yml \
-f "${PWD}"/../../.github/templates/README.tpl \
-o "${PWD}"/../../README.md

# Update Dockerfile
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

# Update action.yml
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
3 changes: 2 additions & 1 deletion .github/templates/README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{- define "sanatize_value" }}{{ . | strings.ReplaceAll "\n\n" "\\n\\n" | strings.ReplaceAll " \n" "\\n" | strings.ReplaceAll "\n" "\\n" }}{{- end }}
{{- $action := (datasource "action") -}}
{{- $version := or (getenv "VERSION") "main" -}}
{{- $tfdocsversion := or (getenv "TERRAFORM_DOCS_VERSION") "v0.0.0" -}}
# terraform-docs GitHub Actions

{{ $action.description }}
Expand All @@ -13,7 +14,7 @@ branch.

## Version

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

{{- if eq $version "main" }}
Expand Down
73 changes: 66 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,73 @@
name: release
run-name: release v${{ github.event.inputs.version }}

on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "gh-actions version to be released (without leading v)"
required: true
type: string

env:
GOMPLATE_VERSION: "v3.8.0"
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}

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: main
fetch-depth: 0
token: ${{ secrets.COMMITTER_TOKEN }}

- name: Install gomplate
run: |
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/${{ env.GOMPLATE_VERSION }}/gomplate_linux-amd64
sudo chmod 755 /usr/local/bin/gomplate
- name: Prepare v${{ inputs.version }} Release
run: |
./.github/scripts/prepare-release.sh ${{ 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 action.yml"
commit_message: "chore: prepare release v${{ inputs.version }}"
commit_user_name: terraform-docs-bot
commit_user_email: bot@terraform-docs.io
commit_author: "terraform-docs-bot <bot@terraform-docs.io>"

- 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 "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
VERSION=$(echo ${{ inputs.version }} | cut -d. -f1)
git tag -f v${VERSION//v/}
git push -f v${VERSION//v/}
docker:
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- name: Login to Docker
uses: docker/login-action@v3
Expand All @@ -25,19 +80,23 @@ jobs:
- name: Build Docker image
if: env.REGISTRY_USERNAME != ''
run: |
VERSION=$(echo ${{ github.event.release.tag_name }} | sed 's/v//')
docker build --pull --tag quay.io/terraform-docs/gh-actions:"${VERSION}" .
docker build --pull --tag quay.io/terraform-docs/gh-actions:${{ inputs.version }} .
docker build --pull --tag quay.io/terraform-docs/gh-actions:latest .
docker push quay.io/terraform-docs/gh-actions:"${VERSION}"
docker push quay.io/terraform-docs/gh-actions:${{ inputs.version }}
docker push quay.io/terraform-docs/gh-actions:latest
update-tag:
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.COMMITTER_TOKEN }}

- run: |
VERSION=$(echo ${{ github.event.release.tag_name }} | cut -d. -f1)
git tag -f "${VERSION}"
VERSION=$(echo ${{ inputs.version }} | cut -d. -f1)
git tag -f v${{ inputs.version }}
git push -f --tags
47 changes: 47 additions & 0 deletions .github/workflows/update-tfdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: update-terraform-docs
run-name: update terraform-docs to v${{ github.event.inputs.version }}

on:
workflow_dispatch:
inputs:
tfdocs-version:
description: "terraform-docs version (without leading v)"
required: true
type: string

env:
GOMPLATE_VERSION: "v3.8.0"

jobs:
prepare:
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: Install gomplate
run: |
sudo curl -o /usr/local/bin/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/${{ env.GOMPLATE_VERSION }}/gomplate_linux-amd64
sudo chmod 755 /usr/local/bin/gomplate
- name: Bump to terraform-docs v${{ inputs.tfdocs-version }}
run: |
./.github/scripts/prepare-release.sh "" ${{ inputs.tfdocs-version }}
- name: Push terraform-docs v${{ inputs.tfdocs-version }} Changes
uses: stefanzweifel/git-auto-commit-action@v5
env:
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
with:
file_pattern: "README.md Dockerfile"
commit_message: "chore: bump terraform-docs to v${{ inputs.tfdocs-version }}"
commit_user_name: terraform-docs-bot
commit_user_email: bot@terraform-docs.io
commit_author: "terraform-docs-bot <bot@terraform-docs.io>"
49 changes: 0 additions & 49 deletions scripts/pre-release.sh

This file was deleted.

38 changes: 0 additions & 38 deletions scripts/release.sh

This file was deleted.

18 changes: 15 additions & 3 deletions scripts/update-readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,31 @@ set -o pipefail
set -o errtrace

NEW_VERSION=$1
TF_DOCS_VERSION=$2

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

if [ -z "${NEW_VERSION}" ]; then
NEW_VERSION=$(grep "uses: terraform-docs/gh-actions" "${PWD}"/../README.md | tr -s ' ' | uniq | cut -d"@" -f2)
fi

if [ -z "${NEW_VERSION}" ]; then
echo "Must have version like: v1.0.1"
echo "Usage: update-readme.sh <NEW_VERSION> <TF_DOCS_VERSION>"
exit 1
fi

if [ -z "${TF_DOCS_VERSION}" ]; then
TF_DOCS_VERSION=$(grep "FROM quay.io/terraform-docs/terraform-docs" "${PWD}"/../Dockerfile | tr -s ' ' | uniq | cut -d":" -f2)
fi
if [ -z "${TF_DOCS_VERSION}" ]; then
echo "Usage: update-readme.sh <NEW_VERSION> <TF_DOCS_VERSION>"
exit 1
fi

# Update the README
VERSION=${NEW_VERSION} gomplate -d action="${PWD}"/../action.yml -f "${PWD}"/../.github/templates/README.tpl -o "${PWD}"/../README.md
VERSION=v${NEW_VERSION//v/} TERRAFORM_DOCS_VERSION=v${TF_DOCS_VERSION//v/} \
gomplate -d \
action="${PWD}"/../action.yml \
-f "${PWD}"/../.github/templates/README.tpl \
-o "${PWD}"/../README.md

echo "README.md updated."

0 comments on commit 120e327

Please sign in to comment.