1

I want to automate the release process of pypdf. The idea is that I just push a git tag and a Github Action creates a Github release.

In Bash, I use the following to set the `tag_body:

latest_tag=$(git describe --tags --abbrev=0)
tag_body=$(git tag -l "${latest_tag}" --format='%(contents:body)')

That works. But I also get the desired name with the following two steps, but the tag_body variable is always empty:

      - name: Prepare variables
        id: prepare_variables
        run: |
          git fetch --tags --force
          latest_tag=$(git describe --tags --abbrev=0)
          echo "latest_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
          echo "tag_body<<EOF" >> $GITHUB_ENV
          echo "$(git tag -l \"${latest_tag}\" --format='%(contents:body)')" >> $GITHUB_ENV
          echo "EOF" >> $GITHUB_ENV
          echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"
          echo "tag_body2=$(git tag -l \"${latest_tag}\" --format='%(contents:body)')" >> $GITHUB_ENV
          echo "tag_body3=$(git tag -l ${git describe --tags --abbrev=0} --format='%(contents:body)')" >> $GITHUB_ENV
      - name: Create GitHub Release 
        uses: actions/create-release@v1
        with:
          tag_name: ${{ github.ref }}
          release_name: Version ${{ env.latest_tag }}, ${{ env.date }}
          draft: false
          prerelease: false
          body: Body is ${{ env.tag_body }}

My suspicion is that it's either due to escaping or due to the multi-line string. How can I make the tag_body variable have the same value as locally in Bash?

Context

In case you wonder about the project: https://github.com/py-pdf/pypdf/pull/1970

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • Use `fetch-depth: 0` with `actions/checkout@v3` to fetch the git history. – Azeem Jul 16 '23 at 17:14
  • I have that in a previous step. I get the tag name, so the cloning is not the issue – Martin Thoma Jul 16 '23 at 17:58
  • Got it. You are manually fetching the tags before the `latest_tag` is set [here](https://github.com/py-pdf/pypdf/actions/runs/5569764049/workflow#L42-L49). Looks like the workflow is working fine now, right? I see that the PR has been merged. – Azeem Jul 17 '23 at 04:10
  • No, it's not. I merged it because I can manually edit the release and set the body. So it's already helpful, but not working completely as desired – Martin Thoma Jul 17 '23 at 05:39
  • Right. Tested your [scenario](https://rhysd.github.io/actionlint/#eJyFUc1PwjAUv/eveFkwg8PExFvDiNEgetGDH9el695YBdpl7SAL8r/bMrY5RL20fX2/j/ch2RopLISJDFtEXEmD0ugoVklFiJIUtqpYpiu1jRKhc2Z4RsiHijUlAFy4E6AopQ4ctoxLacpgxQxqQw45bTDXNSwAeTC7y5AvVWkOnwClRk2BcSOU1GN+TN5sro/5rTAZPb6tF+ZKC6OKikJeBXmSjvPKnqRn8YKNuq2NwmdLt41CirYLCALbsLZXqgqOLaCu3Q0jHAwdOkHNCxFjR2BxXOAmvBq1JOSZAq+jUhh0gdeDtYEbt5ty6NU+NoZgBd53Zl3dmpnQvxg2u6GONfJH3ol9I2jNm+cv1n38ZDJ7vvdgOrXe88fXh7fbaPb0fqreaf6HPK/WW8+8XQ/KDf0xEgr+YLdzucvmC/Z7//xG/2j+Cynk0Ck=). See: https://github.com/iamazeem/test/actions/runs/5573292945/jobs/10180372007 – Azeem Jul 17 '23 at 08:16
  • Have you tried to put all commands of `run` in a script ? – Philippe Jul 17 '23 at 08:36
  • I don't know what you mean – Martin Thoma Jul 17 '23 at 15:01

1 Answers1

1

tag_body is blank in your example because the following outputs blank:

echo "$(git tag -l \"${latest_tag}\" --format='%(contents:body)')"

You can verify that this is blank locally by doing:

echo "$(git tag -l \"3.12.2\" --format='%(contents:body)')"

By removing the \" around the $latest_tag reference, you will see that echo then output something:

echo "$(git tag -l ${latest_tag} --format='%(contents:body)')"

at which point the pipe into $GITHUB_ENV will now receive data. However, you could drop the echo altogether and pipe the output of the command itself into $GITHUB_ENV instead of passing it to echo to pipe it:

git tag -l "${latest_tag}" --format='%(contents:body)')" >> $GITHUB_ENV
MasterOdin
  • 7,117
  • 1
  • 20
  • 35