Skip to content

Instantly share code, notes, and snippets.

@garywill
Created January 30, 2025 06:21
Show Gist options
  • Save garywill/8cfcbda62197c145e100079fce334d3c to your computer and use it in GitHub Desktop.
Save garywill/8cfcbda62197c145e100079fce334d3c to your computer and use it in GitHub Desktop.

Revisions

  1. garywill created this gist Jan 30, 2025.
    28 changes: 28 additions & 0 deletions trigger_github_action.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/bin/bash

    # https://docs.github.com/zh/rest/actions/workflows#create-a-workflow-dispatch-event

    echo -n "Enter GitHub token: "
    # Disable echo.
    stty -echo

    read token

    # Enable echo.
    stty echo
    echo

    username=
    repo=
    workflow_id=
    ci_branch=

    curl -L \
    -X POST \
    -H "Accept: application/vnd.github+json" \
    -H "Authorization: Bearer $token" \
    -H "X-GitHub-Api-Version: 2022-11-28" \
    https://api.github.com/repos/$username/$repo/actions/workflows/$workflow_id/dispatches \
    -d '{"ref":"'"$ci_branch"'"}'