From 361b99e9a6c8154596ad2f23c54e13cb5684c584 Mon Sep 17 00:00:00 2001 From: icenine451 Date: Mon, 17 Apr 2023 11:28:58 -0400 Subject: [PATCH] Upgrade pre-build automation --- .github/workflows/cooker-selfhosted.yml | 4 +- .github/workflows/main-selfhosted.yml | 4 +- automation_tools/automation_task_list.cfg | 4 ++ automation_tools/pre_build_automation.sh | 58 +++++++++++++++++++++++ automation_tools/sha_update_list.cfg | 4 -- automation_tools/update_sha.sh | 29 ------------ 6 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 automation_tools/automation_task_list.cfg create mode 100644 automation_tools/pre_build_automation.sh delete mode 100644 automation_tools/sha_update_list.cfg delete mode 100644 automation_tools/update_sha.sh diff --git a/.github/workflows/cooker-selfhosted.yml b/.github/workflows/cooker-selfhosted.yml index dc2c01a4..d840fba3 100644 --- a/.github/workflows/cooker-selfhosted.yml +++ b/.github/workflows/cooker-selfhosted.yml @@ -42,7 +42,7 @@ jobs: io.qt.qtwebengine.BaseApp/x86_64/6.3 \ org.freedesktop.Sdk.Extension.llvm13 \ org.freedesktop.Sdk.Extension.dotnet6/x86_64/21.08 - /bin/bash ${GITHUB_WORKSPACE}/automation_tools/update_sha.sh # Run SHA placehold replacement script for dynamic archives + /bin/bash ${GITHUB_WORKSPACE}/automation_tools/pre_build_automation.sh # Run pre-build automation tasks - name: Build flatpak run: | @@ -92,4 +92,4 @@ jobs: with: name: retrodeck-flatpak path: RetroDECK.flatpak - continue-on-error: true \ No newline at end of file + continue-on-error: true diff --git a/.github/workflows/main-selfhosted.yml b/.github/workflows/main-selfhosted.yml index c3fa9dd4..073ec7c9 100644 --- a/.github/workflows/main-selfhosted.yml +++ b/.github/workflows/main-selfhosted.yml @@ -42,7 +42,7 @@ jobs: io.qt.qtwebengine.BaseApp/x86_64/6.3 \ org.freedesktop.Sdk.Extension.llvm13 \ org.freedesktop.Sdk.Extension.dotnet6/x86_64/21.08 - sh ${GITHUB_WORKSPACE}/automation_tools/update_sha.sh # Run SHA placehold replacement script for dynamic archives + /bin/bash ${GITHUB_WORKSPACE}/automation_tools/pre_build_automation.sh # Run pre-build automation tasks - name: Build flatpak run: | @@ -95,4 +95,4 @@ jobs: with: name: retrodeck-flatpak path: RetroDECK.flatpak - continue-on-error: true \ No newline at end of file + continue-on-error: true diff --git a/automation_tools/automation_task_list.cfg b/automation_tools/automation_task_list.cfg new file mode 100644 index 00000000..6f3c79d2 --- /dev/null +++ b/automation_tools/automation_task_list.cfg @@ -0,0 +1,4 @@ +# The proper format for this file is +# ACTION^PLACEHOLDERTEXT^URL^REPO(Optional) +hash^DOOMSHAPLACEHOLDER^https://buildbot.libretro.com/assets/cores/DOOM/Doom%20%28Shareware%29.zip +hash^VITASHAPLACEHOLDER^https://github.com/Vita3K/Vita3K/releases/download/continuous/ubuntu-latest.zip diff --git a/automation_tools/pre_build_automation.sh b/automation_tools/pre_build_automation.sh new file mode 100644 index 00000000..b02225c4 --- /dev/null +++ b/automation_tools/pre_build_automation.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# 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 +# 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 +# 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 + +rd_manifest=${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml +automation_task_list=${GITHUB_WORKSPACE}/automation_tools/automation_task_list.cfg + +echo "Manifest location: $rd_manifest" +echo "Automation task list location: $automation_task_list" +echo +echo "Task list contents:" +cat "$automation_task_list" +echo + +while IFS="^" read -r action placeholder url branch +do + if [[ ! $action == "#"* ]] && [[ ! -z "$action" ]]; then + if [[ "$action" == "hash" ]]; then + echo + echo "Placeholder text: $placeholder" + echo "URL to hash: $url" + echo + hash=$(curl -sL "$url" | sha256sum | cut -d ' ' -f1) + echo "Hash found: $hash" + /bin/sed -i 's^'"$placeholder"'^'"$hash"'^' $rd_manifest + elif [[ "$action" == "latestcommit" ]]; then + echo + echo "Placeholder text: $placeholder" + echo "Repo to get latest commit from: $url branch: $branch" + echo + commit=$(git ls-remote "$url" "$branch" | cut -f1) + echo "Commit found: $commit" + /bin/sed -i 's^'"$placeholder"'^'"$commit"'^' $rd_manifest + elif [[ "$action" == "latestappimage" ]]; then + echo + echo "Placeholder text: $placeholder" + echo "Repo to look for AppImage releases: $url" + echo + appimageurl=$(curl -s "$url" | grep browser_download_url | grep "\.AppImage\"" | cut -d : -f 2,3 | tr -d \" | sed -n 1p | tr -d ' ') + echo "AppImage URL found: $appimageurl" + /bin/sed -i 's^'"$placeholder"'^'"$appimageurl"'^' $rd_manifest + appimagehash=$(curl -sL "$appimageurl" | sha256sum | cut -d ' ' -f1) + echo "AppImage hash found: $appimagehash" + /bin/sed -i 's^'"HASHFOR$placeholder"'^'"$appimagehash"'^' $rd_manifest + fi + fi +done < "$automation_task_list" diff --git a/automation_tools/sha_update_list.cfg b/automation_tools/sha_update_list.cfg deleted file mode 100644 index e4d06b35..00000000 --- a/automation_tools/sha_update_list.cfg +++ /dev/null @@ -1,4 +0,0 @@ -# The proper format for this file is -# URL^PLACEHOLDERTEXT -https://buildbot.libretro.com/assets/cores/DOOM/Doom%20%28Shareware%29.zip^DOOMSHAPLACEHOLDER -https://github.com/Vita3K/Vita3K/releases/download/continuous/ubuntu-latest.zip^VITASHAPLACEHOLDER diff --git a/automation_tools/update_sha.sh b/automation_tools/update_sha.sh deleted file mode 100644 index 5bcbc8ee..00000000 --- a/automation_tools/update_sha.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# For the file paths to work correctly, call this script with this command from the cloned repo folder root: -# sh automation_tools/update_sha.sh - -rd_manifest=${GITHUB_WORKSPACE}/net.retrodeck.retrodeck.yml -sha_update_list=${GITHUB_WORKSPACE}/automation_tools/sha_update_list.cfg - -echo "Manifest location: $rd_manifest" -echo "Hash update list location: $sha_update_list" -echo -echo "Update list contents:" -cat "$sha_update_list" -echo - -while IFS="^" read -r url placeholder -do - if [[ ! "$url" == "#"* ]] && [[ ! -z "$url" ]]; then - echo - echo "Placeholder text: $placeholder" - echo "URL to hash: $url" - echo - hash=$(curl -sL "$url" | sha256sum | cut -d ' ' -f1) - echo "Hash found: $hash" - /bin/sed -i 's^'"$placeholder"'^'"$hash"'^' $rd_manifest - fi -done < "$sha_update_list" - -echo "Done updating manifest hashes."