Skip to content

Commit a8ec6d0

Browse files
authored
airbyte-ci: improve git diff comparison (#37616)
1 parent 6ea66e5 commit a8ec6d0

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

airbyte-ci/connectors/pipelines/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ options to the `airbyte-ci` command group.**
183183
| `--is-local/--is-ci` | `--is-local` | | Determines the environment in which the CLI runs: local environment or CI environment. |
184184
| `--git-branch` | The checked out git branch name | `CI_GIT_BRANCH` | The git branch on which the pipelines will run. |
185185
| `--git-revision` | The current branch head | `CI_GIT_REVISION` | The commit hash on which the pipelines will run. |
186-
| `--diffed-branch` | `origin/master` | | Branch to which the git diff will happen to detect new or modified files. |
186+
| `--diffed-branch` | `master` | | Branch to which the git diff will happen to detect new or modified files. |
187187
| `--gha-workflow-run-id` | | | GHA CI only - The run id of the GitHub action workflow |
188188
| `--ci-context` | `manual` | | The current CI context: `manual` for manual run, `pull_request`, `nightly_builds`, `master` |
189189
| `--pipeline-start-timestamp` | Current epoch time | `CI_PIPELINE_START_TIMESTAMP` | Start time of the pipeline as epoch time. Used for pipeline run duration computation. |
@@ -649,6 +649,7 @@ E.G.: running Poe tasks on the modified internal packages of the current branch:
649649

650650
| Version | PR | Description |
651651
| ------- | ---------------------------------------------------------- |----------------------------------------------------------------------------------------------------------------------------|
652+
| 4.10.0 | [#37616](https://github.com/airbytehq/airbyte/pull/37616) | Improve modified files comparison when the target branch is from a fork. |
652653
| 4.9.0 | [#37440](https://github.com/airbytehq/airbyte/pull/37440) | Run regression tests with `airbyte-ci connectors test` |
653654
| 4.8.0 | [#37404](https://github.com/airbytehq/airbyte/pull/37404) | Accept a `git-repo-url` option on the `airbyte-ci` root command to checkout forked repo. |
654655
| 4.7.4 | [#37485](https://github.com/airbytehq/airbyte/pull/37485) | Allow java connectors to be written in kotlin. |

airbyte-ci/connectors/pipelines/pipelines/cli/airbyte_ci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def is_current_process_wrapped_by_dagger_run() -> bool:
153153
@click.option(
154154
"--diffed-branch",
155155
help="Branch to which the git diff will happen to detect new or modified connectors",
156-
default="origin/master",
156+
default="master",
157157
type=str,
158158
)
159159
@click.option("--gha-workflow-run-id", help="[CI Only] The run id of the GitHub action workflow", default=None, type=str)

airbyte-ci/connectors/pipelines/pipelines/dagger/containers/git.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ async def checked_out_git_container(
1313
diffed_branch: Optional[str] = None,
1414
repo_url: str = AIRBYTE_REPO_URL,
1515
) -> Container:
16-
"""Builds git-based container with the current branch checked out."""
16+
"""
17+
Create a container with git in it.
18+
We add the airbyte repo as the origin remote and the target repo as the target remote.
19+
We fetch the diffed branch from the origin remote and the current branch from the target remote.
20+
We then checkout the current branch.
21+
"""
1722
current_git_branch = current_git_branch.removeprefix("origin/")
1823
diffed_branch = current_git_branch if diffed_branch is None else diffed_branch.removeprefix("origin/")
1924
return await (
@@ -26,14 +31,19 @@ async def checked_out_git_container(
2631
[
2732
"remote",
2833
"add",
29-
"--fetch",
30-
"--track",
31-
current_git_branch,
32-
"--track",
33-
diffed_branch if diffed_branch is not None else current_git_branch,
3434
"origin",
35+
AIRBYTE_REPO_URL,
36+
]
37+
)
38+
.with_exec(
39+
[
40+
"remote",
41+
"add",
42+
"target",
3543
repo_url,
3644
]
3745
)
38-
.with_exec(["checkout", "-t", f"origin/{current_git_branch}"])
46+
.with_exec(["fetch", "origin", diffed_branch])
47+
.with_exec(["fetch", "target", current_git_branch])
48+
.with_exec(["checkout", current_git_branch])
3949
)

airbyte-ci/connectors/pipelines/pipelines/helpers/git.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_current_git_branch() -> str: # noqa D103
2121

2222

2323
async def get_modified_files_in_branch_remote(
24-
current_git_repo_url: str, current_git_branch: str, current_git_revision: str, diffed_branch: str = "origin/master", retries: int = 3
24+
current_git_repo_url: str, current_git_branch: str, current_git_revision: str, diffed_branch: str = "master", retries: int = 3
2525
) -> Set[str]:
2626
"""Use git diff to spot the modified files on the remote branch."""
2727
try:
@@ -30,7 +30,7 @@ async def get_modified_files_in_branch_remote(
3030
dagger_client, current_git_branch, current_git_revision, diffed_branch, repo_url=current_git_repo_url
3131
)
3232
modified_files = await container.with_exec(
33-
["diff", f"--diff-filter={DIFF_FILTER}", "--name-only", f"{diffed_branch}...{current_git_branch}"]
33+
["diff", f"--diff-filter={DIFF_FILTER}", "--name-only", f"origin/{diffed_branch}...target/{current_git_branch}"]
3434
).stdout()
3535
except SessionError:
3636
if retries > 0:

airbyte-ci/connectors/pipelines/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pipelines"
7-
version = "4.9.0"
7+
version = "4.10.0"
88
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
99
authors = ["Airbyte <[email protected]>"]
1010

0 commit comments

Comments
 (0)