Skip to content

Instantly share code, notes, and snippets.

@Maumagnaguagno
Last active February 18, 2020 00:02
Show Gist options
  • Save Maumagnaguagno/84a9807ed71d233e5d3f to your computer and use it in GitHub Desktop.
Save Maumagnaguagno/84a9807ed71d233e5d3f to your computer and use it in GitHub Desktop.
Make Travis-CI push files to other repositories for you when tests pass
language: ruby
rvm:
- 2.0.0
env:
global:
- USER="username"
- EMAIL="[email protected]"
- REPO="name of target repo"
- FILES="README.md foo.txt bar.txt"
- GH_REPO="github.com/${USER}/${REPO}.git"
- secure: "put travis gem output here => http://docs.travis-ci.com/user/encryption-keys/"
script:
- ruby test.rb
after_success:
- MESSAGE=$(git log --format=%B -n 1 $TRAVIS_COMMIT)
- git clone git://${GH_REPO}
- mv -f ${FILES} ${REPO}
- cd ${REPO}
- git remote
- git config user.email ${EMAIL}
- git config user.name ${USER}
- git add ${FILES}
- git commit -m ${MESSAGE}
- git push "https://${TRAVIS_SECURE_TOKEN_NAME}@${GH_REPO}" master > /dev/null 2>&1

Travis-CI tested push

Sometimes we have a private repository to hold both problems and solutions as a reference for the class projects. The students can see only the problems in a public repository where they are able to clone/fork and develop their own solutions. We do not want the solution files in the public repository and each bug found/feature added in the project requires a push for each repository. It would be cool to work only with the reference repo and use tests to see if our modification is good enough for the public release. This is possible with Travis-CI following simple steps:

  • Create private and public repos
  • Install Ruby
  • Install Travis gem gem install travis
  • Generate a token in the Github website to allow others to play with your repos (copy the hash)
  • Log into your git account
  • Generate a secure token with the Travis gem (copy long hash)
  • Fill the environment variables in the .travis.yml file (USER, EMAIL, REPO, FILES)
  • Replace the value of secure with your long hash
  • Replace TRAVIS_SECURE_TOKEN_NAME with your Travis token name
  • Push .travis.yml to private repo
  • Go to Travis to unlock your private repo tests
  • Push your files to the private repo to test

Travis now has a deployment feature, which may be better for certain scenarios.

@avchugaev
Copy link

Thank you. It works for me.

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