Marco
Marco

Reputation: 5109

Conditionally append a string in a GitHub actions workflow

Is it possible to use GitHub Actions expressions to concatenate a string conditionally?

E.g. like I'm trying to do in below example.

      - name: Release
        uses: goreleaser/goreleaser-action@v2
        with:
          version: latest
          args: release --rm-dist  ${{ if (startsWith(github.ref, 'refs/tags/')) { '--snapshot' }}

Upvotes: 15

Views: 6640

Answers (1)

Bertrand Martel
Bertrand Martel

Reputation: 45523

You could use the following which would return -additional-arg if the condition is satisfied and empty string otherwise:

${{ (startsWith(github.ref, 'refs/tags/') && '-additional-arg') || '' }}

Example:

name: Test arguments

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Release
        uses: goreleaser/goreleaser-action@v2
        with:
          version: latest
          args: release --rm-dist ${{ (startsWith(github.ref, 'refs/tags/') && '--snapshot') || '' }}

Upvotes: 18

Related Questions