Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(get-modified-packages): support retrieving diffs without fetching all #299

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

xmfcx
Copy link
Contributor

@xmfcx xmfcx commented Jun 11, 2024

Description

Continuation from:

  • ci(build-and-test-differential): set checkout fetch-depth to 1 autoware.universe#7408

  • Renaming the input parameter name from base-branch to base-ref. (Mostly it defaults to main)

    • I think it is not used anywhere.
    • But we might use it for merge_group triggers in the future
  • It will run: git fetch origin ${{ inputs.base-ref }} to make sure it has common merge-base commit to get diffs

  • And now it is possible to only fetch the necessary commits instead of entire history of the repository. (For universe it allows time saving from about 2m30s to 6s)

  • Separate the get-modified-packages action into 2 steps so it will report if it fails

    • Also exit with failure on the sh script.
    • set -e is removed from the script because it is set by default on github actions.

Tests performed

Failure condition

image

It fails on failure.
https://github.com/autowarefoundation/autoware.universe/actions/runs/9482100138/job/26126284417?pr=7340#step:7:29

Success condition

image

And it is successful on success:
https://github.com/autowarefoundation/autoware.universe/actions/runs/9482151939/job/26126437257?pr=7340#step:7:35

Effects on system behavior

Not applicable.

Interface changes

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

  • There are no open discussions or they are tracked via tickets.

After all checkboxes are checked, anyone who has write access can merge the PR.

@xmfcx xmfcx self-assigned this Jun 11, 2024
@xmfcx xmfcx force-pushed the feat/support-partial-fetch branch from 2547fd9 to b4135e3 Compare June 11, 2024 14:22
@xmfcx xmfcx requested a review from HansRobo June 11, 2024 17:44
@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 11, 2024

I've fixed it.

Job: https://github.com/autowarefoundation/autoware.universe/actions/runs/9470181454/job/26090502061?pr=7340

Workflow: https://github.com/autowarefoundation/autoware.universe/actions/runs/9470181454/workflow?pr=7340#L33-L51

Github action PR:
https://github.com/autowarefoundation/autoware-github-actions/pull/299/files

First part

  • base-branch in the action is a bad idea because it hides the commit sha of the feature branch's base, it is just "main"
  • I've replaced it with base-sha, which is github.event.pull_request.base.sha and it is much more simple to use and fits better with the code (we don't need to add origin/ before it)
  • It works with existing jobs without problems

Second part

  • In order to fetch only what we need, we need to do it like this:
    steps:
      - name: "Set PR fetch depth"
        run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

      - name: "Checkout PR branch and all PR commits"
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: ${{ env.PR_FETCH_DEPTH }}

@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 11, 2024

This solution works for both fetch-depth: ${{ env.PR_FETCH_DEPTH }} and for fetch-depth: 0 so it is safe to merge.

You can test it with existing PRs if you need confirmation using uses: autowarefoundation/autoware-github-actions/get-modified-packages@v-test-shallow-copy tag. (Will remove it once this is merged.)

@xmfcx xmfcx marked this pull request as ready for review June 11, 2024 17:51
@xmfcx xmfcx changed the title feat(get-modified-packages): support fetching for shallow clones feat(get-modified-packages): get diffs from base-sha instead of implicit base-branch Jun 11, 2024
@xmfcx xmfcx requested a review from mitsudome-r June 11, 2024 17:55
@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 11, 2024

Outdated comment.

🖱️Click here to expand🔛

Screenshot from the job link above
image

@HansRobo
Copy link
Member

Thank you for taking over the job from me and completing it!
BTW, this is a breaking change and will affect people who specify base-branch in get-modified-packages@v1.
Would you consider bumping the repository major version?

@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 12, 2024

@HansRobo

If everyone used it with the default "base-branch" parameter, it won't break existing functionality, anyone using the old version can keep using the new version without modifying any code and it will work the same.

But if someone changed the "base-branch" parameter (which is github.base_ref which is main by default for most cases), then it won't work since this parameter no longer exists. But I've never seen anyone passing that variable to it. Everyone uses it to get the diffs from the place they've branched out. I think we could even remove that parameter completely, what do you think?

@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 12, 2024

We can still bump versions but then it will bump the versions of everything else in this repository too. Then any new change on them needs to be updated on the repository sides too (to v2) even if they were not changed. :(

@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 12, 2024

I've removed the input parameter because I don't see a use for it.
Also updated the readme to have both fetch-all and fetch-enough versions.

@HansRobo
Copy link
Member

@xmfcx
Thank you for the discussion!
Considering the pros and cons, it seems better not to bump the major version.

@xmfcx xmfcx marked this pull request as draft June 12, 2024 07:17
@xmfcx xmfcx force-pushed the feat/support-partial-fetch branch 2 times, most recently from 235cca8 to 498beca Compare June 12, 2024 09:39
@xmfcx xmfcx changed the title feat(get-modified-packages): get diffs from base-sha instead of implicit base-branch feat(get-modified-packages): support retrieving diffs without fetching all Jun 12, 2024
@xmfcx xmfcx force-pushed the feat/support-partial-fetch branch 2 times, most recently from 0f6c357 to d966cbf Compare June 12, 2024 11:21
Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
@xmfcx xmfcx force-pushed the feat/support-partial-fetch branch from d966cbf to 3fcb1c4 Compare June 12, 2024 11:22
Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
@xmfcx xmfcx marked this pull request as ready for review June 12, 2024 12:07
Copy link
Member

@HansRobo HansRobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
Thank you for working hard on this task!!

@xmfcx xmfcx merged commit 9a6e0b7 into main Jun 12, 2024
17 of 18 checks passed
@xmfcx xmfcx deleted the feat/support-partial-fetch branch June 12, 2024 12:26
@xmfcx
Copy link
Contributor Author

xmfcx commented Jun 12, 2024

To confirm, it is working well for regular PRs in the universe too:

@HansRobo
Copy link
Member

I have only found one person who uses the base-branch argument... and that is me haha 😆.
https://github.com/ibis-ssl/crane/blob/8a0fae59b45e578b53064878819aa65cb2af8cd1/.github/workflows/build_test.yaml#L70
Don't worry, I'll fix it according to the new specifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants