Skip to content

A program to automatically run code based on GH webhooks

License

Notifications You must be signed in to change notification settings

0xDevansh/github-deploy-inator

Repository files navigation

Project logo GitHub Deploy-inator

Automatic deployment app based on GitHub webhooks

💡 Motivation

I code and maintain a lot of Discord bots and other projects, all running on my web server. Every time I pushed an update to a bot, I'd have to SSH in, pull the code from Github, build it and restart the process. Although I managed to boil this down into a sweet yarn deploy, that still needed me to SSH into the server. I tried implementing git hooks but to no avail.

And then, this project was born.

🛠️ Installation and Setup

I have no idea. Use systemd perhaps.

Download the built version from releases and unzip it to a directory. Edit the config.json to your requirements and run the executable.

📝 config.json

All the required data must be provided in a config.json file, placed in the current working directory.

Format

  • port: The port on which the application will listen for webhooks

    • type: string
    • format: ":DDDD", where D is a digit
    • example: ":8000", ":440"

  • endpoint: The endpoint where the webhooks will be sent

    • type: string
    • format: "/*"
    • example: "/webhooks/github", "/github/listener"

  • listeners: Settings for individual listeners

    • type: Listener[]

Listener

  • name: [required] A unique name for the listener. This is mentioned when a webhook is received, executed or failed.

    • type: string
    • example: my-chat-app (try not to include spaces)

  • repository: [required] The full name of the repository for which this webhook will be executed.

    • type: string
    • format: "author-name/repository-name"
    • example: "DeathVenom54/github-deploy-inator"

  • directory: [required] The absolute path to the directory (folder) where the command will be executed.

    • type: string
    • example: "E:/projects/github-deploy-inator", "/home/dv/projects/github-deploy-inator"

  • command: [required] The command to run when the webhook is received.

    • type: string
    • example: "yarn deploy", "git pull origin main"

  • secret: The secret token set for your webhook. This makes sure that the webhook is from GitHub and is highly recommended to set.

    • type: string
    • example: j4g34O3TK2JF4jrnjrkj34nt3i4

  • branch: Execute the command only if the push was to this branch.

    • type: string
    • example: "main", "dev"

  • allowedPushers: Execute the command only if this array contains the pusher's GitHub username

    • type: string[]
    • example: ["DeathVenom54", "webnoob"]

  • notifyDiscord: If you want to receive a notification on Discord (via webhook)

    • type: boolean

  • discord: This contains information needed for sending Discord notifications

    • type: Discord

Discord

  • webhook: [required] The url of the webhook where notifications should be sent

    • type: string
    • example: "https://discord.com/api/webhooks/938275411766720533/s4nhfM-8XH1hMu9WYqSBUFaSD_erXSn6qqfdazzieCwtlINZho4teSvdlnEYgBM1E1IO"

  • notifyBeforeRun: Whether a notification should be sent before running the command

    • type: boolean

  • sendOutput: Whether the notification should contain the output sent by the command

    • type: boolean

💻 Contributing to this project

If you find any bug in this project, have a suggestion or wish to contribute to it, feel free to open an issue.