Hello,
I mirrored a github repo to my gitea server, in the hooks I put a script in the post-update script file that should build the repo and deploy it (to a web server), however it seems the script did not run on a push on the github repo while the local server did get the update.
How can I make sure a script is ran on a github repo commit without periodically reading the github repo?
I thought about webhooks, but as I understand this is for making a http request so I would need to run a separate web server for this locally.
maybe its not in the right hook file, is there one that will update on a mirror repo commit?
or is there a way to use a github hook/script?
Thanks in advance.
Hi,
What you’re experiencing is actually a common scenario when mirroring a repo to Gitea. The key thing to understand is that hooks in a mirrored repository behave differently than in a regular repo. Let me break it down:
1. Why your post-update script didn’t run
-
When Gitea mirrors a repo from GitHub, the updates are pulled automatically on the Gitea server.
-
The server-side hooks in the mirrored repo (like post-update) are not triggered by the mirror pull — they only trigger on local pushes to that repo.
-
So even though the repo on your Gitea server is updated, your script didn’t run because Gitea’s mirror pull does not invoke hooks.
2. How to trigger actions on GitHub pushes without polling
You’re correct that webhooks are the usual way to trigger scripts on a remote push. Some options:
Option A: Use GitHub Webhooks
-
On GitHub, set up a webhook pointing to your server.
-
You do need some HTTP endpoint to receive the webhook — yes, typically this means running a small web server or a lightweight listener (could be a simple Flask/PHP/Node server listening for POST requests).
-
When the webhook hits, you can trigger your build/deploy script.
Option B: Use Gitea’s Webhooks
-
Even after mirroring, Gitea allows webhooks on mirrored repos.
-
You can configure a “Push” webhook to call your deployment script via HTTP. Again, you’ll need a small local HTTP listener to handle it.
Option C: Polling (less ideal)
- Running a cron job to
git fetch and trigger your script is another method, but it’s less efficient and you already mentioned wanting to avoid it.
3. Alternative: Custom Mirror Post-Receive Hook
- Some users set up a wrapper script on the mirror repo that runs after the
git fetch by Gitea, but this requires modifying Gitea’s mirror update process, which is more complex and not officially supported.
Recommended Approach
-
Set up a small local HTTP listener (even a simple Flask/Node server works).
-
Configure a GitHub webhook pointing to that listener.
-
In the listener, call your build/deploy script whenever a push is received.
This is the most reliable and real-time method without constantly polling.
Alright, I will take a look at the webhooks, thank you for the answer!