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

FIX Set fetch-depth for parent-branch #31

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,42 @@ jobs:

steps:

- name: Set fetch depth
id: set-fetch-depth
env:
GITHUB_REPOSITORY: ${{ github.repository }}
shell: bash
run: |
# Default fetch-depth of 1 will only fetch the latest commit
# This is fine for non-pull-request events where standard major.minor naming conventions
# are used so we do not need to attempt to get the name of the parent branch
FETCH_DEPTH=1
# For pull-requests, set fetch-depth to one more than the number of commits
# so we can later make a best attempt at getting the name of the parent branch
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
PR_NUMBER=${{ github.event.pull_request.number }}
# https://docs.github.com/en/rest/pulls/pulls#list-commits-on-a-pull-request
RESP_CODE=$(curl -w %{http_code} -s -o __pr_commits.json \
-X GET https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/commits \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ github.token }}" \
)
if [[ $RESP_CODE == "200" ]]; then
NUM_COMMITS=$(cat __pr_commits.json | jq '. | length')
FETCH_DEPTH=$(( NUM_COMMITS + 1 ))
rm __pr_commits.json
else
echo "Failed to fetch commits for pull-request - HTTP response code was $RESP_CODE"
exit 1
fi
fi
echo "FETCH_DEPTH is $FETCH_DEPTH"
echo "::set-output name=fetch-depth::$FETCH_DEPTH"

- name: Checkout code
uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2.4.2
with:
fetch-depth: ${{ steps.set-fetch-depth.outputs.fetch-depth }}

- name: Install PHP
# SHA will need to be updated to support new php version when they are released
Expand Down