goreleaser separate flows for merging to master and for cutting release

432 Views Asked by At

GoReleaser & GitHub actions are currently configured as follows when a tag is pushed:

# github action
name: Release

on:
  push:
    tags:
      - '*'

env:
  REF: ${{ github.event.inputs.tag || github.ref }}

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          version: latest
          args: release --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# .goreleaser.yaml snippet
dockers:
  - image_templates:
    - "foo/bar:latest"
    - "foo/bar:v{{ .Major }}"
    - "foo/bar:v{{ .Major }}.{{ .Minor }}"
    - "foo/bar:{{ .Tag }}"

The current setup has the disadvantage that I have to wait until we cut a release to play with latest. It also means that latest is out of sync with Master branch in GitHub. I would like to build and publish latest - potentially several times per day - whenever my automated tests are successful, and I merge to master branch.

I would like goreleaser to build an publish in different senarios.

  1. whenever I merge a pull request to master, build & push latest
  2. whenever I tag a release, build and push semver tags

The logical way to achieve this would be simply to have 2 github actions, which would operate on different .goreleaser.yml files. However the problem is that I cannot find a way to override the goreleaser.yaml

1

There are 1 best solutions below

0
On

you can override the goreleaser config file with

args: release --rm-dist -f path_to_goreleaser.yml

Although goreleaser will refuse to publish anything if current commit is not a tag. Maybe what you'll need to do is some sort of automated tagging on each commit and run goreleaser against that tag, solving the image templates and etc using go templates only.

It will likely be very hacky, but I think it might work.