Skip to content

Commit 2b71b4d

Browse files
committed
chore: add release-cut workflow
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent dcdda6f commit 2b71b4d

File tree

2 files changed

+55
-17
lines changed

2 files changed

+55
-17
lines changed

.github/workflows/cut-release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: release-cut
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The version to be released (without leading v)"
8+
required: true
9+
type: string
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
15+
permissions:
16+
contents: write
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
ref: master
22+
fetch-depth: 0
23+
24+
- name: Prepare v${{ inputs.version }} Release
25+
run: |
26+
make release VERSION=${{ inputs.version }}
27+
28+
- name: Push v${{ inputs.version }} Changes
29+
uses: stefanzweifel/git-auto-commit-action@v5
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
32+
with:
33+
file_pattern: "README.md docs/user-guide/installation.md internal/version/version.go"
34+
commit_message: "Release version v${{ inputs.version }}"
35+
commit_user_name: terraform-docs-bot
36+
commit_user_email: bot@terraform-docs.io
37+
commit_author: "terraform-docs-bot <bot@terraform-docs.io>"
38+
39+
- name: Cut v${{ inputs.version }} Release
40+
run: |
41+
git config --global user.name terraform-docs-bot
42+
git config --global user.email bot@terraform-docs.io
43+
44+
git tag --annotate --message "v${{ inputs.version }} Release" "v${{ inputs.version }}"
45+
git push origin "v${{ inputs.version }}"

scripts/release/release.sh

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set -o errexit
1212
set -o pipefail
1313

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

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

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

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

53-
PWD=$(cd "$(dirname "$0")" && pwd -P)
54-
5554
# get closest GA tag, ignore alpha, beta and rc tags
5655
function getClosestVersion() {
5756
for t in $(git tag --sort=-creatordate); do
@@ -65,27 +64,21 @@ function getClosestVersion() {
6564
}
6665
CLOSEST_VERSION=$(getClosestVersion)
6766

67+
echo "Release Version: ${RELEASE_VERSION}"
68+
echo "Closest Version: ${CLOSEST_VERSION}"
69+
6870
# Bump the released version in README and version.go
6971
if [[ $RELEASE_VERSION != *"-alpha"* && $RELEASE_VERSION != *"-beta"* && $RELEASE_VERSION != *"-rc"* ]]; then
7072
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" README.md
7173
sed -i -E "s|${CLOSEST_VERSION}|${RELEASE_VERSION}|g" docs/user-guide/installation.md
74+
75+
echo "Modified: README.md"
76+
echo "Modified: docs/user-guide/installation.md"
7277
git add README.md docs/user-guide/installation.md
7378
fi
7479

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

79-
# Commit changes
80-
printf "\033[36m==> %s\033[0m\n" "Commit changes for release version v${RELEASE_VERSION}"
81-
git commit -m "Release version v${RELEASE_VERSION}"
82-
83-
printf "\033[36m==> %s\033[0m\n" "Push commits for v${RELEASE_VERSION}"
84-
git push origin master
85-
86-
# Tag the release
87-
printf "\033[36m==> %s\033[0m\n" "Tag release v${RELEASE_VERSION}"
88-
git tag --annotate --message "v${RELEASE_VERSION} Release" "v${RELEASE_VERSION}"
89-
90-
printf "\033[36m==> %s\033[0m\n" "Push tag release v${RELEASE_VERSION}"
91-
git push origin "v${RELEASE_VERSION}"
83+
echo "Modified: internal/version/version.go"
84+
git add internal/version/version.go

0 commit comments

Comments
 (0)