You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org

Difference between revisions of "Help:Toolforge/Auto-update a tool from GitHub"

From Wikitech
Jump to navigation Jump to search
imported>Lucas Werkmeister (WMDE)
(attempt to clarify that this only applies to PHP tools (because 1. other types need a webservice restart after deploying code, and 2. the git-pull.php needs a PHP webservice running))
imported>SRodlund
Line 1: Line 1:
 +
{{Warning|'''Note:''' Use of this deployment method has risks. If your GitHub repository is compromised by a 3rd party, your live tool could be impacted. Please think carefully before proceeding.}}
 +
 
{{Toolforge nav}}
 
{{Toolforge nav}}
 +
 +
== Overview ==
  
 
You can use GitHub's [https://help.github.com/en/articles/about-webhooks 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 <code>git pull</code>.
 
You can use GitHub's [https://help.github.com/en/articles/about-webhooks 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 <code>git pull</code>.
  
You can find helpful introductory-level information about using webhooks with GitHub [https://itnext.io/automate-deployment-with-webhooks-18735f1c7f84 here] and [https://codeburst.io/whats-a-webhook-1827b07a3ffa here].
+
== Using webhooks with Github ==
 +
 
 +
Introductory-level information about using webhooks with GitHub can be found here:
  
{{Warn|'''Note:''' Use of this deployment method has some risks. If your GitHub repository is compromised by a 3rd party, they will be able to change your live tool. Please think carefully about the implications of this to your tool and its users before proceeding.}}
+
* [https://itnext.io/automate-deployment-with-webhooks-18735f1c7f84 Automatic deployment with webhooks]
 +
* [https://codeburst.io/whats-a-webhook-1827b07a3ffa What's a webhook?]
  
 
==== PHP tool hosted in <code>$HOME/public_html</code> ====
 
==== PHP tool hosted in <code>$HOME/public_html</code> ====
Line 38: Line 45:
  
 
That's it! Now whenever you push commits to the repo on GitHub, the Toolforge clone will be automatically updated.
 
That's it! Now whenever you push commits to the repo on GitHub, the Toolforge clone will be automatically updated.
 +
 +
{{:Help:Cloud Services communication}}
  
 
[[Category:Toolforge]]
 
[[Category:Toolforge]]
 +
[[Category:Documentation]]
 +
[[Category:Cloud Services]]

Revision as of 22:09, 14 February 2020

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