Skip to content

Commit

Permalink
Optimize regex patterns to get version name from dependencies.gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarSpruit authored and jreij committed May 2, 2023
1 parent 248f21e commit 6e58dd4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions scripts/version_name.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/bin/bash

function release_version() {
local build_file="${GITHUB_WORKSPACE}/build.gradle"
local version_name_key="ext.version_name"
local build_file="${GITHUB_WORKSPACE}/dependencies.gradle"
local version_name_key="version_name"
local version_name_regex="^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}(-(alpha|beta|rc)[0-9]{2}){0,1}$"

local version
version=$(grep "${version_name_key}" "${build_file}" | sed -E "s/.*${version_name_key}[[:space:]]*=[[:space:]]*[\"\'](.*)[\"\'].*/\1/")
local version=$(sed -n "s/.*${version_name_key}[[:space:]]*=[[:space:]]*[\"\']\(.*\)[\"\'].*/\1/p" ${build_file})

if [[ ! ${version} =~ ${version_name_regex} ]]; then
echo "Error: invalid version name [$version], please validate that [$version_name_key] at [$build_file] follows regex $version_name_regex ."
Expand All @@ -16,4 +15,4 @@ function release_version() {
echo "$version"
}

release_version
release_version

0 comments on commit 6e58dd4

Please sign in to comment.