Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: overall improvements to release scripts #134

Merged
merged 1 commit into from
Jun 4, 2024
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
63 changes: 63 additions & 0 deletions .github/scripts/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/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

if [ "$(git status --porcelain | grep -c 'M README.md')" -eq 1 ]; then
echo "Modified: README.md"
fi
if [ "$(git status --porcelain | grep -c 'M Dockerfile')" -eq 1 ]; then
echo "Modified: Dockerfile"
fi
if [ "$(git status --porcelain | grep -c 'M action.yml')" -eq 1 ]; then
echo "Modified: action.yml"
fi
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
77 changes: 68 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
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:/hairyhenderson/gomplate/releases/download/${{ env.GOMPLATE_VERSION }}/gomplate_linux-amd64
sudo chmod 755 /usr/local/bin/gomplate

- name: Get variables
run: |
release_version="${{ inputs.version }}"
echo "release_version=${release_version//v/}" >> "$GITHUB_ENV"

- name: Prepare v${{ env.release_version }} Release
run: |
./.github/scripts/prepare-release.sh ${{ env.release_version }}

- name: Push v${{ env.release_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${{ env.release_version }}"
commit_user_name: terraform-docs-bot
commit_user_email: [email protected]
commit_author: "terraform-docs-bot <[email protected]>"

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 +73,30 @@ 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:${{ env.release_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:${{ env.release_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 }}

- name: Cut v${{ env.release_version }} Release
run: |
git config --global user.name terraform-docs-bot
git config --global user.email [email protected]

git tag "v${{ env.release_version }}"
git push origin "v${{ env.release_version }}"

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

on:
repository_dispatch:
types: [trigger-workflow]
workflow_dispatch:
inputs:
release-version:
description: "terraform-docs new release version"
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 -sSLo /usr/local/bin/gomplate https:/hairyhenderson/gomplate/releases/download/${{ env.GOMPLATE_VERSION }}/gomplate_linux-amd64
sudo chmod 755 /usr/local/bin/gomplate

- name: Get variables
run: |
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"

- name: Bump to terraform-docs v${{ env.release_version }}
run: |
./.github/scripts/prepare-release.sh "" ${{ env.release_version }}

- name: Push terraform-docs v${{ env.release_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${{ env.release_version }}"
commit_user_name: terraform-docs-bot
commit_user_email: [email protected]
commit_author: "terraform-docs-bot <[email protected]>"
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."