Skip to content
Draft
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
90 changes: 80 additions & 10 deletions shared-overwrite/.github/workflows/mt-record-screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ env:
MT_IS_AGENCY_REPO: ${{ ! contains(fromJSON('["mtransitapps/commons", "mtransitapps/commons-java", "mtransitapps/parser", "mtransitapps/commons-android"]'), github.repository) && ! endsWith(github.repository, '/mtransit-for-android')}}
MT_IS_AGENCY_RDS: ${{ ! contains(github.repository, '-bike-') }}
MT_IS_AGENCY_BIKE: ${{ contains(github.repository, '-bike-') }}
# modules to install for screenshots (one per line: pkg:repo_url)
MT_MODULES: |
org.mtransit.android.ca_montreal_amt_train:https://github.com/mtransitapps/ca-montreal-amt-train-android
org.mtransit.android.ca_montreal_stm_subway:https://github.com/mtransitapps/ca-montreal-stm-subway-android
# git commit & push
MT_ORG_GIT_COMMIT_ON: ${{ secrets.MT_ORG_GIT_COMMIT_ON }}
MT_ORG_GIT_COMMIT_OFF: ${{ secrets.MT_ORG_GIT_COMMIT_OFF }}
Expand All @@ -45,7 +49,7 @@ jobs:
MT-RECORD-SCREENSHOTS-JOB:
name: "MT record screenshots"
# if: ${{ env.MT_IS_MAIN_REPO != 'true' }} # can NOT use env here:
if: ${{ ! endsWith(github.repository, '/mtransit-for-android') && github.event_name != 'pull_request' }}
if: ${{ github.event_name != 'pull_request' }}
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
Expand All @@ -72,6 +76,7 @@ jobs:

- name: MT download main app release APK
id: download-main-apk
if: ${{ env.MT_IS_MAIN_REPO != 'true' }}
run: |
source ./download_latest_apk.sh "mtransitapps/mtransit-for-android"
if [[ -z "$APK_FILE" ]]; then
Expand All @@ -84,7 +89,7 @@ jobs:
GH_TOKEN: ${{ secrets.MT_PAT }}

- name: MT download this app release APK
id: download-module-apk
id: download-this-repo-apk
if: github.event.inputs.buildFromSource != 'true'
continue-on-error: true
run: |
Expand All @@ -95,14 +100,24 @@ jobs:
echo "WARNING: no APK file!"
exit 1 # triggers fallback step
fi
echo "MODULE_APK_FILE=$APK_FILE" >> $GITHUB_OUTPUT
echo "Module app APK downloaded successfully."
if [[ "$MT_IS_MAIN_REPO" == "true" ]]; then
echo "MAIN_APK_FILE=$APK_FILE" >> $GITHUB_OUTPUT
echo "Main app APK downloaded successfully."
else
MODULE_PACKAGE=$(cat "config/pkg")
if [[ -z "$MODULE_PACKAGE" ]]; then
echo "ERROR: package name not found in config/pkg"
exit 1
fi
echo "MODULE_APK_FILES=${MODULE_PACKAGE}:${APK_FILE}" >> $GITHUB_OUTPUT
echo "Module app APK downloaded successfully."
fi
env:
GH_TOKEN: ${{ secrets.MT_PAT }}

- name: MT build this app release APK (fallback)
if: steps.download-module-apk.outcome == 'failure' || github.event.inputs.buildFromSource == 'true'
id: build-module-apk
if: steps.download-this-repo-apk.outcome == 'failure' || github.event.inputs.buildFromSource == 'true'
id: build-this-repo-apk
env:
MT_ENCRYPT_KEY: ${{ secrets.MT_ENCRYPT_KEY }}
run: |
Expand All @@ -127,12 +142,67 @@ jobs:
echo "ERROR: APK file not found in ./app-android/build/outputs/apk/release/"
exit 1
fi
echo "MODULE_APK_FILE=$APK_FILE" >> $GITHUB_OUTPUT
echo "Module app APK assembled successfully at: $APK_FILE"
if [[ "$MT_IS_MAIN_REPO" == "true" ]]; then
echo "MAIN_APK_FILE=$APK_FILE" >> $GITHUB_OUTPUT
echo "Main app APK assembled successfully at: $APK_FILE"
else
MODULE_PACKAGE=$(cat "config/pkg")
if [[ -z "$MODULE_PACKAGE" ]]; then
echo "ERROR: package name not found in config/pkg"
exit 1
fi
echo "MODULE_APK_FILES=${MODULE_PACKAGE}:${APK_FILE}" >> $GITHUB_OUTPUT
echo "Module app APK assembled successfully at: $APK_FILE"
fi

