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

Only run APK/IPA builds on changes demos in PRs only #3205

Conversation

cpholguera
Copy link
Collaborator

@cpholguera cpholguera commented Mar 8, 2025

This PR closes #3204

This PR optimizes the GitHub Action for building Android and iOS demos by modifying its behavior based on the event type:

  • For push to master: The workflow remains unchanged and builds all Android demos.
  • For pull requests: The build now runs only if files within demos/android/** or demos/ios/** have changed, reducing unnecessary builds. This is achieved by using git diff to detect modified files and updating the matrix accordingly.

This improves CI efficiency by avoiding redundant builds when no relevant changes are made.

Additional changes: Demo download buttons

This PR also updated the script that ensures that the last successful run of the GitHub Action was on the master branch.

  • Script: docs/hooks/github_api.py
  • Used from: docs/hooks/maswe-beta-banner.py in the get_android_demo_buttons and get_android_demo_buttons methods.

Previously, the script fetched the most recent successful run without checking the branch, which could lead to using artifacts from non-master branches. Now, it explicitly filters for successful runs on master, ensuring that only stable and merged builds are considered.

…uests in Android and iOS builds and restrict them to only changes in the PR.
Copy link
Collaborator

@javier-ruiz-b javier-ruiz-b left a comment

Choose a reason for hiding this comment

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

Looks great as it is. Check if it makes sense to do the refactor mentioned before.


- name: Generate matrix
id: set-matrix
run: |
matrix="$(echo demos/android/*/MASTG-DEMO-* | sed 's/ /","/g')"
echo "matrix={\"demo\":[\"$matrix\"]}" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" = "pull_request" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great idea! The script is good as it is, I don't think it's necessary to improve it.

I am thinking in extracting the script into a separate file, because it is very similar between iOS and Android. For example:

.github/workflows/matrix-demos-json.sh

#!/bin/bash
set -eu
event_name="$1" # check for "pull_request"
pr_commit_hash="$2"
demo_path="$3" # demos/android or demos/ios
...

The idea is to shorten the step to something like this:

      - name: Generate matrix
        id: set-matrix
        run: |
          event_name="${{ github.event_name }}"
          pr_hash="${{ github.event.pull_request.base.sha }}"
.github/workflows/matrix-demos-json.sh "$event_name"  "$pr_hash" demos/android >> $GITHUB_OUTPUT

Copy link
Collaborator Author

@cpholguera cpholguera Mar 8, 2025

Choose a reason for hiding this comment

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

That'd be really nice, let's do that on a separate PR. Thanks a lot!

@cpholguera cpholguera merged commit 84c3b68 into master Mar 8, 2025
8 checks passed
@cpholguera cpholguera deleted the 3204-optimize-apk-and-ipa-build-actions-to-run-only-on-relevant-changes-in-prs branch March 8, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize APK and IPA Build Actions to Run Only on Relevant Changes in PRs
2 participants