blob: c41424cbd6a23b225a05da499e57bb9641e279c0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
name: 'Prepare Release'
description: 'Prepare release branch with version bump, changelog update, and push'
inputs:
version-change:
description: 'Version change type: PATCH, MINOR, or MAJOR'
required: true
version-file:
description: 'Path to version.txt file (e.g., ydb/apps/ydb/version.txt)'
required: true
changelog-file:
description: 'Path to CHANGELOG.md file (optional, e.g., ydb/apps/ydb/CHANGELOG.md)'
required: false
default: ''
branch-prefix:
description: 'Release branch prefix (e.g., cli-release/)'
required: true
product-name:
description: 'Product name for commit message (e.g., YDB CLI)'
required: true
version-artifact-name:
description: 'Name for the version artifact (e.g., cli-version)'
required: true
version-artifact-file:
description: 'File name inside the version artifact (e.g., cli_version.txt)'
required: false
default: 'version.txt'
outputs:
branch-name:
description: 'Name of the created release branch'
value: ${{ steps.create-branch.outputs.branch-name }}
new-version:
description: 'New version number'
value: ${{ steps.update-version.outputs.new-version }}
release-commit-sha:
description: 'SHA of the release commit'
value: ${{ steps.push-branch.outputs.release-commit-sha }}
runs:
using: 'composite'
steps:
- name: Read current version
id: read-version
shell: bash
run: |
CURRENT_VERSION=$(cat ${{ inputs.version-file }})
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Calculate new version
id: update-version
shell: bash
run: |
CURRENT_VERSION="${{ steps.read-version.outputs.current-version }}"
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
if [ "${{ inputs.version-change }}" = "MAJOR" ]; then
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
elif [ "${{ inputs.version-change }}" = "MINOR" ]; then
MINOR=$((MINOR+1))
PATCH=0
elif [ "${{ inputs.version-change }}" = "PATCH" ]; then
PATCH=$((PATCH+1))
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Create release branch
id: create-branch
shell: bash
run: |
git fetch origin main
git checkout main
git reset --hard origin/main
BRANCH_NAME="${{ inputs.branch-prefix }}${{ steps.update-version.outputs.new-version }}"
git checkout -b "$BRANCH_NAME"
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "Created branch: $BRANCH_NAME"
- name: Check CHANGELOG.md format
if: ${{ inputs.changelog-file != '' }}
shell: bash
run: |
FIRST_LINE=$(head -n 1 ${{ inputs.changelog-file }})
SECOND_LINE=$(head -n 2 ${{ inputs.changelog-file }} | tail -n 1)
THIRD_LINE=$(head -n 3 ${{ inputs.changelog-file }} | tail -n 1)
if [[ -z "$FIRST_LINE" ]] && [[ "$SECOND_LINE" =~ ^##.*##$ ]] && [[ -z "$THIRD_LINE" ]]; then
echo "Error: CHANGELOG has nothing new since last release"
exit 1
fi
- name: Update version file
shell: bash
run: |
echo "${{ steps.update-version.outputs.new-version }}" > ${{ inputs.version-file }}
git add ${{ inputs.version-file }}
- name: Update CHANGELOG
if: ${{ inputs.changelog-file != '' }}
shell: bash
run: |
NEW_VERSION="${{ steps.update-version.outputs.new-version }}"
echo "" > /tmp/changelog_header.md
echo "## $NEW_VERSION ##" >> /tmp/changelog_header.md
echo "" >> /tmp/changelog_header.md
cat /tmp/changelog_header.md ${{ inputs.changelog-file }} > /tmp/new_changelog.md
mv /tmp/new_changelog.md ${{ inputs.changelog-file }}
git add ${{ inputs.changelog-file }}
- name: Create version file
shell: bash
run: |
NEW_VERSION="${{ steps.update-version.outputs.new-version }}"
echo "$NEW_VERSION" > ${{ inputs.version-artifact-file }}
echo "Created ${{ inputs.version-artifact-file }} with version: $NEW_VERSION"
- name: Upload version artifact
uses: actions/upload-artifact@v6
with:
name: ${{ inputs.version-artifact-name }}
path: ${{ inputs.version-artifact-file }}
if-no-files-found: error
retention-days: 1
- name: Commit changes
shell: bash
run: |
git commit -m "${{ inputs.product-name }} release ${{ steps.update-version.outputs.new-version }}"
- name: Push branch
id: push-branch
shell: bash
run: |
git push origin "${{ steps.create-branch.outputs.branch-name }}"
RELEASE_SHA=$(git rev-parse HEAD)
echo "release-commit-sha=$RELEASE_SHA" >> $GITHUB_OUTPUT
echo "Release commit SHA: $RELEASE_SHA"
|