- name: MT validate main repo requires modules env var
if: ${{ env.MT_IS_MAIN_REPO == 'true' && env.MT_MODULES == '' }}
run: |
echo "ERROR: MT_MODULES env var is required when running for the main repo!"
echo "Expected format: one 'pkg:repo_url' per line."
exit 1

- name: MT download module APKs
id: download-modules-apks
if: ${{ env.MT_MODULES != '' }}
run: |
MANIFEST_FILE="module_apks_manifest.txt"
> "$MANIFEST_FILE"
while IFS= read -r MODULE_LINE; do
[ -z "$MODULE_LINE" ] && continue
PKG="${MODULE_LINE%%:*}"
REPO="${MODULE_LINE#*:}"
if [[ -z "$PKG" || -z "$REPO" || "$PKG" == "$REPO" ]]; then
echo "ERROR: invalid MT_MODULES line '$MODULE_LINE' (expected pkg:repo_url)."
exit 1
fi
echo "Downloading APK for '$PKG' from '$REPO'..."
source ./download_latest_apk.sh "$REPO"
if [[ -z "$APK_FILE" ]]; then
echo "ERROR: no APK file for '$PKG' from '$REPO'!"
exit 1
fi
echo "${PKG}:${APK_FILE}" >> "$MANIFEST_FILE"
echo " Module '$PKG' downloaded: $APK_FILE"
done <<< "$MT_MODULES"
{
echo "MODULE_APK_FILES<<EOF"
cat "$MANIFEST_FILE"
echo "EOF"
} >> $GITHUB_OUTPUT
echo "All module APKs downloaded."
env:
GH_TOKEN: ${{ secrets.MT_PAT }}

- name: MT read timezone from XML resource value
id: timezone
run: |
if [[ "$MT_IS_MAIN_REPO" == "true" ]]; then
echo "Main repo detected: using America/Montreal timezone."
echo "TIMEZONE=America/Montreal" >> $GITHUB_OUTPUT
exit 0
fi

command -v "xmllint" >/dev/null 2>&1 || (sudo apt-get update && sudo apt-get install -y "libxml2-utils")
GTFS_TIMEZONE_XML_FILE="app-android/src/main/res/values/gtfs_rts_values_gen.xml"
BIKE_TIMEZONE_XML_FILE="app-android/src/main/res/values/bike_station_values.xml"
Expand Down Expand Up @@ -163,8 +233,8 @@ jobs:
timeout-minutes: 10
env:
TZ: ${{ steps.timezone.outputs.TIMEZONE || 'UTC' }}
MAIN_APK_FILE: ${{ steps.download-main-apk.outputs.MAIN_APK_FILE }}
MODULE_APK_FILE: ${{ steps.download-module-apk.outputs.MODULE_APK_FILE || steps.build-module-apk.outputs.MODULE_APK_FILE }}
MAIN_APK_FILE: ${{ steps.download-main-apk.outputs.MAIN_APK_FILE || steps.download-this-repo-apk.outputs.MAIN_APK_FILE || steps.build-this-repo-apk.outputs.MAIN_APK_FILE }}
MODULE_APK_FILES: ${{ steps.download-modules-apks.outputs.MODULE_APK_FILES || steps.download-this-repo-apk.outputs.MODULE_APK_FILES || steps.build-this-repo-apk.outputs.MODULE_APK_FILES }}
with:
api-level: ${{ steps.sdk-target.outputs.API_LEVEL }}
target: google_apis
Expand Down
2 changes: 1 addition & 1 deletion shared/download_latest_apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if [[ -z "$APK_FILE" ]]; then
fi

echo "Downloading '$APK_FILE'..."
if ! gh release download -R "$REPO" --pattern "$APK_FILE" >/dev/null; then
if ! gh release download -R "$REPO" --pattern "$APK_FILE" --skip-existing >/dev/null; then
echo "ERROR: Could not download APK from latest release!"
exit 1 #error
fi
Expand Down
158 changes: 88 additions & 70 deletions shared/setup-and-all-app-screenshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# 1. Installs the main mtransit-for-android app (APK path from env var)
# 2. Grants location permission to the main app
# 3. Sets GPS location based on GTFS area bounds
# 4. Installs the current repository's module app (APK path from env var)
# 4. Installs module app(s) from MODULE_APK_FILES (newline list, item = pkg:apkPath)
# 5. Calls the screenshot recording script

set -e
Expand All @@ -26,28 +26,32 @@ if [ ! -f "$MAIN_APK_FILE" ]; then
exit 1
fi

