Skip to content

Instantly share code, notes, and snippets.

@upggr
Last active February 5, 2024 08:24
Show Gist options
  • Save upggr/a6d92e2808e9628ebe0d01fd93569f4a to your computer and use it in GitHub Desktop.
Save upggr/a6d92e2808e9628ebe0d01fd93569f4a to your computer and use it in GitHub Desktop.
Workflow for automated github pull on windows
On the github website there is guide detailing a worfklow for the developer that wants to have continuous integration on a linux server.
This has been detailed in many gists and goes like this in its simplest form :
1.git clone on your public_html folder (after you create ssh keys etc)
2.create a file gitpull.php with the command : exec(git pull); inside it
3.create a webhook on github to call yourwebsite.com/gitpull.php
What about windows though? you can install git bash, but the above will not work because of permissions, mostly because the user that will invoke the url will be whatever user is running the process that calls php (for example SYSTEM or IUSR)
I have a better, clever solution for that, that uses.. the windows log! Also great for troubleshooting your deployments:
1.git clone your repo in your htdocs folder (taking for example xampp on windows) or even IIS
2.create a file github_pull_win.php with contents : exec('eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO YOUR_APPLICATION_NAME /D "git webhook"',$return,$output); (Replacing your YOUR_APPLICATION_NAME with something)
3.create a file pull.bat with "git pull" in it
4.invoke the file once using "php github_pull_win.php"
5.start the task scheduler on windows
6.Add a new task that triggers "On event - Log: Application, Source:YOUR_APPLICATION_NAME,Event ID:1"
7.Set the action of this task to run the file : pull.bat using your user that holds the keys.
Done! Continuous deployment on windows
You could also modify the above to include the actual git message rather than just "git webhook"
@000000042
Copy link

2.create a file github_pull_win.php with contents : exec('eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO YOUR_APPLICATION_NAME /D "git webhook"',$return,$output); (Replacing your YOUR_APPLICATION_NAME with something) wont do anything, because of permissions. (IUSR cannot create events on Windows)

so whats the replacement for "2." what if we give perm to IUSR event on windows ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment