diff --git a/.github/workflows/pr-release-publish.yml b/.github/workflows/pr-release-publish.yml index f27a5a4a..6679d948 100644 --- a/.github/workflows/pr-release-publish.yml +++ b/.github/workflows/pr-release-publish.yml @@ -126,27 +126,20 @@ jobs: sdk=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}} tools=$(find "$sdk/build-tools" -mindepth 1 -maxdepth 1 -type d | sort -V | tail -1) - # Not releases/latest: gamescope and wlroots releases can hold that mark. The stable app - # release is the newest published one that ships DroidDeck-.apk. - stable_tag=$(gh api "repos/$GITHUB_REPOSITORY/releases?per_page=100" --jq ' - [.[] | select((.draft | not) and (.prerelease | not)) | .tag_name as $t | - select(any(.assets[]; .name == "DroidDeck-\($t).apk"))] | - sort_by(.published_at) | last | .tag_name // empty') - [[ -n "$stable_tag" ]] || { echo "::error::No published DroidDeck release to compare against"; exit 1; } - mkdir -p "$RUNNER_TEMP/stable" "$RUNNER_TEMP/pr" - gh release download "$stable_tag" -R "$GITHUB_REPOSITORY" \ - -p "DroidDeck-$stable_tag.apk" -D "$RUNNER_TEMP/stable" + # A PR build is made from the PR merged onto main, so it must install over main's own + # build. main is what this job checked out; no release has to exist or be marked latest. + main_code=$(sed -n 's/^[[:space:]]*versionCode[[:space:]][[:space:]]*\([0-9][0-9]*\)[[:space:]]*$/\1/p' app/build.gradle) + [[ "$main_code" =~ ^[0-9]+$ ]] || { echo "::error::No numeric versionCode in main's app/build.gradle"; exit 1; } + mkdir -p "$RUNNER_TEMP/pr" gh run download "$run_id" -R "$GITHUB_REPOSITORY" -n droiddeck-apk -D "$RUNNER_TEMP/pr" mapfile -t apks < <(find "$RUNNER_TEMP/pr" -type f -name '*.apk') [[ ${#apks[@]} == 1 ]] || { echo '::error::Expected one PR APK'; exit 1; } package_line() { "$tools/aapt" dump badging "$1" | sed -n "s/^package: name='\\([^']*\\)' versionCode='\\([^']*\\)'.*/\\1 \\2/p" } - stable=$(package_line "$RUNNER_TEMP/stable/DroidDeck-$stable_tag.apk") candidate=$(package_line "${apks[0]}") - [[ "$stable" =~ ^com\.droiddeck\.launcher\ [0-9]+$ && "$candidate" =~ ^com\.droiddeck\.launcher\ [0-9]+$ && - ${candidate##* } -ge ${stable##* } ]] || { - echo "::error::PR package/versionCode '$candidate' cannot install over stable '$stable'"; exit 1; + [[ "$candidate" =~ ^com\.droiddeck\.launcher\ [0-9]+$ && ${candidate##* } -ge $main_code ]] || { + echo "::error::PR package/versionCode '$candidate' cannot install over main (versionCode $main_code)"; exit 1; } current=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER")