feat/auto version (#1072)

* MANIFEST: Update version initialization to dynamically extract version from metainfo XML

* BUILD: now version is automated and taken from the metainfo
This commit is contained in:
XargonWan 2025-03-29 09:59:02 +09:00 committed by GitHub
parent aa5374d7fd
commit 8be9782ff7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 89 deletions

1
.gitignore vendored
View file

@ -28,6 +28,7 @@ placeholders.cache
RetroDECK*Artifact.tar.gz RetroDECK*Artifact.tar.gz
./gits ./gits
flathub.json flathub.json
./version
# Components artifacts # # Components artifacts #
############################ ############################

View file

@ -7,4 +7,10 @@ capitalized_word2="$(tr '[:lower:]' '[:upper:]' <<< ${word2:0:1})${word2:1}"
result=$capitalized_word1$capitalized_word2 result=$capitalized_word1$capitalized_word2
echo $result > ${GITHUB_WORKSPACE}/buildid echo $result > ${GITHUB_WORKSPACE}/buildid
echo "BUILD_ID=$result" >> $GITHUB_ENV echo "BUILD_ID=$result" >> $GITHUB_ENV
echo "VersionID is $result" echo "VersionID is $result"
source automation_tools/version_extractor.sh
VERSION=$(fetch_metainfo_version)
echo "$VERSION" > ${GITHUB_WORKSPACE}/version
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Version is $VERSION"

View file

@ -1,63 +0,0 @@
#!/bin/bash
# This script is used to check that the versions are correct and stopping the pipeline if something is wrong.
# This is designed to be run on the main pipeline to check that everything is in order before building RetroDECK.
source automation_tools/version_extractor.sh
# Set the file paths
metainfo="net.retrodeck.retrodeck.metainfo.xml"
manifest="net.retrodeck.retrodeck.yml"
manifest_content=$(cat "$manifest")
compare_versions() {
local manifest_version_cleaned=$(echo "$1" | sed 's/[a-zA-Z]//g')
local metainfo_version_cleaned=$(echo "$2" | sed 's/[a-zA-Z]//g')
if [[ "$manifest_version_cleaned" == "$metainfo_version_cleaned" ]]; then
return 0 # Versions are equal
fi
local IFS=.
local manifest_parts=($manifest_version_cleaned)
local metainfo_parts=($metainfo_version_cleaned)
for ((i=0; i<${#manifest_parts[@]}; i++)); do
if ((manifest_parts[i] > metainfo_parts[i])); then
return 1 # Manifest version is greater
elif ((manifest_parts[i] < metainfo_parts[i])); then
return 2 # Metainfo version is greater
fi
done
return 0 # Versions are equal
}
repo_version=$(fetch_repo_version)
echo -e "Online repository:\t$repo_version"
manifest_version=$(fetch_manifest_version)
echo -e "Manifest:\t\t$manifest_version"
metainfo_version=$(fetch_metainfo_version)
echo -e "Metainfo:\t\t$metainfo_version"
# Additional checks
if [[ "$manifest_version" == "main" || "$manifest_version" == "THISBRANCH" || "$manifest_version" == *"cooker"* ]]; then
echo "Manifest version cannot be 'main', 'THISBRANCH', or contain 'cooker'. Please fix it."
exit 1
fi
if [[ "$metainfo_version" != "$manifest_version" ]]; then
echo "Metainfo version is not equal to manifest version. Please fix it."
exit 1
fi
compare_versions "$repo_version" "$manifest_version"
result=$?
if [ "$result" -eq 1 ]; then
echo "Repository version is less than manifest version. Please fix it."
exit 1
fi
echo "All checks passed. Well done!"

View file

@ -3,12 +3,9 @@
# This script is intended to gather version information from various sources: # This script is intended to gather version information from various sources:
# RetroDECK repository # RetroDECK repository
# Metainfo.xml file # Metainfo.xml file
# Manifest YAML file
# It consists of three functions, each responsible for retrieving a specific version-related data. # It consists of three functions, each responsible for retrieving a specific version-related data.
metainfo="net.retrodeck.retrodeck.metainfo.xml" metainfo="net.retrodeck.retrodeck.metainfo.xml"
manifest="net.retrodeck.retrodeck.yml"
manifest_content=$(cat "$manifest")
fetch_repo_version(){ fetch_repo_version(){
# Getting latest RetroDECK release info # Getting latest RetroDECK release info
@ -20,17 +17,9 @@ fetch_repo_version(){
} }
fetch_metainfo_version(){ fetch_metainfo_version(){
# Extract the version from the net.retrodeck.retrodeck.metainfo.xml file # Extract the version number from the metainfo XML file
metainfo_version=$(grep -oPm1 "(?<=<release version=\")[^\"]+" "$metainfo") VERSION=$(xmlstarlet sel -t -v "/component/releases/release[1]/@version" net.retrodeck.retrodeck.metainfo.xml)
echo "$metainfo_version" echo "$VERSION"
}
fetch_manifest_version(){
# Use awk to extract the value of the first iteration of VERSION variable
manifest_version=$(echo "$manifest_content" | awk '/VERSION=/ && !/#/ { sub(/.*VERSION=/, ""); sub(/#.*/, ""); print; exit }')
# Trim leading and trailing whitespace
manifest_version=$(echo "$manifest_version" | awk '{$1=$1;print}')
echo "$manifest_version"
} }
echo "Version extractor functions loaded" echo "Version extractor functions loaded"

View file

@ -75,8 +75,7 @@ modules:
# The version number is hardcoded in /app/retrodeck/version # The version number is hardcoded in /app/retrodeck/version
# #
# UPDATE STEPS FOR MAIN: # UPDATE STEPS FOR MAIN:
# [X] Update the VERSION variable in retrodeck-initialization module # [ ] Update the net.retrodeck.retrodeck.metainfo.xml with the version number, date and notes
# [X] Update the net.retrodeck.retrodeck.metainfo.xml with the version number, date and notes
- name: retrodeck-initialization - name: retrodeck-initialization
buildsystem: simple buildsystem: simple
@ -84,18 +83,26 @@ modules:
- | - |
# VERSION INITIALIZATION # VERSION INITIALIZATION
# on main please update this with the version variable, eg: VERSION=0.8.0b # If the current Git branch is not 'main', append 'cooker-' to the version number
# on cooker will be VERSION=cooker-0.9.0b for example if [[ "${GITHUB_REF_NAME}" != "main" ]]; then
VERSION=cooker-0.9.2b VERSION="cooker-$(cat ./version)-$(cat buildid)"
else # Otherwise, if we're on main, use the version number as is
git checkout ${GITHUB_REF_NAME} VERSION=$(cat ./version)
mkdir -p ${FLATPAK_DEST}/retrodeck/
if [[ $VERSION == *"cooker"* ]];
then
VERSION="$VERSION-VERSIONPLACEHOLDER"
fi fi
# Check out the current Git branch
git checkout ${GITHUB_REF_NAME}
# Create the retrodeck directory in the Flatpak destination
mkdir -p ${FLATPAK_DEST}/retrodeck/
# Write the version number to the retrodeck version file
echo $VERSION >> ${FLATPAK_DEST}/retrodeck/version echo $VERSION >> ${FLATPAK_DEST}/retrodeck/version
# Display the contents of the version file
cat ${FLATPAK_DEST}/retrodeck/version cat ${FLATPAK_DEST}/retrodeck/version
# Print the version number to the console
echo "Version is $VERSION" echo "Version is $VERSION"
# LIBMAN INSTALLATION # LIBMAN INSTALLATION