Skip to content

markpendlebury/github-remote-workflow-trigger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

GitHub Workflow Trigger

This repository contains an exampleog how to trigger a github workflow using the PyGithub library. It also contains an example github workflow which echos out an inputted string.

What the Code Does

.github/workflows/workflow.yml will create a basic workflow which is triggered on a workflow dispatch and accepts one input named my_input

workflow_trigger.py does the following:

  1. Retrieves environment variables for the GitHub token, my input, repository name, workflow filename, and branch name.
  2. Defines a function trigger_workflow that:
    • Creates an instance of GitHub and logs in using the provided token.
    • Retrieves the repository object.
    • Retrieves the workflow object from the repository.
    • Triggers the workflow on the specified branch, passing a string as an input.
  3. Calls the trigger_workflow function.

How to Use

  1. Clone/Fork this repository and make sure it creates a new workflow named "Example Workflow".
  2. Generate a PAT token with at least read/write scope for Actions.
  3. Set the following environment variables on your local machine:
    • GITHUB_TOKEN: Your GitHub PAT token from step 2.
    • MY_INPUT: A simple string, for example "Hello World".
    • REPOSITORY: The name of your repository in the format owner/repo.
    • WORKFLOW_FILENAME: The filename of your workflow file in the .github/workflows directory.
    • BRANCH: The name of the branch you want to run the workflow on.
  4. Run the script locally with the command python workflow_trigger.py.

Profit

About

Demonstrating how to trigger a github workflow remoteley in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%