diff --git a/.github/workflows/e2e-v2.yml b/.github/workflows/e2e-v2.yml index 54668f4d2b..3fa0a92a1c 100644 --- a/.github/workflows/e2e-v2.yml +++ b/.github/workflows/e2e-v2.yml @@ -7,6 +7,7 @@ on: - v5 - release/** pull_request: + types: [opened, synchronize, reopened, labeled] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -19,7 +20,15 @@ env: IOS_VERSION: '18.1' jobs: + ready-to-merge-gate: + name: Ready-to-merge gate + uses: ./.github/workflows/ready-to-merge-workflow.yml + with: + is-pr: ${{ github.event_name == 'pull_request' }} + labels: ${{ toJson(github.event.pull_request.labels) }} + diff_check: + needs: [ready-to-merge-gate] uses: ./.github/workflows/skip-ci.yml auth_token_check: uses: ./.github/workflows/skip-ci-noauth.yml diff --git a/.github/workflows/native-tests.yml b/.github/workflows/native-tests.yml index 97aaffa327..e096f7de40 100644 --- a/.github/workflows/native-tests.yml +++ b/.github/workflows/native-tests.yml @@ -7,13 +7,22 @@ on: - v5 - release/** pull_request: - + types: [opened, synchronize, reopened, labeled] + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: + ready-to-merge-gate: + name: Ready-to-merge gate + uses: ./.github/workflows/ready-to-merge-workflow.yml + with: + is-pr: ${{ github.event_name == 'pull_request' }} + labels: ${{ toJson(github.event.pull_request.labels) }} + diff_check: + needs: [ready-to-merge-gate] uses: ./.github/workflows/skip-ci.yml test-ios: diff --git a/.github/workflows/ready-to-merge-workflow.yml b/.github/workflows/ready-to-merge-workflow.yml new file mode 100644 index 0000000000..402593eb85 --- /dev/null +++ b/.github/workflows/ready-to-merge-workflow.yml @@ -0,0 +1,41 @@ +name: Ready to Merge Workflow +on: + workflow_call: + inputs: + labels: + description: The GitHub event's labels + required: true + type: string + is-pr: + description: Whether the workflow is running on a PR + required: true + type: boolean + +jobs: + ready-to-merge-gate: + name: 'Missing "ready-to-merge" label' + runs-on: ubuntu-latest + steps: + - name: Check for exact 'ready-to-merge' label + if: ${{ inputs.is-pr }} + id: check-label + run: | + # Use jq to check for exact label match (avoids substring matching issues with contains()) + if echo '${{ inputs.labels }}' | jq -e '.[] | select(.name == "ready-to-merge")' > /dev/null; then + echo "label_found=true" >> $GITHUB_OUTPUT + else + echo "label_found=false" >> $GITHUB_OUTPUT + fi + # Since Github also accepts `skipped` results for Required Workflows, we need + # to fail the job to ensure that the downstream jobs don't just skip. + - name: Fail until the 'ready-to-merge' label is present + if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'false' }} + run: | + echo "Add the 'ready-to-merge' label to run CI." + exit 1 + - name: Gate passed + if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'true' }} + run: echo "Label present. Proceeding with CI." + - name: Gate passed + if: ${{ !inputs.is-pr }} + run: echo "Not a PR. Proceeding with CI." diff --git a/.github/workflows/sample-application-expo.yml b/.github/workflows/sample-application-expo.yml index 6d1008e5f6..9b7c17f94d 100644 --- a/.github/workflows/sample-application-expo.yml +++ b/.github/workflows/sample-application-expo.yml @@ -6,6 +6,7 @@ on: - main - v5 pull_request: + types: [opened, synchronize, reopened, labeled] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -16,7 +17,15 @@ env: RN_SENTRY_POD_NAME: RNSentry jobs: + ready-to-merge-gate: + name: Ready-to-merge gate + uses: ./.github/workflows/ready-to-merge-workflow.yml + with: + is-pr: ${{ github.event_name == 'pull_request' }} + labels: ${{ toJson(github.event.pull_request.labels) }} + diff_check: + needs: [ready-to-merge-gate] uses: ./.github/workflows/skip-ci.yml build: diff --git a/.github/workflows/sample-application.yml b/.github/workflows/sample-application.yml index 18e6910885..f9b39ce194 100644 --- a/.github/workflows/sample-application.yml +++ b/.github/workflows/sample-application.yml @@ -6,6 +6,7 @@ on: - main - v5 pull_request: + types: [opened, synchronize, reopened, labeled] concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -23,7 +24,15 @@ env: ANDROID_API_LEVEL: '30' jobs: + ready-to-merge-gate: + name: Ready-to-merge gate + uses: ./.github/workflows/ready-to-merge-workflow.yml + with: + is-pr: ${{ github.event_name == 'pull_request' }} + labels: ${{ toJson(github.event.pull_request.labels) }} + diff_check: + needs: [ready-to-merge-gate] uses: ./.github/workflows/skip-ci.yml build: diff --git a/CI.md b/CI.md new file mode 100644 index 0000000000..09ee96b7c8 --- /dev/null +++ b/CI.md @@ -0,0 +1,25 @@ +# CI inner working + +## `ready-to-merge` label + +CI checks are great, but macOS runners are limited on every provider, because of this, we need to be smarter on how we run jobs. +To avoid running many jobs on every PR's commit, we have decided to only run a subset of tests regularily and run the full suite only when the PR has the label `ready-to-merge`. + +### How to use the gate + +Add this job at the start the workflow and then add `need: ready-to-merge-gate` to jobs that you want to be skipped. + +``` +ready-to-merge-gate: + name: Ready-to-merge gate + uses: ./.github/workflows/ready-to-merge-workflow.yml + with: + is-pr: ${{ github.event_name == 'pull_request' }} + labels: ${{ toJson(github.event.pull_request.labels) }} +``` + +This job will: + +- Pass if the event is not a PR +- Fail if the event is a PR and is missing the `ready-to-merge` label +- Pass if the event is a PR and is has the `ready-to-merge` label