Skip to content

Commit

Permalink
Base files on source branch in PR workflows (#190)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chrisfenner authored Sep 24, 2024
1 parent f89905d commit 893fc8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/render.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,7 @@ jobs:
echo OUTPUT_FILENAME="${filename}" >> "$GITHUB_OUTPUT"
echo output filename: ${filename}
# For pull requests, check out the head ref of the source branch from the source repo.
- name: Checkout
if: inputs.workflow == 'pr'
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
fetch-tags: true
# For other workflows, check out the requested revision (which defaults to
# head of the default branch).
- name: Checkout
if: inputs.workflow != 'pr'
uses: actions/checkout@v4
with:
ref: ${{ inputs.revision }}
Expand Down
11 changes: 10 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ fi
# figure out git version and revision if needed.
EXTRA_PANDOC_OPTIONS=""
if test "${DO_GITVERSION}" == "yes"; then
if [ ! -z "${PR_NUMBER}" ] && $(git rev-parse HEAD^2 >/dev/null 2>/dev/null); then
# For PR workflows, base the version info on the right parent.
# In the context of a GitHub pull request, HEAD is a merge commit where
# parent1 (HEAD^1) is the target branch and parent2 (HEAD~2) is the source
GIT_COMMIT=$(git rev-parse --short HEAD^2)
else
# Otherwise, base the version info on HEAD.
GIT_COMMIT=$(git rev-parse --short HEAD)
fi

# TODO: Should we fail if dirty?
raw_version="$(git describe --always --tags)"
echo "Git version: ${raw_version}"
Expand All @@ -263,7 +273,6 @@ if test "${DO_GITVERSION}" == "yes"; then
# Where $REVISION is the number of commits since the last tag (e.g., 54)
# $VERSION-$REVISION-g$COMMIT --> version without prerelease tag at a particular commit (len 3)
# $VERSION-$PRERELEASE-$REVISION-g$COMMIT --> version with (len 4)
GIT_COMMIT=$(git rev-parse --short HEAD)
len=${#dash_hunks[@]}
case $len in
1)
Expand Down

0 comments on commit 893fc8c

Please sign in to comment.