0

What specifically needs to change in the -f body=$DESCRIPTION flag of the gh api CLI command in the GitHub workflow below in order for a multi-word string such as "Lots of new stuff" to successfully be passed into the description of the resulting GitHub release?

The problem we are currently having is that the "Lots of new stuff" string results in an error stating that the body expects 1 argument but received 4.

When we pass a single-word string into the same workflow, it runs successfully without error.

When we change the body flag to read -f body='$DESCRIPTION', the resulting description for the release is rendered as $DESCRIPTION.

WORKFDLOW CODE:

name: release-manually
on:
  workflow_dispatch:
    inputs:
      version:
        description: 'Version'
        required: true
        type: string
      description:
        description: 'Description of release'
        required: true
        type: string
jobs:
  release-a-version:
    runs-on: ubuntu-latest
    steps:
      - shell: bash
        name: Release
        env:
          DESCRIPTION: ${{ inputs.description }}
          VERSION: ${{ inputs.version }}
          GH_TOKEN: ${{ secrets.GIT_PAT }}
        run: |
          vers="_linux_"$VERSION
          echo "About to print version"
          echo $vers
          nameOfRelease="release_name"$vers
          echo "About to print name of release"
          echo $nameOfRelease 
          echo "About to create release"
          gh api \
            --method POST \
            -H "Accept: application/vnd.github+json" \
            /repos/AccountName/RepoName/releases \
            -f tag_name=$vers \
            -f target_commitish='branch-name' \
            -f name=$nameOfRelease \
            -f body=$DESCRIPTION \
            -F draft=false \
            -F prerelease=false \
            -F generate_release_notes=false 
CodeMed
  • 5,199
  • 2
    Since double quotes seem to work on the -H "Accept: application/vnd.github+json" line, I would try them around the value you're asking about: -f body="$DESCRIPTION". Shells will expand "$DESCRIPTION" (wrapped in double-quotes) where they won't expand '$DESCRIPTION' (wrapped in single-quotes) – Sotto Voce Sep 08 '22 at 20:43
  • @SottoVoce The double quotes worked. I just needed another set of eyes to look at it. Thank you. – CodeMed Sep 08 '22 at 21:08

1 Answers1

0

I didn't think this question would let me learn a new thing, I stand corrected.

Firstly, I think the question could be flagged a duplicate of the explanation of quotes as @rugk said at this supposedly duplicate stackoverflow question.

Now the fun part is I had no idea there is functionality such as VAR=$'hello\nworld' which is exact same as:

VAR='hello
world'

Use -f body="$DESCRIPTION" and you should be fine. Also skim those links above and maybe have a look at parameter expansion as well for a through understanding.

cbugk
  • 436