Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions scripts/pre_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,36 @@ source scripts/helpers.sh

# Get number of the latest OSIDB version
get_new_version() {
osidb_github_base_link="https://api.github.com/repos/RedHatProductSecurity/osidb"
osidb_repo_url="https://github.com/RedHatProductSecurity/osidb.git"

# Get latest OSIDB release branch name
local curl_args=(-s -f "${osidb_github_base_link}/branches" -f -w 'HTTPSTATUS:%{http_code}\n')
if [ -n "${GITHUB_API_TOKEN}" ]; then
curl_args+=(-H \"Authorization: Bearer ${GITHUB_API_TOKEN}\")
fi
local response=$(curl "${curl_args[@]}")

local body=$(echo ${response} | sed -E 's/HTTPSTATUS\:[0-9]{3}$//')
local status=$(echo ${response} | tr -d '\n' | sed -E 's/.*HTTPSTATUS:([0-9]{3})$/\1/')
# Get latest OSIDB release branch name using git ls-remote
latest_osidb_release_branch=$(git ls-remote --heads "${osidb_repo_url}" 'release-*' | \
sed 's|.*/||' | \
grep -E '^release-[0-9]+\.[0-9]+\.[0-9]+$' | \
sort -r -V | head -n 1)

if [ ! ${status} -eq 200 ]; then
echo "Error accessing \"${osidb_github_base_link}/branches\" [HTTP status: ${status}]"
if [ -z "${latest_osidb_release_branch}" ]; then
echo "Error: Could not fetch release branches from ${osidb_repo_url}"
exit 1
fi

latest_osidb_release_branch=$(echo ${body} | jq -r '.[] | .name | select(match("^release-[0-9]+\\.[0-9]+\\.[0-9]+$"))' |\
sort -r -V | head -n 1)
latest_osidb_version=${latest_osidb_release_branch#"release-"}
local split_osidb_version=($(echo "${latest_osidb_version}" | tr "." '\n'))
IFS='.' read -ra split_osidb_version <<< "${latest_osidb_version}"

# PATCH version is not synced between OSIDB and bindings, set it to zero
split_osidb_version[2]="0"

# Get latest tagged bindings version
latest_bindings_version=$(git tag --sort '-authordate' | head -n 1)
local split_bindings_version=($(echo "${latest_bindings_version}" | tr "." '\n'))
latest_bindings_version=$(git tag --sort=-v:refname | head -n 1)
IFS='.' read -ra split_bindings_version <<< "${latest_bindings_version}"

# Based on the versions check whether the major/minor release is needed
if [ ${split_osidb_version[0]} -gt ${split_bindings_version[0]} ]; then
echo "New major version of OSIDB found [${latest_osidb_version}]"
new_version=$(echo $(local IFS="." ; echo "${split_osidb_version[*]}"))
new_version=$(IFS='.'; echo "${split_osidb_version[*]}")
elif [ ${split_osidb_version[1]} -gt ${split_bindings_version[1]} ];then
echo "New minor version of OSIDB found [${latest_osidb_version}]"
new_version=$(echo $(local IFS="." ; echo "${split_osidb_version[*]}"))
new_version=$(IFS='.'; echo "${split_osidb_version[*]}")
else
echo "No new major or minor version of OSIDB. Release is not needed."
echo "OSIDB latest version: ${latest_osidb_version}"
Expand Down
29 changes: 10 additions & 19 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,31 @@ source scripts/helpers.sh

# Get number of the latest OSIDB version
get_new_version() {
osidb_github_base_link="https://api.github.com/repos/RedHatProductSecurity/osidb"
osidb_repo_url="https://github.com/RedHatProductSecurity/osidb.git"

# Get latest tagged OSIDB version
local curl_args=(-s -f "${osidb_github_base_link}/tags" -f -w 'HTTPSTATUS:%{http_code}\n')
if [ -n "${GITHUB_API_TOKEN}" ]; then
curl_args+=(-H \"Authorization: Bearer ${GITHUB_API_TOKEN}\")
fi
local response=$(curl "${curl_args[@]}")

local body=$(echo ${response} | sed -E 's/HTTPSTATUS\:[0-9]{3}$//')
local status=$(echo ${response} | tr -d '\n' | sed -E 's/.*HTTPSTATUS:([0-9]{3})$/\1/')
# Get latest tagged OSIDB version using git ls-remote
latest_osidb_version=$(git ls-remote --tags --refs --sort=-v:refname "${osidb_repo_url}" | head -n 1 | sed 's/.*refs\/tags\///')

if [ ! ${status} -eq 200 ]; then
echo "Error accessing \"${osidb_github_base_link}/tags\" [HTTP status: ${status}]"
if [ -z "${latest_osidb_version}" ]; then
echo "Error: Could not fetch tags from ${osidb_repo_url}"
exit 1
fi

latest_osidb_version=$(echo ${body} | jq -r ".[0] | .name")
local split_osidb_version=($(echo "${latest_osidb_version}" | tr "." '\n'))
IFS='.' read -ra split_osidb_version <<< "${latest_osidb_version}"

# PATCH version is not synced between OSIDB and bindings, set it to zero
split_osidb_version[2]="0"

# Get latest tagged bindings version
latest_bindings_version=$(git tag --sort '-authordate' | head -n 1)
local split_bindings_version=($(echo "${latest_bindings_version}" | tr "." '\n'))
latest_bindings_version=$(git tag --sort=-v:refname | head -n 1)
IFS='.' read -ra split_bindings_version <<< "${latest_bindings_version}"

# Based on the versions check whether the major/minor release is needed
if [ ${split_osidb_version[0]} -gt ${split_bindings_version[0]} ]; then
echo "New major version of OSIDB found [${latest_osidb_version}]"
new_version=$(echo $(local IFS="." ; echo "${split_osidb_version[*]}"))
new_version=$(IFS='.'; echo "${split_osidb_version[*]}")
elif [ ${split_osidb_version[1]} -gt ${split_bindings_version[1]} ];then
echo "New minor version of OSIDB found [${latest_osidb_version}]"
new_version=$(echo $(local IFS="." ; echo "${split_osidb_version[*]}"))
new_version=$(IFS='.'; echo "${split_osidb_version[*]}")
else
echo "No new major or minor version of OSIDB. Release is not needed."
echo "OSIDB latest version: ${latest_osidb_version}"
Expand Down