r/git•
_thinkdigital

[Question] How can I watch a remote repository for changes and trigger a build?

There's a project I'm watching and I'd like to have my mac automatically build the updates as the come in the background so that I always have the latest version. I tried searching but I didn't get the results I was looking for.

Posted Feb 21, 2020, 7:02 PM UTC

19
plg94•

To verify: it's an upstream project you have nothing to do with?

Set up a simple cron-job to git pull && build every day/hour/x min. (doubt there's even a fundamentally different solution). Ideally with some automated testing before installing, so you don't end up with a bad version.

You can also check if there's a build-script for this software in Archlinux/AUR where dou can copy some commands.

1
_thinkdigitalOP•

Correct. no connection. It's a friend's app that I'm testing on occasion. I don't feel like checking to see if there's a new version.
The problem with the cron job is that it always builds even if there's no new version. I guess it works, but it's not optimal. I know there are triggers because CI/CD pipelines can trigger on build

1
plg94•

The problem with the cron job is that it always builds even if there's no new version.

Sorry, I thought git pull had error codes, hence the &&. So run a git fetch first and check if there are changes. StackOverflow is your friend here. Same commit hash of master and origin/master would be the simplest I guess. Or check if your shell has git integration so you can read out this info (fish has by default, for bash and zsh there are plugins). Or grep the git pull output for "already up-to-date".

I know there are triggers because CI/CD pipelines can trigger on build.

Usually CI pipelines trigger on commit (git pre/post commit hooks) and are installed on the hosting server.

2
_thinkdigitalOP•

Ok, thanks for your help with this. Now I have some bullets to shoot with

1
Shred_Alert•

You're looking for Git hooks.

1
_thinkdigitalOP•

Unfortunately, git hooks run after manual commands. I need to automate these.

1
Shred_Alert•

Unfortunately, git hooks run after manual commands.

Git hooks run based on events; it doesn't matter if they were manual or automated.

I see your problem though. You've basically got two options. Either ask your friend to put a hook in their repo to send some sort of RPC or schedule checks for changes as already suggested.

1
_thinkdigitalOP•

Yes, I meant as opposed to watching for events, they get triggered.

OK, thank you

1
kreiger•

If it were me i'd probably set up a local Jenkins instance, but a simple cron job should suffice.

1