|
8 | 8 |
|
9 | 9 | jobs: |
10 | 10 |
|
| 11 | + check-android-changes: |
| 12 | + name: Check Android Changes |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + should_build: ${{ steps.check.outputs.should_build }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v3 |
| 19 | + with: |
| 20 | + fetch-depth: 0 # Fetch all history for all branches and tags |
| 21 | + |
| 22 | + - name: Check for Android changes |
| 23 | + id: check |
| 24 | + run: | |
| 25 | + # For push events, check if workflow file has changed |
| 26 | + if [ "${{ github.event_name }}" == "push" ] && [ -n "${{ github.event.before }}" ] && [ -n "${{ github.event.after }}" ]; then |
| 27 | + if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -q ".github/workflows/workflow.yml"; then |
| 28 | + echo "Workflow file has changed, building Android" |
| 29 | + echo "should_build=true" >> $GITHUB_OUTPUT |
| 30 | + exit 0 |
| 31 | + fi |
| 32 | + fi |
| 33 | +
|
| 34 | + # For pull requests, check the files changed in the PR |
| 35 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 36 | + echo "Checking files changed in pull request..." |
| 37 | +
|
| 38 | + # Check if PR has android label or title contains android |
| 39 | + if [[ "${{ contains(github.event.pull_request.labels.*.name, 'android') }}" == "true" || \ |
| 40 | + "${{ contains(github.event.pull_request.title, 'android') }}" == "true" || \ |
| 41 | + "${{ contains(github.event.pull_request.title, 'Android') }}" == "true" ]]; then |
| 42 | + echo "PR has android label or title contains android" |
| 43 | + echo "should_build=true" >> $GITHUB_OUTPUT |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + # Get the list of files changed in the PR |
| 48 | + git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1 |
| 49 | + PR_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }}) |
| 50 | + else |
| 51 | + # For pushes, check the files changed in the last commit |
| 52 | + echo "Checking files changed in push..." |
| 53 | +
|
| 54 | + # If this is the first commit, build Android |
| 55 | + if [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then |
| 56 | + echo "First commit, building Android" |
| 57 | + echo "should_build=true" >> $GITHUB_OUTPUT |
| 58 | + exit 0 |
| 59 | + fi |
| 60 | +
|
| 61 | + # Get the list of files changed in the push |
| 62 | + PR_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }}) |
| 63 | + fi |
| 64 | +
|
| 65 | + # Check if any Android-related files have changed |
| 66 | + ANDROID_PATTERN="attachments/34_android.cpp|attachments/35_gltf_ktx.cpp|attachments/android/|attachments/27_shader_depth.(frag|vert)" |
| 67 | + if echo "$PR_FILES" | grep -E "$ANDROID_PATTERN"; then |
| 68 | + echo "Android-related files have changed" |
| 69 | + echo "should_build=true" >> $GITHUB_OUTPUT |
| 70 | + else |
| 71 | + echo "No Android-related files have changed" |
| 72 | + echo "should_build=false" >> $GITHUB_OUTPUT |
| 73 | + fi |
| 74 | +
|
11 | 75 | build: |
12 | 76 | strategy: |
13 | 77 | fail-fast: false |
@@ -337,6 +401,10 @@ jobs: |
337 | 401 | name: Android Build |
338 | 402 | runs-on: ubuntu-latest |
339 | 403 |
|
| 404 | + # We need to run a preliminary job to check for changes |
| 405 | + needs: check-android-changes |
| 406 | + if: needs.check-android-changes.outputs.should_build == 'true' |
| 407 | + |
340 | 408 | steps: |
341 | 409 | - uses: actions/checkout@v3 |
342 | 410 |
|
|
0 commit comments