jirutka / rake-jekyll

Rake tasks for Jekyll as a gem.
MIT License
30 stars 3 forks source link

Consider checking for SOURCE_BRANCH environment variable for skip_commit #7

Closed razor-x closed 9 years ago

razor-x commented 9 years ago

Say I want my branches to benefit from Travis CI but not actually deploy the site. I could configure in .travis.yml to build all branches except gh-pages. Then I can set a Travis environment variable SOURCE_BRANCH which sets the name of the only branch that should acually get pushed to gh-pages. I realize this could be customized in skip_commit, however maybe you would consider adding it as part of the default.

Another way to do this would be to add this as an option for the task itself, say t.source_branch = ENV['SOURCE_BRANCH'] which would be empty by default. Then people could set it in the Rakefile or .travis.yml or directly via Travis's interface.

razor-x commented 9 years ago

If anyone is curious, I am using the following to achieve this:

t.skip_commit = -> {
  ENV['TRAVIS_PULL_REQUEST'].to_i > 0 ||
    %w[yes y true 1].include?(ENV['SKIP_COMMIT'].to_s.downcase) ||
    (!ENV['SOURCE_BRANCH'].nil? && ENV['SOURCE_BRANCH'] != ENV['TRAVIS_BRANCH'])
}

Feel free to make this the default or just close the issue if you don't want to implement. :smile:

jirutka commented 9 years ago

I would like to understand your use case, but I still can’t imagine any situation where this may be useful. Could you please give me some example?

razor-x commented 9 years ago

@jirutka Sure, the basic idea is that you have a repo for your site and each branch should benefit from normal CI testing, but only one branch should ever push to gh-pages.

For example, by setting SOURCE_BRANCH=production, I am free to branch without worry I will ever change the live site unless I push to production, but I still get Travis to check if my branch is building without error. Also I don't have to encode this info in the actual source code where I don't think it belongs.

jirutka commented 9 years ago

Ah, now I get it. I’m using this approach instead:

script: |
  if [[ "$TRAVIS_BRANCH" == pages-src ]]; then
      bundle exec rake deploy
  fi

However, I like your suggestion, so I’m gonna implement it.