Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a step manually with Github Actions

In every CI solutions, it's possible to pause a pipeline and wait to a manual approval to continue (Jenkins, CircleCI, GitlabCI).

How to do this with Github Actions ?

like image 543
Antoine Avatar asked Nov 15 '19 12:11

Antoine


4 Answers

Afaik there is no manual triggering at the moment. You can only re-run failed workflows.

But there are lots of useful events to achieve similar things.

Ex.: the Label event: Someone puts the "Approved" label on a PR.

Or the Pull request review comment event: Someone comments "Deploy to stage." on a PR.

like image 123
scthi Avatar answered Nov 14 '22 12:11

scthi


Seems you can do this now using Environments: https://devblogs.microsoft.com/devops/i-need-manual-approvers-for-github-actions-and-i-got-them-now/

Simply create an environment, select required reviewers, add yourself or a team, and then hit save.

Then associate the environment in your Github Actions YAML file like so

environment:
  name: <Your Github Environment here>

Then to release that step you can click "Review Deployments" and then choose which environment you want to deploy.

like image 26
Matt Dell Avatar answered Nov 14 '22 14:11

Matt Dell


There is a way to do it now (not sure when this started being available, but I just saw it). So basically just add "workflow_dispatch:" before your workflow like this

  # Controls when the workflow will run 
  on:
  # Triggers the workflow on push or pull request events but only for the master branch
    push:
      branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
    workflow_dispatch:

  # A workflow run is made up of one or more jobs that can run sequentially or in parallel
  jobs:
  # This workflow contains a single job called "build"
    build:
    # The type of runner that the job will run on
      runs-on: ubuntu-latest

And now when you navigate to "Actions" tab and select the workflow you added this command to, you see a "Run workflow" dropdown above the list. Use this control to manually run your workflow.

Here is where you should see the button.

like image 4
markovic-m Avatar answered Nov 14 '22 14:11

markovic-m


I have to work with GitHub Actions for my current work, I can't say I'm amazed on how they evolved this product with the Microsoft wallet backing them.

Anyway, there is still no dedicated feature to do that very simple and needed task. I got a not so bad and not so dirty workaround though.

  • If you are not using environments just define one, call it "manual_approval" or something similar and assign required approver (can be groups). That will do the trick.

  • If you are already using Environments (and you should). Just define 2 Environment entries for each (ie. "prod" & "prod-manual"). Then configure then the same way just adding the required approver on the manual one.

You now just have to add this environment in your pipeline as in this example:

name: manual approval demo
on:
  push:

jobs:
  tf_plan:
    name: Terraform Plan
    runs-on: terraform
    environment: Prod
    steps:
    ...

  tf_apply:
    name: Terraform Apply
    runs-on: terraform
    environment: Prod-manual
    steps:
    ...

You have to define 2 environments per real life environment as the workflow can reference only a single environment per job.

That's not perfect, but once again that's the less ugly I came up with. GitHub Actions is really lacking maturity compared to other tools.

like image 2
Nicolas Aizier Avatar answered Nov 14 '22 13:11

Nicolas Aizier