Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly use CI scripts with Git hooks to compress source

I have a feature branch and a testing branch (for initial regression). I would like to have a working copy available for my testing branch for the testing environment. However, I need to compress some of the source code (not into binary, just optimize) via a script. I can enact this script via a post-receive Git hook.

I'm trying to design my bash script (for CI) so that it's fairly robust and want to avoid automation causing Git conflicts. I'm thinking of having a main repository (origin) and a testing environment repository (ci_test) simply to allow CI to commit.

I'm thinking about pushing to ci_test/testing when promoting source. CI should compress, add, commit, fetch from origin/testing, merge if necessary (taking theirs-full iff conflicts), then push to origin/testing.

The problem to my model above is that Git complains when I attempt to push to ci_test/testing because it has a working copy (makes sense, because they may not be synced). Is there a proper (automated) way to use Continuous Integration scripts with Git so that they're still tracked?

like image 587
BLaZuRE Avatar asked Oct 29 '22 14:10

BLaZuRE


1 Answers

The problem to my model above is that Git complains when I attempt to push to ci_test/testing because it has a working copy (makes sense, because they may not be synced).

You can either:

  • make sure your ci_test is a bare repo, with a post-receive hook which would:

    • checkout your branch testing
    • triggers all your operations
  • or, if you are the only one pushing to that ci_testing remote repo, configure the remote Git to accept pushes to a non-bare repo.
    This is possible since Git 2.3+ with:

    git config receive.denyCurrentBranch updateInstead
    

And with Git 2.4+, you can setup the remote ci_testing with a "push-to-checkout" hook, which can be installed on the server to customize exactly what happens when a user pushes to the checked-out branch.

like image 51
VonC Avatar answered Nov 09 '22 10:11

VonC