diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 9636632..20ce62e 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -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 }} diff --git a/build.sh b/build.sh index 51a2f3b..f04bc2e 100755 --- a/build.sh +++ b/build.sh @@ -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}" @@ -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)