[GitHub Actions] How to execute GitHub Actions manually

2024-09-16 hit count image

Let's see how to execute GitHub Actions manually.

Outline

When using GitHub Actions, sometimes you need to run GitHub Actions manually. In this blog post, I’ll introduce how to run GitHub Actions manually.

workflow_dispatch

To run GitHub Actions manually, you need to use workflow_dispatch.

At this time, you can pass parameters through inputs of workflow_dispatch.

You can set workflow_dispatch as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:

inputs type

You can use the following types in inputs of workflow_dispatch.

  • boolean: true or false
  • choice: SelectBox that can select one of the predefined options
  • number: number
  • string: string
  • environment: Use environment variables set in GitHub

You can check the inputs type that can be used in the official document.

Yon can set inputs of workflow_dispatch as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:
    inputs:
      input_boolean:
        description: 'This is a boolean input'
        required: true
        default: false
        type: boolean

You can set the description, required, default in addition to the type in inputs of workflow_dispatch. Except for type, all are optional.

Example

Then, let’s see an example about how to run GitHub Actions manually using workflow_dispatch.

boolean

To create GitHub Actions that run manually, create a .github/workflows/manual_test.yml file and modify it as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:
    inputs:
      input_boolean:
        description: 'This is a boolean input'
        required: true
        default: false
        type: boolean

jobs:
  deploy-to-staging:
    runs-on: ubuntu-latest
    steps:
      - name: Print the input
        run: echo $

After committing and pushing the file you wrote like this, you can see the following screen when you go to the Actions tab of GitHub.

Execute GitHub Actions manually - Boolean input

When you click the Run workflow displayed on the right side, you can see the inputs of the boolean type we’ve set. If you run this, you can get the following result.

Execute GitHub Actions manually - Boolean input result

choice

To create GitHub Actions that run manually, create a .github/workflows/manual_test.yml file and modify it as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:
    inputs:
      input_choice:
        description: 'This is a choice input'
        required: true
        default: 'warning'
        type: choice
        options:
          - info
          - warning
          - debug

jobs:
  deploy-to-staging:
    runs-on: ubuntu-latest
    steps:
      - name: Print the input
        run: echo $

After committing and pushing the file you wrote like this, you can see the following screen when you go to the Actions tab of GitHub.

Execute GitHub Actions manually - Choice input

When you click the Run workflow displayed on the right side, you can see the inputs of the choice type we’ve set. If you run this, you can get the following result.

Execute GitHub Actions manually - Choice input result

number

To create GitHub Actions that run manually, create a .github/workflows/manual_test.yml file and modify it as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:
    inputs:
      input_number:
        description: 'This is a number input'
        required: true
        default: 20
        type: number

jobs:
  deploy-to-staging:
    runs-on: ubuntu-latest
    steps:
      - name: Print the input
        run: echo $

After committing and pushing the file you wrote like this, you can see the following screen when you go to the Actions tab of GitHub.

Execute GitHub Actions manually - Number input

When you click the Run workflow displayed on the right side, you can see the inputs of the number type we’ve set. If you run this, you can get the following result.

Execute GitHub Actions manually - Number input result

string

To create GitHub Actions that run manually, create a .github/workflows/manual_test.yml file and modify it as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:
    inputs:
      input_string:
        description: 'This is a string input'
        required: true
        default: 'Hello, World!'
        type: string

jobs:
  deploy-to-staging:
    runs-on: ubuntu-latest
    steps:
      - name: Print the input
        run: echo $

After committing and pushing the file you wrote like this, you can see the following screen when you go to the Actions tab of GitHub.

Execute GitHub Actions manually - String input

When you click the Run workflow displayed on the right side, you can see the inputs of the string type we’ve set. If you run this, you can get the following result.

Execute GitHub Actions manually - String input result

environment

To use the environment type in workflow_dispatch, you need to set Environment in GitHub’s Settings.

Execute GitHub Actions manually - Environments

Click New environment and enter dev in the Name as follows, and click Configure environment.

Execute GitHub Actions manually - New Dev Environment

Then click the Add environment variable button in Environment variables and add the Variable as follows.

Execute GitHub Actions manually - Dev environment variable

In the same way, add the same variable to the prod environment.

Execute GitHub Actions manually - Prod environment variable

Now, create a .github/workflows/manual_test.yml file to run GitHub Actions manually and modify it as follows.

name: GITHUB ACTIONS NAME

on:
  workflow_dispatch:
    inputs:
      input_environment:
        description: 'This is a environment input'
        required: true
        type: environment

jobs:
  deploy-to-staging:
    runs-on: ubuntu-latest
    environment: $
    steps:
      - name: Print the input
        run: echo $

After committing and pushing the file you wrote like this, you can see the following screen when you go to the Actions tab of GitHub.

Execute GitHub Actions manually - Environment input

When you click the Run workflow displayed on the right side, you can see the Environment that we’ve set in GitHub’s Settings. If you run this, you can get the following result.

  • dev environment
Execute GitHub Actions manually - Environment input result dev
  • prod environment
Execute GitHub Actions manually - Environment input result prod

Completed

Done! We’ve seen how to run GitHub Actions manually. We also learned about the inputs type that can be set.

If you need to run GitHub Actions manually, try using workflow_dispatch and various types of inputs to run GitHub Actions manually.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts