From 80196fe7f08b74387e07be91ac98d9f50d20394e Mon Sep 17 00:00:00 2001 From: icenine451 Date: Wed, 24 Jan 2024 10:48:56 -0500 Subject: [PATCH] Build automation updates - Added "custom_command" option to run arbitrary command explicitly - Split "outside_file" and "outside_env_var" options to accomodate both types of data - Changed from elif to case - Added more informational comments --- automation_tools/automation_task_list.cfg | 2 +- automation_tools/pre_build_automation.sh | 54 +++++++++++++++++++---- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/automation_tools/automation_task_list.cfg b/automation_tools/automation_task_list.cfg index 7a60c9d4..1b955846 100644 --- a/automation_tools/automation_task_list.cfg +++ b/automation_tools/automation_task_list.cfg @@ -11,5 +11,5 @@ hash^RANIGHTLYCORESPLACEHOLDER^https://buildbot.libretro.com/nightly/linux/x86_6 hash^RETRODECKMAMEPLACEHOLDER^"https://github.com/XargonWan/RetroDECK-MAME/releases/download/$(curl -s https://api.github.com/repos/XargonWan/RetroDECK-MAME/releases/latest | grep -oP '"tag_name": "\K(.*?)(?=")')/RetroDECK-MAME-Artifact.tar.gz" url^RETRODECKMAMEURLPLACEHOLDER^"https://github.com/XargonWan/RetroDECK-MAME/releases/download/$(curl -s https://api.github.com/repos/XargonWan/RetroDECK-MAME/releases/latest | grep -oP '"tag_name": "\K(.*?)(?=")')/RetroDECK-MAME-Artifact.tar.gz" latestcommit^UNIVERSALDYNAMICINPUTCOMMITPLACEHOLDER^https://github.com/Venomalia/UniversalDynamicInput^main -outside_info^VERSIONPLACEHOLDER^${GITHUB_WORKSPACE}/buildid +outside_file^VERSIONPLACEHOLDER^${GITHUB_WORKSPACE}/buildid branch^THISBRANCH diff --git a/automation_tools/pre_build_automation.sh b/automation_tools/pre_build_automation.sh index 9c363c96..bcca05c4 100755 --- a/automation_tools/pre_build_automation.sh +++ b/automation_tools/pre_build_automation.sh @@ -3,15 +3,21 @@ # For the file paths to work correctly, call this script with this command from the cloned repo folder root: # sh automation_tools/pre_build_automation.sh # Different actions need different information in the task list file +# branch: This changes the placeholder text to the currently-detected GIT branch if an automated build was started from a PR environment. # hash: Finds the SHA256 hash of a file online and updates the placeholder in the manifest. # Needs the URL of the file, in this line format: hash^PLACEHOLDERTEXT^url # latestcommit: Finds the most recent commit of a git repo and updated the placeholder in the manifest. # Needs the URL of the repo and the branch to find the latest commit from, in this line format: latestcommit^PLACEHOLDERTEXT^url^branch -# latestappimage: Finds the download URL and SHA256 hash of the latest AppImage release from a git repo +# latestappimage: Finds the download URL and SHA256 hash of the latest AppImage release from a git repo. # Needs the API URL of the repo, in this line format: latestappimage^PLACEHOLDERTEXT^https://api.github.com/repos///releases/latest # As this command updates two different placeholders (one for the URL, one for the file hash) in the manifest, # the URL that would be used in the above example is "PLACEHOLDERTEXT" and the hash placeholder text would be "HASHPLACEHOLDERTEXT" # The "HASH" prefix of the placeholder text is hardcoded in the script +# outside_file: Prints the contents of a file from the build environment (such as the buildid file) and replaces the placeholder text with those contents. +# outside_env_var: Gets the value of an environmental variable from the build environment (the output of "echo $var" from the terminal) and replaces the placeholder text with that value. +# custom_command: Runs a single command explicitly as written in the $URL field of the task list, including variable and command expansion. This should work the same as if you were runnig the command directly from the terminal. +# This command does not need a PLACEHOLDERTEXT field in the task list, so needs to be in this syntax: custom_command^^$COMMAND +# url: This is used to calculate a dynamic URL and the value to the $caluculated_url environmental variable, for use in other subsequent commands. rd_manifest=${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml automation_task_list=${GITHUB_WORKSPACE}/automation_tools/automation_task_list.cfg @@ -35,13 +41,17 @@ echo while IFS="^" read -r action placeholder url branch do if [[ ! $action == "#"* ]] && [[ ! -z "$action" ]]; then - if [[ "$action" == "branch" ]]; then + case "$action" in + + "branch" ) echo echo "Placeholder text: $placeholder" echo "Current branch:" "$current_branch" echo /bin/sed -i 's^'"$placeholder"'^'"$current_branch"'^g' $rd_manifest - elif [[ "$action" == "hash" ]]; then + ;; + + "hash" ) echo echo "Placeholder text: $placeholder" calculated_url=$(eval echo "$url") # in case the url has to be calculated from an expression @@ -50,7 +60,9 @@ do hash=$(curl -sL "$calculated_url" | sha256sum | cut -d ' ' -f1) echo "Hash found: $hash" /bin/sed -i 's^'"$placeholder"'^'"$hash"'^' $rd_manifest - elif [[ "$action" == "latestcommit" ]]; then + ;; + + "latestcommit" ) echo echo "Placeholder text: $placeholder" echo "Repo to get latest commit from: $url branch: $branch" @@ -58,7 +70,9 @@ do commit=$(git ls-remote "$url" "$branch" | cut -f1) echo "Commit found: $commit" /bin/sed -i 's^'"$placeholder"'^'"$commit"'^' $rd_manifest - elif [[ "$action" == "latestappimage" ]]; then + ;; + + "latestappimage" ) echo echo "Placeholder text: $placeholder" echo "Repo to look for AppImage releases: $url" @@ -69,7 +83,9 @@ do appimagehash=$(curl -sL "$appimageurl" | sha256sum | cut -d ' ' -f1) echo "AppImage hash found: $appimagehash" /bin/sed -i 's^'"HASHFOR$placeholder"'^'"$appimagehash"'^' $rd_manifest - elif [[ "$action" == "outside_info" ]]; then + ;; + + "outside_file" ) if [[ "$url" = \$* ]]; then # If value is a reference to a variable name eval url="$url" fi @@ -78,7 +94,27 @@ do echo "Information being injected: $(cat $url)" echo /bin/sed -i 's^'"$placeholder"'^'"$(cat $url)"'^' $rd_manifest - elif [[ "$action" == "url" ]]; then + ;; + + "outside_env_var" ) + if [[ "$url" = \$* ]]; then # If value is a reference to a variable name + eval url="$url" + fi + echo + echo "Placeholder text: $placeholder" + echo "Information being injected: $(echo $url)" + echo + /bin/sed -i 's^'"$placeholder"'^'"$(echo $url)"'^' $rd_manifest + ;; + + "custom_command" ) + echo + echo "Command to run: $url" + echo + eval "$url" + ;; + + "url" ) # this is used to calculate a dynamic url echo echo "Placeholder text: $placeholder" @@ -86,6 +122,8 @@ do echo "Information being injected: $calculated_url" echo /bin/sed -i 's^'"$placeholder"'^'"$calculated_url"'^' $rd_manifest - fi + ;; + + esac fi done < "$automation_task_list"