if [ -z "$MODULE_APK_FILE" ]; then
echo " > ERROR: MODULE_APK_FILE environment variable not set"
if [ -z "$MODULE_APK_FILES" ]; then
echo " > ERROR: MODULE_APK_FILES environment variable not set"
exit 1
fi

if [ ! -f "$MODULE_APK_FILE" ]; then
echo " > ERROR: module APK file not found: $MODULE_APK_FILE"
exit 1
fi
# Validate every MODULE_APK_FILES entry before installation.
while IFS= read -r MODULE_ENTRY; do
[ -z "$MODULE_ENTRY" ] && continue

# Get the package name from config/pkg if it exists
CONFIG_PKG_FILE="config/pkg"
if [ ! -f "$CONFIG_PKG_FILE" ]; then
echo " > ERROR: $CONFIG_PKG_FILE not found"
exit 1
fi
if [[ "$MODULE_ENTRY" != *:* ]]; then
echo " > ERROR: invalid MODULE_APK_FILES entry (expected pkg:apkPath): $MODULE_ENTRY"
exit 1
fi

MODULE_PACKAGE=$(cat "$CONFIG_PKG_FILE")
if [ -z "$MODULE_PACKAGE" ]; then
echo " > ERROR: $MODULE_PACKAGE not found in $CONFIG_PKG_FILE"
exit 1
fi
MODULE_PKG="${MODULE_ENTRY%%:*}"
MODULE_APK="${MODULE_ENTRY#*:}"
if [ -z "$MODULE_PKG" ] || [ -z "$MODULE_APK" ]; then
echo " > ERROR: invalid MODULE_APK_FILES entry (empty pkg/apk): $MODULE_ENTRY"
exit 1
fi

if [ ! -f "$MODULE_APK" ]; then
echo " > ERROR: module APK file not found: $MODULE_APK"
exit 1
fi
done <<< "$MODULE_APK_FILES"

echo " - Installing main app from: $MAIN_APK_FILE"
adb install -r -d "$MAIN_APK_FILE"
Expand All @@ -70,69 +74,83 @@ echo " - Location permissions granted"

echo ">> Step 2.5: Set emulator GPS location..."

# Parse GPS coordinates from XML if available
GPS_XML_FILE="app-android/src/main/res-current/values/current_gtfs_rts_values_gen.xml"
if [ -f "$GPS_XML_FILE" ]; then
echo " - Found GPS coordinates file: $GPS_XML_FILE"

# Extract min/max lat/lng values using xmllint
MIN_LAT=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_min_lat']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LAT=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_max_lat']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")
MIN_LNG=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_min_lng']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LNG=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_max_lng']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")

if [ -n "$MIN_LAT" ] && [ -n "$MAX_LAT" ] && [ -n "$MIN_LNG" ] && [ -n "$MAX_LNG" ]; then
# Calculate center point (average of min and max)
CENTER_LAT=$(echo "scale=6; ($MIN_LAT + $MAX_LAT) / 2" | bc)
CENTER_LNG=$(echo "scale=6; ($MIN_LNG + $MAX_LNG) / 2" | bc)
REPO_NAME=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")

if [[ "$REPO_NAME" == "mtransit-for-android" ]]; then
MAIN_APP_SCREENSHOT_LAT="45.5230433"
MAIN_APP_SCREENSHOT_LNG="-73.5814131"
echo " - Main app repo detected ('$REPO_NAME'): setting GPS to $MAIN_APP_SCREENSHOT_LAT, $MAIN_APP_SCREENSHOT_LNG"
adb emu geo fix "$MAIN_APP_SCREENSHOT_LNG" "$MAIN_APP_SCREENSHOT_LAT"
echo " - GPS location set successfully"
else
# Parse GPS coordinates from XML if available
GPS_XML_FILE="app-android/src/main/res-current/values/current_gtfs_rts_values_gen.xml"
if [ -f "$GPS_XML_FILE" ]; then
echo " - Found GPS coordinates file: $GPS_XML_FILE"

echo " - Setting GPS location to center: $CENTER_LAT, $CENTER_LNG"
adb emu geo fix "$CENTER_LNG" "$CENTER_LAT"
# Extract min/max lat/lng values using xmllint
MIN_LAT=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_min_lat']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LAT=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_max_lat']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")
MIN_LNG=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_min_lng']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LNG=$(xmllint --xpath "string(//resources/string[@name='current_gtfs_rts_area_max_lng']/text())" "$GPS_XML_FILE" 2>/dev/null || echo "")

echo " - GPS location set successfully"
else
echo " > WARNING: Could not parse GPS coordinates from XML"
fi
elif [ -f "app-android/src/main/res/values/bike_station_values.xml" ]; then
BIKE_GPS_XML_FILE="app-android/src/main/res/values/bike_station_values.xml"
echo " - Found bike station coordinates file: $BIKE_GPS_XML_FILE"

# Extract min/max lat/lng values using xmllint
MIN_LAT=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_min_lat']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LAT=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_max_lat']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")
MIN_LNG=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_min_lng']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LNG=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_max_lng']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")

if [ -n "$MIN_LAT" ] && [ -n "$MAX_LAT" ] && [ -n "$MIN_LNG" ] && [ -n "$MAX_LNG" ]; then
# Calculate center point (average of min and max)
CENTER_LAT=$(echo "scale=6; ($MIN_LAT + $MAX_LAT) / 2" | bc)
CENTER_LNG=$(echo "scale=6; ($MIN_LNG + $MAX_LNG) / 2" | bc)
if [ -n "$MIN_LAT" ] && [ -n "$MAX_LAT" ] && [ -n "$MIN_LNG" ] && [ -n "$MAX_LNG" ]; then
# Calculate center point (average of min and max)
CENTER_LAT=$(echo "scale=6; ($MIN_LAT + $MAX_LAT) / 2" | bc)
CENTER_LNG=$(echo "scale=6; ($MIN_LNG + $MAX_LNG) / 2" | bc)

echo " - Setting GPS location to center: $CENTER_LAT, $CENTER_LNG"
adb emu geo fix "$CENTER_LNG" "$CENTER_LAT"

echo " - GPS location set successfully"
else
echo " > WARNING: Could not parse GPS coordinates from XML"
fi
elif [ -f "app-android/src/main/res/values/bike_station_values.xml" ]; then
BIKE_GPS_XML_FILE="app-android/src/main/res/values/bike_station_values.xml"
echo " - Found bike station coordinates file: $BIKE_GPS_XML_FILE"

echo " - Setting GPS location to center: $CENTER_LAT, $CENTER_LNG"
adb emu geo fix "$CENTER_LNG" "$CENTER_LAT"
# Extract min/max lat/lng values using xmllint
MIN_LAT=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_min_lat']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LAT=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_max_lat']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")
MIN_LNG=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_min_lng']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")
MAX_LNG=$(xmllint --xpath "string(//resources/string[@name='bike_station_area_max_lng']/text())" "$BIKE_GPS_XML_FILE" 2>/dev/null || echo "")

echo " - GPS location set successfully"
if [ -n "$MIN_LAT" ] && [ -n "$MAX_LAT" ] && [ -n "$MIN_LNG" ] && [ -n "$MAX_LNG" ]; then
# Calculate center point (average of min and max)
CENTER_LAT=$(echo "scale=6; ($MIN_LAT + $MAX_LAT) / 2" | bc)
CENTER_LNG=$(echo "scale=6; ($MIN_LNG + $MAX_LNG) / 2" | bc)

echo " - Setting GPS location to center: $CENTER_LAT, $CENTER_LNG"
adb emu geo fix "$CENTER_LNG" "$CENTER_LAT"

echo " - GPS location set successfully"
else
echo " > WARNING: Could not parse bike station coordinates from XML"
fi
else
echo " > WARNING: Could not parse bike station coordinates from XML"
echo " - No GPS coordinates file found, skipping GPS setup"
fi
else
echo " - No GPS coordinates file found, skipping GPS setup"
fi

echo ">> Step 3: Install current repository module app..."
echo ">> Step 3: Install module app(s)..."

echo " - Module package: $MODULE_PACKAGE"
echo " - Installing module app from: $MODULE_APK_FILE"
while IFS= read -r MODULE_ENTRY; do
[ -z "$MODULE_ENTRY" ] && continue

adb install -r -d "$MODULE_APK_FILE"
MOD_PKG="${MODULE_ENTRY%%:*}"
MOD_APK="${MODULE_ENTRY#*:}"

# Verify installation
if adb shell pm list packages | grep -q "^package:${MODULE_PACKAGE}$"; then
echo " - Module app installed successfully"
else
echo " > ERROR: Module app installation may have failed!"
exit 1
fi
echo " - Installing module '$MOD_PKG' from: $MOD_APK"
adb install -r -d "$MOD_APK"

if adb shell pm list packages | grep -q "^package:${MOD_PKG}$"; then
echo " - Module '$MOD_PKG' installed successfully"
else
echo " > ERROR: Module '$MOD_PKG' installation may have failed!"
exit 1
fi
done <<< "$MODULE_APK_FILES"

echo ">> Step 4: Disable Pixel Launcher to prevent crashes..."

Expand Down