diff --git a/.github/workflows/actions/early-exit-check/action.yml b/.github/workflows/actions/early-exit-check/action.yml index ffc4c4b8..6a68fe1c 100644 --- a/.github/workflows/actions/early-exit-check/action.yml +++ b/.github/workflows/actions/early-exit-check/action.yml @@ -9,23 +9,32 @@ runs: - name: Check location of changed files shell: bash run: | - # On main branch, compare with the previous - # commit otherwise (for PRs) compare with the - # current commit. - if [ "${GITHUB_REF_NAME}" = "main" ]; then - end_ref="HEAD^" + set -x + + if [ "${GITHUB_REF_NAME}" = "main" ]; then + # On main branch, compare with the previous + # commit otherwise (for PRs) compare with the + # current commit. + parent_ref="${GITHUB_REF_NAME:-main}^" + child_ref="${GITHUB_SHA}" else - end_ref="HEAD" + # On PRs, compare with the base branch. + parent_ref="origin/${GITHUB_BASE_REF:-main}" + child_ref="HEAD" fi - echo "Comparing origin/${GITHUB_BASE_REF:-HEAD} with ${end_ref}" + echo "Comparing ${parent_ref} with ${child_ref}" + + diff_output=$(git diff --name-only ${parent_ref}..${child_ref}) + # change_count=$(echo "$diff_output" | grep -E '^(app/.*)|(.yarn/.*)|(.github/workflows/.*)' | wc -l | awk '{$1=$1};1' || true) + change_count=$(echo "$diff_output" | grep -E '^(blarb/.*)' | wc -l | awk '{$1=$1};1' || true) - change_count=$(git diff --name-only origin/${GITHUB_BASE_REF:-HEAD}..${end_ref} | grep -E '^(app/.*)|(.yarn/.*)|(.github/workflows/.*)' | wc -l | awk '{$1=$1};1') echo "$change_count files changed in app, .yarn, or .github/workflows" + if [ $change_count -gt 0 ]; then # A result greater than 0 means there are changes # in the specified directories. - echo "result=false" >> $GITHUB_OUTPUT + echo "result=zz" >> $GITHUB_OUTPUT else - echo "result=true" >> $GITHUB_OUTPUT + echo "result=xx" >> $GITHUB_OUTPUT fi diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 82ee86f3..0e12d14f 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -68,22 +68,54 @@ jobs: MEDIATOR_USE_PUSH_NOTIFICATIONS: ${{ vars.MEDIATOR_USE_PUSH_NOTIFICATIONS }} INDY_VDR_PROXY_URL: ${{ vars.INDY_VDR_PROXY_URL }} - build-ios: - needs: [check-secrets, check-vars] - runs-on: macos-13 + early-exit-check: + runs-on: ubuntu-22.04 + outputs: + should_skip_build: ${{ steps.core_files_check.outputs.result != 'true' }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all branches, main needed. - - name: Run early exit check - id: should_early_exit - uses: ./.github/workflows/actions/early-exit-check - - - name: Exit if no changes in core paths - if: steps.should_early_exit.outputs.result == 'true' + - name: Check if core files changed + id: core_files_check + shell: bash run: | - exit 0 + set -x + + if [ "${GITHUB_REF_NAME}" = "main" ]; then + # On main branch, compare with the previous + # commit otherwise (for PRs) compare with the + # current commit. + parent_ref="${GITHUB_REF_NAME:-main}^" + child_ref="${GITHUB_SHA}" + else + # On PRs, compare with the base branch. + parent_ref="origin/${GITHUB_BASE_REF:-main}" + child_ref="HEAD" + fi + + echo "Comparing ${parent_ref} with ${child_ref}" + + diff_output=$(git diff --name-only ${parent_ref}..${child_ref}) + change_count=$(echo "$diff_output" | grep -E '^(app/.*)|(.yarn/.*)|(.github/workflows/.*)' | wc -l | awk '{$1=$1};1' || true) + + echo "$change_count files changed in app, .yarn, or .github/workflows" + + if [ $change_count -gt 0 ]; then + # A result greater than 0 means there are changes + # in the specified directories. + echo "result=true" >> $GITHUB_OUTPUT + else + echo "result=false" >> $GITHUB_OUTPUT + fi + + build-ios: + needs: [check-secrets, check-vars, early-exit-check] + if: ${{ needs.early-exit-check.outputs.should_skip_build != 'true' }} + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: @@ -237,24 +269,14 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} build-android: - needs: [check-secrets, check-vars] + needs: [check-secrets, check-vars, early-exit-check] + if: ${{ needs.early-exit-check.outputs.should_skip_build != 'true' }} runs-on: ubuntu-22.04 permissions: contents: read packages: write steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch all branches, main needed. - - - name: Run early exit check - id: should_early_exit - uses: ./.github/workflows/actions/early-exit-check - - - name: Exit if no changes in core paths - if: steps.should_early_exit.outputs.result == 'true' - run: | - exit 0 - uses: actions/setup-python@v5 with: