goreleaser / goreleaser-action

GitHub Action for GoReleaser
https://github.com/marketplace/actions/goreleaser-action
MIT License
856 stars 75 forks source link

goreleaser workflow testing with `--snapshot` on `pull_request` no longer works in V4 #387

Closed jaqx0r closed 1 year ago

jaqx0r commented 1 year ago

Happy New Year!

In V3 and earlier, one could have the same workflow launched on a pull_request as well as a tag trigger, and in the former goreleaser-action would go into --snapshot mode to allow the config to be tested. This was good as it meant one could test changes to the config in advance of merging and tagging.

goreleaser-action@v4 seems to have regressed the feature for running with --snapshot when triggered by pull_request and not tag, breaking that feature.

https://github.com/google/mtail/actions/runs/3764076951/jobs/6398151701 is a failed run on a pull request with V4 which includes the output:

Run goreleaser/goreleaser-action@v4.1.0
  with:
    version: latest
    args: release --rm-dist
    distribution: goreleaser
    workdir: .
    install-only: false
  env:
    GITHUB_TOKEN: ***
Downloading https://github.com/goreleaser/goreleaser/releases/download/v1.13.1/goreleaser_Linux_x86_64.tar.gz
Extracting GoReleaser
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/852ba213-ba3b-4f9b-9a45-711602ebb679 -f /home/runner/work/_temp/957e67b8-f4a4-461f-b458-9bff6efddef5
GoReleaser latest installed successfully
/opt/hostedtoolcache/goreleaser-action/1.13.1/x64/goreleaser release --rm-dist
  • starting release...
  • loading config file                              file=.goreleaser.yml
  • loading environment variables
  • getting and validating git state
    • building...                                    commit=cf609141417ac3163b73f892a2a9d7ec65ec3164 latest tag=v3.0.0-rc51
  ⨯ release failed after 0s                  error=git tag v3.0.0-rc51 was not made against commit cf609141417ac3163b73f892a2a9d7ec65ec3164
Error: The process '/opt/hostedtoolcache/goreleaser-action/1.13.1/x64/goreleaser' failed with exit code 1

Downgrading to V3, the workflow succeeds as see nin https://github.com/google/mtail/actions/runs/3814614109/jobs/6489047363

Run goreleaser/goreleaser-action@v3
 with:
    version: latest
    args: release --rm-dist
    distribution: goreleaser
    workdir: .
    install-only: false
  env:
    GITHUB_TOKEN: ***
Downloading https://github.com/goreleaser/goreleaser/releases/download/v1.14.0/goreleaser_Linux_x86_64.tar.gz
Extracting GoReleaser
/usr/bin/tar xz --warning=no-unknown-keyword --overwrite -C /home/runner/work/_temp/3e3e09ee-2ca5-4b64-81b1-e445da0eda22 -f /home/runner/work/_temp/b0e45051-4f2f-41ec-96bb-95d5f2109911
GoReleaser latest installed successfully
No tag found for commit 'a0a3db43'. Snapshot forced
/opt/hostedtoolcache/goreleaser-action/1.14.0/x64/goreleaser release --rm-dist --snapshot
  • starting release...
  • loading config file                              file=.goreleaser.yml
  • loading environment variables
  • getting and validating git state
    • building...                                    commit=a0a3db43fa29cc3a16c4e43e44c1dd65d961ddb2 latest tag=v3.0.0-rc51
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
      • DEPRECATED: `archives.replacements` should not be used anymore, check https://goreleaser.com/deprecations#archivesreplacements for more info
  • running before hooks
    • running                                        hook=go mod download
    • took: 7s
  • snapshotting
    • building snapshot...                           version=v3.0.0-rc51-next
  • checking distribution directory
  • loading go mod information
  • build prerequisites
  • writing effective config file
...

As you can see the downgrade to V3 includes the --snapshot flag in the commandline for goreleaser, and V4 no longer adds it, causing the tag lookup error.

I presume this is related to #382 as that's intentionally changed this logic.

I'd like to preserve the behaviour in my workflow of performing a "dry" test of the goreleaser config so it isn't broken accidentally, and so that changes to the goreleaser config get correctly tested as a pull_request as well. How can I get the feature back?

caarlos0 commented 1 year ago

Hey, happy new year!

Here's an example: https://github.com/caarlos0/goreleaser-action-v4-auto-snapshot-example

Hope it helps :)

jaqx0r commented 1 year ago

I wonder if you can leave some comments in the README of that repo that explains the necessary parts that make it work?

Without context it's a bit hard to piece together what I need to copy into my own workflow.

I assume the good bits are the

      - run: echo "flags=--snapshot" >> $GITHUB_ENV
      - if: startsWith(github.ref, 'refs/tags/v')
        run: echo "flags=" >> $GITHUB_ENV

and then

          args: release --rm-dist ${{ env.flags }}

later on.

Is it sufficient to replace the first section with


      - if: !startsWith(github.ref, 'refs/tags/v')
        run: echo "flags=--snapshot" >> $GITHUB_ENV

or is there a good reason to have inverted the test?

jaqx0r commented 1 year ago

Figured it out, and there's another example now in google/mtail#704

caarlos0 commented 1 year ago

ahh, good one, lemme improve that in my example as well