Skip to content

Commit

Permalink
chore: add release-cut workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
  • Loading branch information
khos2ow committed May 30, 2024
1 parent dcdda6f commit 2b71b4d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/cut-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: release-cut

on:
workflow_dispatch:
inputs:
version:
description: "The version to be released (without leading v)"
required: true
type: string

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: master
fetch-depth: 0

- name: Prepare v${{ inputs.version }} Release
run: |
make release VERSION=${{ 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 docs/user-guide/installation.md internal/version/version.go"
commit_message: "Release version 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 --annotate --message "v${{ inputs.version }} Release" "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
27 changes: 10 additions & 17 deletions scripts/release/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set -o errexit
set -o pipefail

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null)

if [ -z "${CURRENT_BRANCH}" ] || [ "${CURRENT_BRANCH}" != "master" ]; then
echo "Error: The current branch is '${CURRENT_BRANCH}', switch to 'master' to do the release."
Expand All @@ -37,7 +38,7 @@ if [ -z "${RELEASE_VERSION}" ]; then
fi

if [ -z "${CURRENT_VERSION}" ]; then
CURRENT_VERSION=$(git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.1-$(COMMIT_HASH)")
CURRENT_VERSION=$(git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.1-${COMMIT_HASH}")
fi

if [ "v${RELEASE_VERSION}" == "${CURRENT_VERSION}" ]; then
Expand All @@ -50,8 +51,6 @@ if [ "$(git describe --tags "v${RELEASE_VERSION}" 2>/dev/null)" ]; then
exit 1
fi

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

# get closest GA tag, ignore alpha, beta and rc tags
function getClosestVersion() {
for t in $(git tag --sort=-creatordate); do
Expand All @@ -65,27 +64,21 @@ function getClosestVersion() {
}
CLOSEST_VERSION=$(getClosestVersion)

echo "Release Version: ${RELEASE_VERSION}"
echo "Closest Version: ${CLOSEST_VERSION}"

# Bump the released version in README and version.go
if [[ $RELEASE_VERSION != *"-alpha"* && $RELEASE_VERSION != *"-beta"* && $RELEASE_VERSION != *"-rc"* ]]; then
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" README.md
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" docs/user-guide/installation.md

echo "Modified: README.md"
echo "Modified: docs/user-guide/installation.md"
git add README.md docs/user-guide/installation.md
fi

sed -i -E "s|coreVersion([[:space:]]*)= \"(.*)\"|coreVersion\1= \"${RELEASE_VERSION}\"|g" internal/version/version.go
sed -i -E "s|prerelease([[:space:]]*)= \"(.*)\"|prerelease\1= \"\"|g" internal/version/version.go
git add internal/version/version.go

# Commit changes
printf "\033[36m==> %s\033[0m\n" "Commit changes for release version v${RELEASE_VERSION}"
git commit -m "Release version v${RELEASE_VERSION}"

printf "\033[36m==> %s\033[0m\n" "Push commits for v${RELEASE_VERSION}"
git push origin master

# Tag the release
printf "\033[36m==> %s\033[0m\n" "Tag release v${RELEASE_VERSION}"
git tag --annotate --message "v${RELEASE_VERSION} Release" "v${RELEASE_VERSION}"

printf "\033[36m==> %s\033[0m\n" "Push tag release v${RELEASE_VERSION}"
git push origin "v${RELEASE_VERSION}"
echo "Modified: internal/version/version.go"
git add internal/version/version.go

0 comments on commit 2b71b4d

Please sign in to comment.