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

Add: [checkout-pull-request] action to checkout all commits of a single Pull Request #26

Merged
merged 1 commit into from May 20, 2021

Conversation

TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented May 20, 2021

Replaces the bash blob for use now everywhere for a single action that does the complexity.

Example of old:

    - name: Get pull-request commits
      run: |
        set -x
        # actions/checkout did a merge checkout of the pull-request. As such, the first
        # commit is the merge commit. This means that on HEAD^ is the base branch, and
        # on HEAD^2 are the commits from the pull-request. We now check if those trees
        # have a common parent. If not, we fetch a few more commits till we do. In result,
        # the log between HEAD^ and HEAD^2 will be the commits in the pull-request.
        DEPTH=4
        while [ -z "$(git merge-base HEAD^ HEAD^2)" ]; do
            # Prevent infinite recursion
            if [ ${DEPTH} -gt 256 ]; then
                echo "No common parent between '${GITHUB_HEAD_REF}' and '${GITHUB_BASE_REF}'." >&2
                exit 1
            fi

            git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --deepen=${DEPTH} origin HEAD
            DEPTH=$(( ${DEPTH} * 4 ))
        done

        # Just to show which commits we are going to evaluate.
        git log --oneline HEAD^..HEAD^2

Example of new:

    - name: Get pull-request commits
      uses: openttd/actions/checkout-pull-request@v2

Example of the result:
https://github.com/TrueBrain/OpenTTD-actions/pull/1/checks?check_run_id=2628923073

In the check commits step you can see it found all the commits of the PR.

@TrueBrain TrueBrain merged commit 50599fe into OpenTTD:master May 20, 2021
@TrueBrain TrueBrain deleted the history branch May 20, 2021 16:12
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.

None yet

2 participants