Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: configure automatic screenshots #2517

Open
wants to merge 7 commits into
base: development
Choose a base branch
from

Conversation

AsCress
Copy link
Contributor

@AsCress AsCress commented Jul 26, 2024

Configures automatic screenshots in our pipelines.
Whenever a new release is made, new screenshots would automatically be captured in the release pipeline for upload to the Google PlayStore.

Changes

  • ScreenshotsTest is added to capture screenshots using fastlane screengrab.
  • Required permissions are added in the AndroidManifest, which include android.permission.DISABLE_KEYGUARD, android.permission.WAKE_LOCK, android.permission.CHANGE_CONFIGURATION and android.permission.DUMP.
  • A new GitHub action (screenshot-android/action.yml) is added, which takes care of creating an emulator and capturing screenshots.
  • The release pipeline release.yml is configured accordingly to push changes to the fastlane branch and then promote the existing APK to the production track.

Screenshots / Recordings

Here, is a screen recording of the test:

Screen_recording_20240726_161336.mp4

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Configure automatic screenshots capturing on new releases. This automates the process of taking screenshots for the Google Play Store during the release pipeline.

CI:

  • Set up a GitHub action to create an emulator, capture screenshots, and add them to the release metadata.

Tests:

  • Add instrumentation tests to capture screenshots using fastlane screengrab.

@AsCress AsCress requested a review from adityastic July 26, 2024 11:01
Copy link

github-actions bot commented Jul 26, 2024

@AsCress AsCress self-assigned this Jul 26, 2024
@AsCress AsCress added Chore Changes to things that do not go into production Status: Review Required Requested reviews from peers and maintainers labels Jul 26, 2024
@AsCress AsCress marked this pull request as ready for review December 30, 2024 19:15
Copy link

sourcery-ai bot commented Dec 30, 2024

Reviewer's Guide by Sourcery

This pull request configures automatic screenshots for Android releases. It introduces a new ScreenshotsTest class for capturing screenshots using fastlane screengrab, adds necessary permissions to the AndroidManifest, implements a GitHub action to manage emulator creation and screenshot capture, and updates the release pipeline to integrate these changes.

Sequence diagram for the automated screenshot capture process

sequenceDiagram
    participant GH as GitHub Actions
    participant E as Android Emulator
    participant A as Android App
    participant F as Fastlane

    GH->>E: Create/restore emulator from cache
    GH->>E: Start emulator
    GH->>A: Install app
    GH->>A: Run ScreenshotsTest
    loop For each screen
        A->>A: Navigate to screen
        A->>F: Capture screenshot
        F->>F: Save screenshot
    end
    GH->>F: Process screenshots
    GH->>GH: Update fastlane branch
Loading

Class diagram for the ScreenshotsTest implementation

classDiagram
    class ScreenshotsTest {
        -UiDevice mDevice
        -String APP_PACKAGE_NAME
        -int TIMEOUT
        +setUp()
        +testTakeScreenshot()
        -getLauncherPackageName()
    }
    note for ScreenshotsTest "Uses @RunWith(AndroidJUnit4.class)
and @LargeTest annotations"

    class Rules {
        +LocaleTestRule localeTestRule
        +ActivityScenarioRule mActivityScenarioRule
        +GrantPermissionRule mGrantPermissionRule
    }

    ScreenshotsTest --> Rules
Loading

File-Level Changes

Change Details Files
Added UI tests for taking screenshots of different screens within the app.
  • Created ScreenshotsTest class to automate UI tests and capture screenshots.
  • Added test cases for capturing screenshots of the dashboard, drawer, and various instrument views within the app.
  • Implemented logic to navigate through the app's UI and interact with elements during testing.
  • Integrated fastlane screengrab for capturing screenshots during UI tests.
  • Configured UI tests to run on an emulator with specified API level and architecture.
  • Added necessary permissions for UI testing, such as disabling keyguard, wake lock, changing configuration, and dumping.
app/src/androidTest/java/io/pslab/activity/ScreenshotsTest.java
Configured GitHub action to automate the process of creating an emulator, running UI tests, and capturing screenshots.
  • Created a new GitHub action named screenshot-android.
  • Defined input parameters for specifying the Android emulator API level and architecture.
  • Implemented steps for enabling KVM group permissions, caching AVD, creating AVD and caching snapshots, and creating Android screenshots.
  • Integrated fastlane screengrab within the GitHub action to capture screenshots.
  • Configured the action to run on a specific emulator profile (pixel_6) with optimized emulator options for faster execution and reduced resource usage.
.github/actions/screenshot-android/action.yml
Updated the release pipeline to integrate the automatic screenshot capture process.
  • Added a step to run the Android Screenshot Workflow GitHub action.
  • Configured the action to use specific environment variables for the emulator API level and architecture.
  • Updated the commit message for adding changelogs to include the version code and timestamp.
  • Modified the release pipeline to push changes to the fastlane branch and promote the existing APK to the production track after capturing screenshots.
.github/workflows/release.yml
Added necessary dependencies and configurations for UI testing and screenshot capture.
  • Added dependencies for fastlane screengrab, Espresso, UI Automator, JUnit, and other testing libraries.
  • Configured the testInstrumentationRunner to androidx.test.runner.AndroidJUnitRunner.
  • Added resource configurations for different languages (en, ru, ar, si, pl).
app/build.gradle.kts
Added necessary permissions for UI testing and screenshot capture.
  • Added permissions for disabling keyguard, wake lock, changing configuration, and dumping.
app/src/main/AndroidManifest.xml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AsCress - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the TIMEOUT value configurable or increasing it from 5000ms to avoid potential flakiness in CI environments
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@AsCress
Copy link
Contributor Author

AsCress commented Dec 30, 2024

@adityastic It's after so long that I'm making this PR ready for review 😂.
Have worked ON and OFF on this for months but never got the final product I wanted.
Today, it seems I have 😂😂.
Here are the screenshots that I obtained from the device:

dashboard_1735585689070
drawer_1735585690758
instrument_accelerometer_view_1735585719323
instrument_barometer_view_1735585761688
instrument_multimeter_view_1735585787238
instrument_wave_generator_1735585805745
oscilloscope_channel_view_1735585838532

I must say, getting screenshots from CI emulators is the hardest thing 😭.
It'd be great if I could get a final review on this on what else can be improved before merging !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chore Changes to things that do not go into production Status: Review Required Requested reviews from peers and maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant