GitHub Actions Manual Trigger / Approvals

Feature Request: GitHub Actions Manual Trigger / Approvals

As far as I can tell, there is no way to manually trigger a workflow execution. If there is, how is it done?

If not, I would like to request an additional event trigger called “manual” that would allow one to arbitrarily trigger an exeuction from the Actions UI within GitHub. My use case is to use Actions as a deployment tool and have the ability to run workflows on older commits (rollbacks) or have production deployment workflows be manually triggered.

In addition to that, the ability to have manual approvals as part of job steps in a workflow would be nice. Similar to the above use case, this would be to have build/tests and development deployments happen automatically, but production deployment steps could be dependent on a manual approval to continue workflow execution.

556 Likes

Hi @blytheaw,

Thanks for this feedback! We’re always working to improve GitHub and the GitHub Community Forum, and we consider every suggestion we receive. I’ve logged your feature request in our internal feature request list. Though I can’t guarantee anything or share a timeline for this, I can tell you that it’s been shared with the appropriate teams for consideration.

Cheers!

115 Likes

might be possible with the API as per https://help.github.com/en/articles/events-that-trigger-workflows#external-events?

7 Likes

It’s very limited right now. It’s impossible to pass any custom parameters, and the workflow YAML file must sit on master.

2 Likes

I’m surprised this wasn’t included with the initial offering. I imagine a lot of people will want to follow the same track in using Actions for deployment. I’m trying to figure out a nicer alternative for the time being, but this would be a useful and much needed addition.

8 Likes

I was really surprised when I found out there was no way to trigger an action manually from the repo.

Coming from GitLab’s CI, this is an important feature for us. We find it cumbersome to use an API to trigger our deployments.

I hope this feature is gonna make it in the initial release of GitHub actions.

13 Likes

There should be a button for this in the interface, yes. In the meantime you should be able to trigger a build manually by sending a Repository Dispatch Event to the GitHub API. If you use something like PostMan you can save a request that does that, or simply create a small curl script that you can run from your machine.

You can then attach your workflow to the repository_dispatch event to have it triggered when you POST to the API:

on: repository_dispatch

jobs:
  manual_deploy:
    steps:
      - name: Checkout master
        uses: actions/checkout@v1
        with:
          ref: master
      - <and so on>

It’s not ideal, but it should allow you to trigger manual builds until official support is added to the UI.

18 Likes

Deployment as been mentioned above.

If you are doing a deployment, do not use repository_dispatch. GitHub has first class support for deployment workflows:

https://developer.github.com/v3/repos/deployments/

Trigger a deployment via the API (we have internal tooling to ease this)

curl POST -H "Authorization: token $GITHUB_TOKEN" \
          -H "Accept: application/vnd.github.ant-man-preview+json" \
          -H "Content-Type: application/json" \
          https://api.github.com/repos/org/repo/deployments \
          --data '{"ref": "master", "environment": "production"}'

Then have a workflow to do your deployment:

name: 'Deploy'
on: ['deployment']

jobs:
  deployment:

    runs-on: 'ubuntu-latest'

    steps:
    - name: 'Checkout'
      uses: 'actions/checkout@v1'

    - name: 'Deployment pending'
      uses: 'deliverybot/status@master'
      with:
        state: 'pending'
        token: '${{ secrets.GITHUB_TOKEN }}'

# do your deployment here, using whatever tooling you like:
    - name: 'Deploy ${{ github.event.deployment.environment }}'
      run: |
        echo "task - ${{ github.event.deployment.task }}"
        echo "environment - ${{ github.event.deployment.environment }}"
        echo "payload - ${{ toJson(github.event.deployment.payload) }}"

    - name: 'deployment success'
      if: success()
      uses: 'deliverybot/status@master'
      with:
        state: 'success'
        token: '${{ secrets.GITHUB_TOKEN }}'

    - name: 'deployment failure'
      if: failure()
      uses: 'deliverybot/status@master'
      with:
        state: 'failure'
        token: '${{ secrets.GITHUB_TOKEN }}' 
37 Likes

Minor: The curl command looks like this. You need to pass an empty array to required_contexts or create a status for a commit sha. 

curl \
-X POST \
-H "Authorization: token $GIT_PERSONAL_ACCESS_TOKEN" \
-H "Accept: application/vnd.github.ant-man-preview+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/bqh-kaiserhl/all/deployments \
--data '{"ref": "master", "required_contexts": [], "environment": "production"}'
1 Like

Hello. Please let us know if it’s possible to do it now. This feature is very important though. 

32 Likes

As someone trying to move from Azure DevOps Pipelines to GitHub actions, having no manual triggers/approvers is a step back :slightly_frowning_face: Hope to see this feature added very soon.

17 Likes

@seanfeldman wrote:

having no manual triggers/approvers is a step back

You can have manual approvers if you have a workflow that is attached to the issue_comment type.

For example, the following workflow would run whenever someone would comment “OK to test” in a PR (which is internally seen as a type of issue by GitHub):

name: Run on demand

on:
  issue_comment:
    types: [created, edited]

jobs:
  ondemand:
    runs-on: ubuntu-latest
    if: github.event.comment.body == 'OK to test'

    steps:
      - name: Hello world
        run: echo Hello world, I was run on demand by ${GITHUB_ACTOR}

Additionally, you can also restrict which users are allowed to trigger a workflow this way, by doing checks against the github.event.comment.user.login variable or the GITHUB_ACTOR environment variable.

17 Likes

does this still work for you? i’ve attempted to use this solution and my workflows are not being triggered by posting a comment anywhere - issue or PR, even while not including the “conditional” statement

e.g.:

name: deploy_to_channel_on_demand

on:
  pull_request_review_comment:
    types: [created, edited]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: logging
        run: echo "$GITHUB_REF"

Deliverybot (using github deployments) might be something that solves this issue. I let deliverybot automatically deploy to the staging server, check if everything is working and manually deploy to producting using deliverybot. 

1 Like

This definitely looks promising as a stop-gap, but I would love to see this as native GitHub functionality. Especially if DeliveryBot becomes a paid product once it is out of beta. I couldn’t find any information on the beta / pricing status for DeliveryBot though.

However, it does look like this will meet our requirements for triggering deployments in the meantime. However, from what I can tell, the approval gate use case is still not covered by this tool.

3 Likes

https://deliverybot.dev/docs/guide/6-promotion/
Documentation isn’t great, it also doesn’t work with caching yet, so I’m just using on: push again.

1 Like

Any news regarding this matter?

The manual approval/trigger functionality would be greatly appreciated, and we are sorry that this is lacking from your otherwise great product :slight_smile: Otherwise we would have started moving other build and deploy-pipelines to Github Actions right away!

11 Likes

This is very important.  We need GitLab’s when:manual stuff and it should come with list of approved users

19 Likes

Hi @uladkasach , you have to use issue_comment for posting a Pull Request comment instead of using  pull_request_review_comment  to trigger the workflow when there is a pull request comment. 

name: deploy_to_channel_on_demand

on:
  issue_comment:
    types: [created, edited]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: logging
        run: echo "$GITHUB_REF"
1 Like

As mentioned in https://github.community/t5/GitHub-Actions/repository-dispatch-not-triggering-actions/m-p/33845/highlight/true#M1677, repository_dispatch will only trigger on default (master) branch.

2 Likes