[go: up one dir, main page]

DEV Community

Cover image for Manual Trigger on Github action - #2
Hidayt Rahman
Hidayt Rahman

Posted on

Manual Trigger on Github action - #2

Intro

In the Github action session, In this article we will be learning about Manual Trigger action for the specific task.

Why we need this?
We often require some short of actions that we only do when we need any specific action.
For example, you wanna release your app from dev env to qa env after fixing a new bug.
In this case we can use Manual trigger that will deploy app from dev to qa once we trigger the action.

Also Read
In the last article We learnt Greet on first PR and Issue

How can we do that?
We can achieve the manual trigger feature using Workflow Dispatch It enables a workflow to be triggered manually, you need to configure the workflow_dispatch event. You can manually trigger a workflow run using the GitHub API, GitHub CLI, or GitHub browser interface

Lets create a brand new workflow under the .github/workflows/manualTrigger.yml

Paste the below code and push your changes to the main branch.

name: "Workflow Manual Trigger"

on: 
  workflow_dispatch:
    inputs:
      author:
       description: 'Choose author'
       required: true
       type: choice
       options:
                - admin
                - editor
                - contributor
      location:
        description: 'Choose Location'     
        required: true
        default: 'in'
        options:
                - us
                - uk
                - in



jobs:
  printInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Author : ${{ github.event.inputs.author }}"
        echo "Location : ${{ github.event.inputs.location }}" 
Enter fullscreen mode Exit fullscreen mode

Now go the actions tab and select Workflow Manual Trigger

Click on the Run Workflow button

Run workflow image

Choose the fields.

Opened workflow image

After selecting the specific field click on green Run workflow button

It will start running the workflow. Once done you can verify the actions while opening the logs.

Action logs

You can see we have the selected data in the logs.

Feel free to utilise the action based on your requirement.

Happy Action!

Top comments (0)