6

I'm trying to build a workflow_dispatch (ie manual) Github action that pre-fills the input fields with the SHA of the branch.

ie

name: Manually tag a release
on: 
  workflow_dispatch:
    inputs:
      git-sha:
        description: Release SHA
        default: <prefill with GITHUB_SHA>
        required: true

I've tried default: ${{ github.sha }} but that throws an error.

Is this possible and what is the syntax?

Ben
  • 10,931
  • 9
  • 38
  • 47
  • Can you try setting the default to `${{ env.GITHUB_SHA }}` and let me know if that works? I haven't tested it myself in a minimal example, but once I do I can write up a full answer. – jidicula Feb 02 '21 at 18:41
  • Also, how are you using the `git-sha` input later in the workflow? – jidicula Feb 03 '21 at 01:22
  • @jidicula I'm using the SHA as a unique tag for that build/release in another system. When I put `${{ env.GITHUB_SHA }}` it just places that string in the text box not the contents of the variable – Ben Feb 03 '21 at 19:09
  • Would my answer [here](https://stackoverflow.com/a/65650260/6310633) be helpful? I'm not sure if that answer maps to your issue, though. – jidicula Feb 03 '21 at 21:41

1 Answers1

2

I just solved this problem a couple of days ago, but in a different way.

I set the required to false and then coalesced the input with the GITHUB_SHA

name: Deploy To PROD

on: 
  workflow_dispatch:
    inputs:
      sha:
        description: 'Git SHA to Deploy'

jobs:
  deploy_prod:
    runs-on: ubuntu-latest
    env:
      SHA_TO_DEPLOY: ${{ github.event.inputs.sha || github.sha }}

Then ${{ env.SHA_TO_DEPLOY }} references the SHA that was passed in, or the default if none was passed in.

Drew Delano
  • 1,421
  • 16
  • 21