Help:Toolforge/Auto-update a tool from GitHub

From Wikitech
Jump to navigation Jump to search

Overview

You can use GitHub's webhooks feature to automatically deploy any changes made on GitHub to Toolforge. With this setup, whenever a push is made to the repository on GitHub, the changes will be fetched to the Toolforge clone of the repository, without having to manually log in to the tool's account and running git pull.

Using webhooks with Github

Introductory-level information about using webhooks with GitHub can be found here:

PHP tool hosted in $HOME/public_html

First, set up a webhook listener that runs "git pull" whenever it's accessed from GitHub:

  1. ssh USER@login.tools.wmflabs.org
  2. become MYTOOL
  3. echo "<?php if(isset($_SERVER['HTTP_X_GITHUB_EVENT'])) { `git pull`; } ?>" > public_html/git-pull.php
    • Hint You can add more commands after git pull, e.g. to run a build script.
    • Info You can find useful information regarding running shell commands from PHP here and here.

Then, set up the webhook emitter on GitHub's side:

  1. Go to https://github.com/USER/REPO/settings/hooks and click the "Add webhook" button
  2. In the "Payload URL" field, type https://tools.wmflabs.org/MYTOOL/git-pull.php
  3. Save the hook (the remaining fields can be kept with the default values)

That's it! Now whenever you push commits to the repo on GitHub, the Toolforge clone will be automatically updated.

PHP tool hosted in $HOME/www/static

First, set up a webhook listener (in the non-static $HOME/public_html directory) that runs "git pull" whenever it's accessed from GitHub:

  1. ssh USER@login.tools.wmflabs.org
  2. become MYTOOL
  3. mkdir ~/public_html
  4. echo "<?php if(isset($_SERVER['HTTP_X_GITHUB_EVENT'])) { `git -C ../www/static pull`; } ?>" > public_html/git-pull.php
  5. webservice start

Then, set up the webhook emitter on GitHub's side:

  1. Go to https://github.com/USER/REPO/settings/hooks and click the "Add webhook" button
  2. In the "Payload URL" field, type https://tools.wmflabs.org/MYTOOL/git-pull.php
  3. Save the hook (the remaining fields can be kept with the default values)

That's it! Now whenever you push commits to the repo on GitHub, the Toolforge clone will be automatically updated.

Communication and support

We communicate and provide support through several primary channels. Please reach out with questions and to join the conversation.

Communicate with us
Connect Best for
Phabricator Workboard #Cloud-Services Task tracking and bug reporting
IRC Channel #wikimedia-cloud connect General discussion and support
Mailing List cloud@ Information about ongoing initiatives, general discussion and support
Announcement emails cloud-announce@ Information about critical changes (all messages mirrored to cloud@)
News wiki page News Information about major near-term plans
Blog Clouds & Unicorns Learning more details about some of our work