Fetching a git trailer in a single-commit PR

11 views
Skip to first unread message

shamim rana

unread,
Jan 20, 2025, 9:11:03 PM1/20/25
to GitHub Copilot in Visual Studio Code
I am using Renovate to generate PRs with a git trailer. These PRs always only contain a single commit. I have configured Renovate to embed a list of the updates in the commit body, and now I want to fetch that list in a Github Actions step.

Currently, I set GITHUB_SHA={{github.event.pull_request.head.sha}} and then I use git log ${GITHUB_SHA}^1..${GITHUB_SHA}^2 with the right formatting argument, which extracts the trailer.

It works, but it seems fragile. It requires the merge commit parents to be ordered. It requires the merge commit to be present. I want the step to be reusable, and to work even if the checkout action is used with an alternative ref. Currently, it would break given that it operates on the merge commit.

How can I more succinctly extract a git trailer from a Renovate generated PR?

My current step, which seems too inelegant (from source):

  - name: Extract New-Versions git trailer from Renovate
    if: ${{ github.event_name == 'pull_request' }}
    env:
      GITHUB_SHA: "{{ github.event.pull_request.head.sha }}"
    run: |
      echo 'packages: .' > cabal.project
      for constraint in $(git log "--format=%(trailers:key=New-Versions,valueonly=true)" ${GITHUB_SHA}^1..${GITHUB_SHA}^2)
        do echo "constraints: $constraint" >> cabal.project
      done
Reply all
Reply to author
Forward
0 new messages