问题
I'm going to setup some tools/techiques/environments so that when I need to provide the source code for third-party developers, I do it without git history with some sensitive code already compiled and stripped. So I want to automate this process, so that I always provide the latest version of it without the pain of doing all necessary steps by hands everytime. I use bitbucket and git.
How can my goals be accomplished using bitbucket and git? Do I need some other tools?
P.S. Feel free to edit the question if it doesn't state clear the idea. I hope this questions is not too broad and doesn't fall under restrictions
回答1:
Sounds like you want to write some post-commit
hook. But that might be too fine grained for you. Just write the automatic steps to .git/hooks/post-commit
and make that executable. You can
git --work-tree PATH_FOR_THIRD_PARTY checkout HEAD -- PUBLIC_FILES
to update the PUBLIC_FILES for your third-party developers in PATH_FOR_THIRD_PARTY, where I assume you publish the data for the third-party developers.
Then to update the compiled results you shoud write some Makefile (or similar) to produce the output in the PATH_FOR_THIRD_PARTY from your hidden files.
If you chose the right layout for your repository can just use a PUBLIC_FILES directory, to checkout all PUBLIC_FILES to PATH_FOR_THIRD_PARTY/PUBLIC_FILES
.
Note that with this method the directory layout will be the same in the publishing directory and in your repository.
BTW.: If a third-party developer changes a PUBLIC_FILE in their directory, you can simply
git --work-tree PATH_FOR_THIRD_PARTY add -u
I use this method often to publish files from a git repository. You can simply
git config -g alias.public '!git --work-tree $(git config --get public.root) '
git config public.root 'PATH_FOR_THIRD_PARTY'
so you can say
git public diff --name-only
or
git public status -s -uno
I think this method is known as or similar to a detached work-tree.
If you use this method you need to checkout the files in your local repository after you did a public commit:
git public add -u; git public commit -m "John Doe changed something"
git checkout HEAD -- .
The last line updates you local work tree to align with the commit you did above.
回答2:
The feature I think you need is git rebase with interactive option -i (git rebase -i). See details from the link: https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase
This will create new base that you can give access a third party. I'm not an expert with rebase feature. Please review the link for more details.
回答3:
If you don't want to be locked into a particular service this is what you can do:
- write a script which does what you need to provide an archive of the source code, compiled binaries and other resources (if any)
- you should be able to execute this script on your own machine, for easy testing / changes
- then write another script to create a package of these the way you want to (create a ZIP file for example) and to distribute it to an FTP server, Amazon S3 or any other service you like
- now you should have everything to automate this for you. You should be able to do this on your own machine
- if you want to automate the whole process so that it's executed every time the code is changed then with this setup you can choose pretty much any Continuous Integration/Delivery service to run it for you, triggered by a Bitbucket webhook.
If you go with this setup you can use our service (https://bitrise.io/ - I'm the CTO) as it has Bitbucket webhook support built in, even for a free account, but of course you can choose any other CI/CD service as this setup doesn't require anything more than Bitbucket hook support and the ability to run your script.
来源:https://stackoverflow.com/questions/30939511/how-to-automate-deployment-of-source-compiled-code-excluding-git-history-to