Skip to content

Commit 893fc8c

Browse files
authored
Base files on source branch in PR workflows (#190)
* Detect merge commits (as in PRs) and switch to first parent if so * always do the unified checkout action * Only check out right parent on PRs * instead of checking out the right parent, just reference the commit
1 parent f89905d commit 893fc8c

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

.github/workflows/render.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,7 @@ jobs:
4848
echo OUTPUT_FILENAME="${filename}" >> "$GITHUB_OUTPUT"
4949
echo output filename: ${filename}
5050
51-
# For pull requests, check out the head ref of the source branch from the source repo.
5251
- name: Checkout
53-
if: inputs.workflow == 'pr'
54-
uses: actions/checkout@v4
55-
with:
56-
ref: ${{ github.head_ref }}
57-
repository: ${{ github.event.pull_request.head.repo.full_name }}
58-
fetch-depth: 0
59-
fetch-tags: true
60-
# For other workflows, check out the requested revision (which defaults to
61-
# head of the default branch).
62-
- name: Checkout
63-
if: inputs.workflow != 'pr'
6452
uses: actions/checkout@v4
6553
with:
6654
ref: ${{ inputs.revision }}

build.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,16 @@ fi
245245
# figure out git version and revision if needed.
246246
EXTRA_PANDOC_OPTIONS=""
247247
if test "${DO_GITVERSION}" == "yes"; then
248+
if [ ! -z "${PR_NUMBER}" ] && $(git rev-parse HEAD^2 >/dev/null 2>/dev/null); then
249+
# For PR workflows, base the version info on the right parent.
250+
# In the context of a GitHub pull request, HEAD is a merge commit where
251+
# parent1 (HEAD^1) is the target branch and parent2 (HEAD~2) is the source
252+
GIT_COMMIT=$(git rev-parse --short HEAD^2)
253+
else
254+
# Otherwise, base the version info on HEAD.
255+
GIT_COMMIT=$(git rev-parse --short HEAD)
256+
fi
257+
248258
# TODO: Should we fail if dirty?
249259
raw_version="$(git describe --always --tags)"
250260
echo "Git version: ${raw_version}"
@@ -263,7 +273,6 @@ if test "${DO_GITVERSION}" == "yes"; then
263273
# Where $REVISION is the number of commits since the last tag (e.g., 54)
264274
# $VERSION-$REVISION-g$COMMIT --> version without prerelease tag at a particular commit (len 3)
265275
# $VERSION-$PRERELEASE-$REVISION-g$COMMIT --> version with (len 4)
266-
GIT_COMMIT=$(git rev-parse --short HEAD)
267276
len=${#dash_hunks[@]}
268277
case $len in
269278
1)

0 commit comments

Comments
 (0)