From a95f743db48b3bb54222eed5c0dfc28602657f6b Mon Sep 17 00:00:00 2001 From: Carly Gundy <47304080+cgundy@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:30:21 +0200 Subject: [PATCH] refactor(IDX): handle case when no target branch is present (#1698) This updates the logic in `diff.sh` to use `HEAD` when no target branch is present. It also removes the `CI_PULL_REQUEST_TARGET_BRANCH_NAME` env var from the workflows as it is not needed anymore. --------- Co-authored-by: IDX GitHub Automation --- .github/actions/bazel-test-all/action.yaml | 2 ++ .github/workflows-source/ci-main.yml | 2 +- .github/workflows-source/ci-pr-only.yml | 1 - .github/workflows-source/release-testing.yml | 1 - .github/workflows-source/schedule-daily.yml | 1 - .github/workflows-source/schedule-hourly.yml | 1 - .github/workflows/ci-main.yml | 2 +- .github/workflows/ci-pr-only.yml | 1 - .github/workflows/release-testing.yml | 1 - .github/workflows/schedule-daily.yml | 1 - .github/workflows/schedule-hourly.yml | 1 - .github/workflows/schedule-rust-bench.yml | 1 - ci/bazel-scripts/diff.sh | 3 +-- 13 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/actions/bazel-test-all/action.yaml b/.github/actions/bazel-test-all/action.yaml index 7093eb5093e..ec6b56067ac 100644 --- a/.github/actions/bazel-test-all/action.yaml +++ b/.github/actions/bazel-test-all/action.yaml @@ -68,5 +68,7 @@ runs: BAZEL_CI_CONFIG: ${{ inputs.BAZEL_CI_CONFIG }} BAZEL_EXTRA_ARGS: "${{ inputs.BAZEL_EXTRA_ARGS }} ${{ inputs.BAZEL_EXTRA_ARGS_RULES }}" BAZEL_STARTUP_ARGS: ${{ inputs.BAZEL_STARTUP_ARGS }} + CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} + MERGE_BASE_SHA: ${{ github.event.pull_request.base.sha }} HONEYCOMB_API_TOKEN: ${{ inputs.HONEYCOMB_API_TOKEN }} SSH_PRIVATE_KEY: ${{ inputs.SSH_PRIVATE_KEY }} diff --git a/.github/workflows-source/ci-main.yml b/.github/workflows-source/ci-main.yml index ee45e737c02..9971312d449 100644 --- a/.github/workflows-source/ci-main.yml +++ b/.github/workflows-source/ci-main.yml @@ -26,7 +26,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} ROOT_PIPELINE_ID: ${{ github.run_id }} RUSTFLAGS: "--remap-path-prefix=${CI_PROJECT_DIR}=/ic" @@ -260,6 +259,7 @@ jobs: env: BAZEL_COMMAND: "build" RUN_ON_DIFF_ONLY: ${{ !contains(github.event.pull_request.labels.*.name, 'CI_ALL_BAZEL_TARGETS') }} + MERGE_BASE_SHA: ${{ github.event.pull_request.base.sha }} - name: Upload build-ic.tar uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows-source/ci-pr-only.yml b/.github/workflows-source/ci-pr-only.yml index 5d2b997f790..6698993b8cb 100644 --- a/.github/workflows-source/ci-pr-only.yml +++ b/.github/workflows-source/ci-pr-only.yml @@ -13,7 +13,6 @@ concurrency: env: CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} MERGE_BRANCH: ${{ github.event.pull_request.base.ref }} ORG: ${{ github.repository_owner }} diff --git a/.github/workflows-source/release-testing.yml b/.github/workflows-source/release-testing.yml index 52ab5ce25e5..45df6974758 100644 --- a/.github/workflows-source/release-testing.yml +++ b/.github/workflows-source/release-testing.yml @@ -19,7 +19,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} BRANCH_NAME: ${{ github.event.workflow_run.head_branch || github.ref_name }} ROOT_PIPELINE_ID: ${{ github.run_id }} RUSTFLAGS: "--remap-path-prefix=${CI_PROJECT_DIR}=/ic" diff --git a/.github/workflows-source/schedule-daily.yml b/.github/workflows-source/schedule-daily.yml index 099422e2c5c..4341b93d2b3 100644 --- a/.github/workflows-source/schedule-daily.yml +++ b/.github/workflows-source/schedule-daily.yml @@ -14,7 +14,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.ref_name }} # this workflow will always run on the default branch ROOT_PIPELINE_ID: ${{ github.run_id }} BUILDEVENT_DATASET: "github-ci-dfinity" diff --git a/.github/workflows-source/schedule-hourly.yml b/.github/workflows-source/schedule-hourly.yml index c932239b9c3..6b74f53b68f 100644 --- a/.github/workflows-source/schedule-hourly.yml +++ b/.github/workflows-source/schedule-hourly.yml @@ -13,7 +13,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} ROOT_PIPELINE_ID: ${{ github.run_id }} RUSTFLAGS: "--remap-path-prefix=${CI_PROJECT_DIR}=/ic" BUILDEVENT_DATASET: "github-ci-dfinity" diff --git a/.github/workflows/ci-main.yml b/.github/workflows/ci-main.yml index 04c616e49b9..57a9b83568a 100644 --- a/.github/workflows/ci-main.yml +++ b/.github/workflows/ci-main.yml @@ -22,7 +22,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} BRANCH_NAME: ${{ github.head_ref || github.ref_name }} ROOT_PIPELINE_ID: ${{ github.run_id }} RUSTFLAGS: "--remap-path-prefix=${CI_PROJECT_DIR}=/ic" @@ -346,6 +345,7 @@ jobs: env: BAZEL_COMMAND: "build" RUN_ON_DIFF_ONLY: ${{ !contains(github.event.pull_request.labels.*.name, 'CI_ALL_BAZEL_TARGETS') }} + MERGE_BASE_SHA: ${{ github.event.pull_request.base.sha }} - name: Upload build-ic.tar uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/ci-pr-only.yml b/.github/workflows/ci-pr-only.yml index ad109e4ff15..c0743f17e21 100644 --- a/.github/workflows/ci-pr-only.yml +++ b/.github/workflows/ci-pr-only.yml @@ -11,7 +11,6 @@ concurrency: env: CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} MERGE_BRANCH: ${{ github.event.pull_request.base.ref }} ORG: ${{ github.repository_owner }} jobs: diff --git a/.github/workflows/release-testing.yml b/.github/workflows/release-testing.yml index 46498010d40..ad68fcd53e1 100644 --- a/.github/workflows/release-testing.yml +++ b/.github/workflows/release-testing.yml @@ -16,7 +16,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} BRANCH_NAME: ${{ github.event.workflow_run.head_branch || github.ref_name }} ROOT_PIPELINE_ID: ${{ github.run_id }} RUSTFLAGS: "--remap-path-prefix=${CI_PROJECT_DIR}=/ic" diff --git a/.github/workflows/schedule-daily.yml b/.github/workflows/schedule-daily.yml index 1a344422586..c11f4c8b498 100644 --- a/.github/workflows/schedule-daily.yml +++ b/.github/workflows/schedule-daily.yml @@ -12,7 +12,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.ref_name }} # this workflow will always run on the default branch ROOT_PIPELINE_ID: ${{ github.run_id }} BUILDEVENT_DATASET: "github-ci-dfinity" jobs: diff --git a/.github/workflows/schedule-hourly.yml b/.github/workflows/schedule-hourly.yml index 65af24bcef6..3bc463cd349 100644 --- a/.github/workflows/schedule-hourly.yml +++ b/.github/workflows/schedule-hourly.yml @@ -11,7 +11,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.event.pull_request.base.ref }} ROOT_PIPELINE_ID: ${{ github.run_id }} RUSTFLAGS: "--remap-path-prefix=${CI_PROJECT_DIR}=/ic" BUILDEVENT_DATASET: "github-ci-dfinity" diff --git a/.github/workflows/schedule-rust-bench.yml b/.github/workflows/schedule-rust-bench.yml index 8d961b21c6c..d1fe578e0fe 100644 --- a/.github/workflows/schedule-rust-bench.yml +++ b/.github/workflows/schedule-rust-bench.yml @@ -14,7 +14,6 @@ env: CI_JOB_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" CI_PIPELINE_SOURCE: ${{ github.event_name }} CI_PROJECT_DIR: ${{ github.workspace }} - CI_PULL_REQUEST_TARGET_BRANCH_NAME: ${{ github.ref_name }} # this workflow will always run on the default branch ROOT_PIPELINE_ID: ${{ github.run_id }} BUILDEVENT_DATASET: "github-ci-dfinity" diff --git a/ci/bazel-scripts/diff.sh b/ci/bazel-scripts/diff.sh index 3774d9a2afd..dc52a4dc4af 100755 --- a/ci/bazel-scripts/diff.sh +++ b/ci/bazel-scripts/diff.sh @@ -13,8 +13,7 @@ set -euo pipefail set -x cd "$(git rev-parse --show-toplevel)" -git fetch origin "$CI_PULL_REQUEST_TARGET_BRANCH_NAME" --quiet -MERGE_BASE="$(git merge-base HEAD origin/$CI_PULL_REQUEST_TARGET_BRANCH_NAME)" +MERGE_BASE="${MERGE_BASE_SHA:-HEAD}" COMMIT_RANGE=${COMMIT_RANGE:-$MERGE_BASE".."} DIFF_FILES=$(git diff --name-only "${COMMIT_RANGE}")