Skip to content

Conversation

@ydshieh
Copy link
Contributor

@ydshieh ydshieh commented May 27, 2025

Allow passing commit sha of the package, so we can checkout to it.

This is necessary when we want to trigger doc-build on a PR with other trigger event, like leaving a comment build-doc, otherwise it will checkout to the main branch in this case

Comment on lines +82 to +89
- name: Checkout to the correct commit
working-directory: ${{ inputs.package }}
run: |
git fetch https://github.com/${{ inputs.repo_owner }}/${{ inputs.package }}.git refs/pull/${{ inputs.pr_number }}/merge:refs/remotes/pull/${{ inputs.pr_number }}/merge
git checkout refs/remotes/pull/${{ inputs.pr_number }}/merge
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we checkout to the merge commit (this is what we get if the event is pull_request without the change in this PR, so the behavior would be consistent in both event types)

@ydshieh ydshieh changed the title [don't merge yet] Allow commit Explicitly checkout to PR commit Aug 12, 2025
Copy link
Contributor

@gante gante left a comment

Choose a reason for hiding this comment

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

LGTM

question: wouldn't ref: ${{ inputs.commit_sha }} on L81 work as well?

@gante gante requested a review from hanouticelina August 12, 2025 13:00
@gante
Copy link
Contributor

gante commented Aug 12, 2025

(tagged @hanouticelina for a second pair of 👀 )

@ydshieh
Copy link
Contributor Author

ydshieh commented Aug 12, 2025

You are likely right. The nit is:

in the caller (the workflow I created in transformers), we have

.github/workflows/pr_build_doc_with_comment.yml

    uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml
        commit_sha: ${{ needs.get-pr-info.outputs.PR_HEAD_SHA }}

which is the head sha of the branch, and that corresponds to

.github/workflows/build_pr_documentation.yml

    uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@main
    with:
      commit_sha: ${{ github.event.pull_request.head.sha }}

that also use the same head sha.

However, arriving doc-builder, in the file .github/workflows/build_pr_documentation.yml

If we use ref: ${{ inputs.commit_sha }}, it will checkout to the PR head sha.

However, currently (without this PR), it will checkout to the so called merge commit sha (when it is triggered by pull_request).
This is the usual way that Github Actions works: it doesn't directly use the head sha, but dynamically create a ``
merge commit.

So we want to:

  • follow what Github Actions does things (use merge commit sha)
  • follow what we have before (i.e. the doc is built with merge commit sha)

And if we don't grab this merge commit sha from the caller (which is extra work), the step I added is necessary

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

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

Conceptually approving ✅
my understanding of the PR: the extra step makes sure that no matter how the doc build is triggered, it always checks out the correct PR merge. That makes sense to me!

@gante
Copy link
Contributor

gante commented Aug 12, 2025

@ydshieh thank you for the detailed explanation 💛

@ydshieh ydshieh merged commit 6fe0dff into main Aug 12, 2025
4 checks passed
@ydshieh ydshieh deleted the allow_commit branch August 12, 2025 14:55
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.

4 participants