Skip to content

GO_BUILD_OPTIONS in build script not quoted; breaks ldflags -X #70

@Bertie690

Description

@Bertie690

Long story short, I am trying to pass version information (build time, commit SHA, version number, etc etc) down into the built gh extension binary to show when the --version flag is passed.

      - name: Create GitHub CLI extension
        uses: cli/gh-extension-precompile@v2
        with:
          draft_release: ${{github.event_name == 'workflow_dispatch'}}
          generate_attestations: true
          go_version_file: go.mod
          go_build_options: |
            -ldflags="-X 'github.com/Bertie690/gh-pr-list/cli.version=${{ env.GH_RELEASE_TAG }}' \
            -X 'github.com/Bertie690/gh-pr-list/cli.commit=${{ github.sha }}' \
            -X 'github.com/Bertie690/gh-pr-list/cli.buildTime=$(date --utc '+%a, %d %b %Y %T %Z')'"

I spent several hours and many many wasted workflow runs on this before copy-pasting your provided script and regressing it down to a simple quoting issue:
https://github.com/cli/gh-extension-precompile/blob/9e2237c30f869ad3bcaed6a4be2cd43564dd421b/build_and_release.sh#L75C1-L76C1

The ${GO_BUILD_ARGS} here should be quoted (like most variable accesses in shell scripts)

How do I know this works? I copied over your build_and_release.sh and added double quotes to that singular line and nothing else. To my surprise, go build went from crashing to working like a charm.

Workarounds

While a temporary workaround would be to copy over the build script and use that instead, this fix is so trivial that it simply isn't worth the hassle.

I am happy to work on a PR to fix this (given it is quite literally 1 line of code).

(Ironically, this would've probably been fixed had #51 been merged, but better late than never I suppose...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions