-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update YugabyteDB version automatically using github action
- Loading branch information
1 parent
f69f4a1
commit 52499fb
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit -o pipefail | ||
|
||
# Following file will modify to update YugabyteDB version | ||
readonly FILE_TO_UPDATE="variables.tf" | ||
|
||
# version_gt compares the given two versions. | ||
# It returns 0 exit code if the version1 is greater than version2. | ||
function version_gt() { | ||
test "$(echo -e "$1\n$2" | sort -V | head -n 1)" != "$1" | ||
} | ||
|
||
# Verify number of arguments | ||
if [[ $# -ne 1 ]]; then | ||
echo "No arguments supplied. Please provide release version" 1>&2 | ||
echo "Terminating the script execution." 1>&2 | ||
exit 1 | ||
fi | ||
|
||
release_version="$1" | ||
echo "Release Version - ${release_version}" | ||
|
||
# Verify release version | ||
if ! [[ "${release_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
echo "Something wrong with the version. Release version format - *.*.*.*" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# Current Version in variables.tf | ||
current_version="$(grep -A 2 "yb_version" "${FILE_TO_UPDATE}" | grep "default" | cut -d '"' -f 2)" | ||
echo "Current Release Version - ${current_version}" | ||
|
||
# Version comparison | ||
if ! version_gt "${release_version}" "${current_version}" ; then | ||
echo "Release version is either older or equal to the current version: '${release_version}' <= '${current_version}'" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# Following parameter will be updated. | ||
# 1. value: "2.1.4.0" | ||
|
||
echo "Updating..." | ||
|
||
# Update Version | ||
sed -i -E "/^variable \"yb_version\"/,+2 s/[0-9]+.[0-9]+.[0-9]+.[0-9]+/"${release_version}"/" "${FILE_TO_UPDATE}" | ||
|
||
echo "Completed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: "Update YugabyteDB version" | ||
on: | ||
repository_dispatch: | ||
types: | ||
- build-on-release | ||
jobs: | ||
update-version: | ||
if: github.event.client_payload.prerelease == 'false' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: "Configure git" | ||
run: | | ||
git config user.name 'YugaByte CI' | ||
git config user.email 'yugabyte-ci@users.noreply.github.com' | ||
- name: "Extract version number from tag" | ||
id: extract-version | ||
run: | | ||
tag_name="${{ github.event.client_payload.release }}" | ||
echo "Extracting version number from the tag '${tag_name}'." | ||
version_number="${tag_name/v/}" | ||
# Keep dots and count the string length | ||
dot_count="$(res="${version_number//[^.]/}"; echo "${#res}")" | ||
if [[ "${dot_count}" -eq 2 ]]; then | ||
version_number="${version_number}.0" | ||
fi | ||
if [[ "$(res="${version_number//[^.]/}"; echo "${#res}")" -ne 3 ]]; then | ||
echo "The tag '${tag_name}' is invalid. Expected format: 'v1.2.3' or 'v1.2.3.5'." 1>&2 | ||
exit 1 | ||
fi | ||
echo "Extracted the version number '${version_number}'." | ||
echo "::set-output name=yb_version::${version_number}" | ||
- name: "Update the version" | ||
id: update-version | ||
continue-on-error: true | ||
run: | | ||
.ci/update-version.sh '${{steps.extract-version.outputs.yb_version}}' | ||
- name: "Push the changes" | ||
if: steps.update-version.outcome == 'success' | ||
run: | | ||
git status | ||
git diff | ||
git add variables.tf | ||
git commit -m "Update the version to ${{steps.extract-version.outputs.yb_version}}" | ||
git push origin ${{ github.ref }} | ||
- name: "Status in case of update-version failure" | ||
if: steps.update-version.outcome == 'failure' | ||
run: | | ||
git status | ||
git diff | ||
exit 1 |