Skip to content

athphane/github-actions-webhook-trigger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github Actions Webhook Trigger

Quick API used to trigger GH Actions on your repos..

I needed something to trigger can action to update my Github profile when I post a new article to my blog.

Setting it up

  1. Environment Variables

    This application uses an env.ini file for it's environment variables. You can rename the env.ini.example to env.ini and fill in the values as below.

    Key Value
    key API key to make sure it's you using the application. Smash your keyboard to generate a secure token.
    github-token Your Github Access Token (Get one from here).
    owner Your Github username
    repository Your Github repo with the action you want to trigger.
  2. The Action Itself

    The workflow.yml file needs to have some specific values for this to work. In particular, the repository_dispatch key. Example below.

    name: Latest blog post workflow
    on:
      repository_dispatch:
        types: [custom-event-type]
      workflow_dispatch:
    jobs:
      your jobs here

    Remember the custom-event-type. More on it later.

  3. Starting Up FastAPI

    It's quite simple.

    uvicorn main:app --port=8000 
  4. Reverse Proxy

    In my deployment I reverse proxied the app so that I can use it with a domain.

    server {
        listen 80;
        server_name domain.com;
    
        location / {
            proxy_pass              http://127.0.0.1:8000;
            proxy_set_header        X-Real-IP  $remote_addr;
            proxy_set_header        Host $host;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header        X-Forwarded-Proto $scheme;
            proxy_redirect          off;
            proxy_buffering         off;
        }
    }
    
  5. Using It

    Once you have everything set up and the server reachable on a public domain, it's time to use it.

    https://domain.com/do?event_type=custom-event-type&secret=key

    The custom-event-type from step 2 goes into your URL params. As well as the secure token you generated by smashing your keyboard.

    The secret will 'authenticate' you to use the API and then the custom-event-type gets sent via the Github API. The on.repository_dispatch.type array on your workflow must contain your custom-event-type for it to trigger successfully.

Future plans

  • Add support for multiple repositories
  • Add support for multiple users
  • More secure authentication
  • Run as a service for everyone to use?

Credits

Releases

No releases published

Packages

No packages published

Languages