From 6636d465ab4ec122ccea5ca5d957b7d189cf2be0 Mon Sep 17 00:00:00 2001 From: "Jason C. Leach" Date: Fri, 25 Oct 2024 08:09:18 -0700 Subject: [PATCH 1/4] fix: pipe logic Signed-off-by: Jason C. Leach --- .../actions/early-exit-check/action.yml | 29 +++++--- .github/workflows/main.yaml | 66 ++++++++++++------- 2 files changed, 63 insertions(+), 32 deletions(-) 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: From 14a5642b026e7363501f92a691940c649390d69e Mon Sep 17 00:00:00 2001 From: "Jason C. Leach" Date: Fri, 25 Oct 2024 11:34:58 -0700 Subject: [PATCH 2/4] fix: pipe logic Signed-off-by: Jason C. Leach --- .github/workflows/actions/early-exit-check/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/actions/early-exit-check/action.yml b/.github/workflows/actions/early-exit-check/action.yml index 6a68fe1c..aee91ea5 100644 --- a/.github/workflows/actions/early-exit-check/action.yml +++ b/.github/workflows/actions/early-exit-check/action.yml @@ -34,7 +34,7 @@ runs: if [ $change_count -gt 0 ]; then # A result greater than 0 means there are changes # in the specified directories. - echo "result=zz" >> $GITHUB_OUTPUT + echo "result=true" >> $GITHUB_OUTPUT else - echo "result=xx" >> $GITHUB_OUTPUT + echo "result=false" >> $GITHUB_OUTPUT fi From 46fe7f87a25db04115caa1560fb68ac5ee136c4d Mon Sep 17 00:00:00 2001 From: "Jason C. Leach" Date: Fri, 25 Oct 2024 11:43:01 -0700 Subject: [PATCH 3/4] fix: simplify logic Signed-off-by: Jason C. Leach --- .../actions/early-exit-check/action.yml | 40 ------------------- .github/workflows/main.yaml | 2 +- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 .github/workflows/actions/early-exit-check/action.yml diff --git a/.github/workflows/actions/early-exit-check/action.yml b/.github/workflows/actions/early-exit-check/action.yml deleted file mode 100644 index aee91ea5..00000000 --- a/.github/workflows/actions/early-exit-check/action.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Check for early exit -description: | - This action checks for changes in specific directories and - exits early if there are none - -runs: - using: composite - steps: - - name: Check location of changed files - shell: bash - run: | - 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) - change_count=$(echo "$diff_output" | grep -E '^(blarb/.*)' | 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 diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0e12d14f..9f327b90 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -71,7 +71,7 @@ jobs: early-exit-check: runs-on: ubuntu-22.04 outputs: - should_skip_build: ${{ steps.core_files_check.outputs.result != 'true' }} + should_skip_build: ${{ steps.core_files_check.outputs.result == 'false' }} steps: - uses: actions/checkout@v4 with: From 0fae985c23791ff62723010ae4c2be60f62a707a Mon Sep 17 00:00:00 2001 From: "Jason C. Leach" Date: Fri, 25 Oct 2024 11:44:47 -0700 Subject: [PATCH 4/4] fix: simplify logic Signed-off-by: Jason C. Leach --- .github/workflows/main.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 9f327b90..66410fc4 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -71,14 +71,14 @@ jobs: early-exit-check: runs-on: ubuntu-22.04 outputs: - should_skip_build: ${{ steps.core_files_check.outputs.result == 'false' }} + should_skip_build: ${{ steps.core_files_changed.outputs.result == 'false' }} steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all branches, main needed. - name: Check if core files changed - id: core_files_check + id: core_files_changed shell: bash run: | set -x