Skip to content
Merged
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
77 changes: 77 additions & 0 deletions .github/actions/moksha-render/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Renders raw captures into finished store images with moksha.
#
# moksha is a checkout, not a dependency: it is a separate tool maintained on
# its own, and pinning a ref here means a change there cannot silently alter
# this app's listing.
#
# It validates every asset against the store it targets and exits non-zero on a
# violation, so the run fails here rather than at upload. The three that
# produce a perfectly valid PNG a store still refuses: an alpha channel, a Play
# aspect ratio over 2:1, and a dimension Apple does not recognise.

name: Render store assets
description: Frame captures with moksha and place them for upload

inputs:
job:
description: Path to the moksha job JSON
required: true
captures:
description: Directory holding the raw captures
default: build/screenshots
destination:
description: Where the finished images should end up
required: true
moksha-ref:
description: Git ref of moksha to render with
default: main

runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: "20"

- name: Check out moksha
shell: bash
run: |
rm -rf "$RUNNER_TEMP/moksha"
git clone --depth 1 --branch "${{ inputs.moksha-ref }}" \
https://github.com/lohanidamodar/moksha.git "$RUNNER_TEMP/moksha"
cd "$RUNNER_TEMP/moksha" && npm ci --silent

- name: Render
shell: bash
env:
JOB: ${{ inputs.job }}
CAPTURES: ${{ inputs.captures }}
DESTINATION: ${{ inputs.destination }}
run: |
set -euo pipefail

count=$(find "$CAPTURES" -name '*.png' 2>/dev/null | wc -l)
echo "captured $count screenshot(s)"
# A green run with an empty listing is indistinguishable from a working
# one. That is the failure this whole harness exists to prevent.
if [ "$count" -eq 0 ]; then
echo "::error::no screenshots were captured"
exit 1
fi

out="$RUNNER_TEMP/rendered"
rm -rf "$out"

cd "$RUNNER_TEMP/moksha"
npm run render -- \
--job "$GITHUB_WORKSPACE/$JOB" \
--images "$GITHUB_WORKSPACE/$CAPTURES" \
--out "$out"

cd "$GITHUB_WORKSPACE"
# Replaced wholesale rather than merged: a screenshot removed from the
# test should disappear from the listing too.
rm -rf "$DESTINATION"
mkdir -p "$DESTINATION"
cp "$out"/*.png "$DESTINATION/"
ls -la "$DESTINATION"
58 changes: 58 additions & 0 deletions .github/actions/open-screenshot-pr/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Opens a pull request with the regenerated images.
#
# A PR rather than a push to the branch: store images are a visual change and
# the diff is the review. It also means the workflow does not need write access
# to a protected branch.

name: Open screenshot PR
description: Commit the rendered assets on a branch and open a pull request

inputs:
paths:
description: Paths to stage
required: true
title:
description: Pull request title
required: true
branch:
description: Branch name to push
required: true

runs:
using: composite
steps:
- shell: bash
env:
PATHS: ${{ inputs.paths }}
TITLE: ${{ inputs.title }}
BRANCH: ${{ inputs.branch }}
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git add $PATHS
if git diff --staged --quiet; then
echo "images unchanged; nothing to open a PR for"
exit 0
fi

git checkout -b "$BRANCH"
git commit -m "$TITLE"
git push --force-with-lease origin "$BRANCH"

# A PR may already exist if this ran twice for the same branch.
if [ -z "$(gh pr list --head "$BRANCH" --json number --jq '.[0].number')" ]; then
gh pr create \
--head "$BRANCH" \
--title "$TITLE" \
--body "Regenerated by the screenshot workflow.

Every image was validated against the store's upload rules before this
PR was opened — no alpha channel, Play's 2:1 aspect limit, and Apple's
accepted dimensions. What that cannot check is whether they *look*
right, so open a few before merging."
else
echo "PR for $BRANCH already open; pushed an update to it"
fi
100 changes: 100 additions & 0 deletions .github/workflows/screenshots-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Capture, frame and open a PR with the Play store phone screenshots.
#
# Manual only: it rewrites listing images, so it runs when you decide the
# listing needs refreshing. Ported from momo-pasal; see screenshots/README.md.
#
# Ubuntu, not macOS: the emulator action's own guidance is that Ubuntu runners
# with KVM are 2-3x faster and much cheaper.
#
# The capture reads the live feed from Appwrite, so the shots show real
# stories. Analytics is compiled out (ANALYTICS_PROPERTY_ID empty) so these
# runs never land in the app's stats.

name: Screenshots (Android)

on:
workflow_dispatch:
inputs:
locale:
description: "Play listing locale"
type: choice
default: en-US
options:
- en-US

permissions:
contents: write
pull-requests: write

jobs:
screenshots:
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"

- uses: subosito/flutter-action@v2
with:
flutter-version: "3.47.1"
channel: stable
cache: true

- name: Install dependencies
run: flutter pub get

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: Capture
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
arch: x86_64
profile: pixel_6
disable-animations: true
script: |
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/screenshot_test.dart \
--dart-define=ANALYTICS_PROPERTY_ID= \
-d emulator-5554

- name: Build the moksha job
run: |
dart run tool/screenshot_job.dart \
--asset-type android-phone-screenshot \
--size-id android-phone \
--locale ${{ inputs.locale }} \
--out "$RUNNER_TEMP/job.json"

- name: Render
uses: ./.github/actions/moksha-render
with:
job: ${{ runner.temp }}/job.json
destination: android/fastlane/metadata/android/${{ inputs.locale }}/images/phoneScreenshots

- name: Open a PR
uses: ./.github/actions/open-screenshot-pr
with:
paths: android/fastlane/metadata
title: "chore: refresh Play phone screenshots (${{ inputs.locale }})"
branch: screenshots/play-phone-${{ inputs.locale }}

- uses: actions/upload-artifact@v4
if: always()
with:
name: play-phone-${{ inputs.locale }}
path: |
build/screenshots/
android/fastlane/metadata/android/${{ inputs.locale }}/images/phoneScreenshots/
if-no-files-found: warn
149 changes: 149 additions & 0 deletions .github/workflows/screenshots-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Capture, frame and open a PR with the App Store screenshots.
#
# macOS, because the iOS simulator has no Linux equivalent. Ported from
# momo-pasal; see screenshots/README.md.
#
# The app is universal (TARGETED_DEVICE_FAMILY = 1,2), so App Store Connect
# wants a 6.9" iPhone set and a 13" iPad set. Each is captured on a matching
# simulator and framed by moksha at a size App Store Connect accepts, into
# ios/fastlane/screenshots/framed/<locale>/, which is where the fastlane
# upload_screenshots / upload_listing lanes read from.

name: Screenshots (iOS)

on:
workflow_dispatch:
inputs:
locale:
description: "App Store locale"
type: choice
default: en-US
options:
- en-US
families:
description: "Which device families to regenerate"
type: choice
default: iphone+ipad
options:
- iphone+ipad
- iphone

permissions:
contents: write
pull-requests: write

jobs:
screenshots:
runs-on: macos-latest
timeout-minutes: 90

strategy:
max-parallel: 1
fail-fast: false
matrix:
include:
- family: iphone
simulator: "iPhone 17 Pro Max"
asset_type: iphone-screenshot
size_id: "ios-6.9"
- family: ipad
simulator: "iPad Pro 13-inch (M4)"
asset_type: ipad-screenshot
size_id: "ipad-13"

steps:
- uses: actions/checkout@v4

- name: Skip families that were not asked for
id: want
run: |
if [ "${{ matrix.family }}" = "ipad" ] && \
[ "${{ inputs.families }}" != "iphone+ipad" ]; then
echo "run=false" >> "$GITHUB_OUTPUT"
else
echo "run=true" >> "$GITHUB_OUTPUT"
fi

- uses: subosito/flutter-action@v2
if: steps.want.outputs.run == 'true'
with:
flutter-version: "3.47.1"
channel: stable
cache: true

- name: Install dependencies
if: steps.want.outputs.run == 'true'
run: flutter pub get

- name: Boot the simulator
if: steps.want.outputs.run == 'true'
id: sim
run: |
set -euo pipefail
xcrun simctl list devicetypes | grep -i -E 'iphone|ipad' || true
udid=$(xcrun simctl create shots "${{ matrix.simulator }}")
xcrun simctl boot "$udid"
xcrun simctl bootstatus "$udid" -b
echo "udid=$udid" >> "$GITHUB_OUTPUT"

- name: Capture
if: steps.want.outputs.run == 'true'
run: |
flutter drive \
--driver=test_driver/integration_test.dart \
--target=integration_test/screenshot_test.dart \
--dart-define=ANALYTICS_PROPERTY_ID= \
-d ${{ steps.sim.outputs.udid }}

- name: Build the moksha job
if: steps.want.outputs.run == 'true'
run: |
dart run tool/screenshot_job.dart \
--asset-type ${{ matrix.asset_type }} \
--size-id ${{ matrix.size_id }} \
--locale ${{ inputs.locale }} \
--out "$RUNNER_TEMP/job.json"

# Each family renders into its own temporary folder first: moksha-render
# replaces its destination wholesale, and both families share the
# locale folder deliver reads.
- name: Render
if: steps.want.outputs.run == 'true'
uses: ./.github/actions/moksha-render
with:
job: ${{ runner.temp }}/job.json
destination: build/rendered/${{ matrix.family }}

- name: Place for deliver
if: steps.want.outputs.run == 'true'
run: |
set -euo pipefail
dest="ios/fastlane/screenshots/framed/${{ inputs.locale }}"
mkdir -p "$dest"
# Replace only this family's images, prefixed so they never collide.
rm -f "$dest"/${{ matrix.family }}_*.png
for f in build/rendered/${{ matrix.family }}/*.png; do
cp "$f" "$dest/${{ matrix.family }}_$(basename "$f")"
done
ls -la "$dest"

- name: Open a PR
if: steps.want.outputs.run == 'true'
uses: ./.github/actions/open-screenshot-pr
with:
paths: ios/fastlane/screenshots
title: "chore: refresh App Store ${{ matrix.family }} screenshots (${{ inputs.locale }})"
branch: screenshots/appstore-${{ matrix.family }}-${{ inputs.locale }}

- name: Shut the simulator down
if: always() && steps.want.outputs.run == 'true'
run: xcrun simctl delete ${{ steps.sim.outputs.udid }} || true

- uses: actions/upload-artifact@v4
if: always() && steps.want.outputs.run == 'true'
with:
name: appstore-${{ matrix.family }}-${{ inputs.locale }}
path: |
build/screenshots/
build/rendered/${{ matrix.family }}/
if-no-files-found: warn
Loading