Last active
October 18, 2018 11:39
-
-
Save WojciechKo/aed07ea940608c40b4cf9a4c9b421fb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def log(msg) | |
puts "\n### #{msg}" | |
end | |
def generate_documentation | |
`bundle exec rake docs:generate` | |
end | |
def setup_git(email, name) | |
log('Setup gtit config') | |
`git config --global user.email "[email protected]"` | |
`git config --global user.name "Travis CI"` | |
end | |
def commit_documentation(commit_message) | |
log('Create commit with new documentation') | |
`mv doc/api/open_api.json open_api.json` | |
`git checkout documentation` | |
`mv open_api.json doc/api/open_api.json` | |
`git add -f doc/api/open_api.json` | |
`git commit --message "#{commit_message}"` | |
end | |
def push_new_documentation(github_repository, github_token = nil) | |
github_remote = github_token ? | |
"https://${GH_TOKEN}@github.com/#{github_repository}.git" : | |
"[email protected]:#{github_repository}.git" | |
log('Add documentation remote') | |
`git remote add origin-documentation #{github_remote}` | |
log('Pull documentation branch') | |
`git pull origin documentation --rebase` | |
log('Push new commit to documentation branch') | |
`git push --set-upstream origin documentation` | |
log('Push new documentation to documentation repository') | |
`git push -f --set-upstream origin-documentation documentation:master` | |
log('Remove documentation remote') | |
`git remote remove origin-documentation` | |
`git checkout master` | |
end | |
email = `git config --global user.email`.strip | |
name = `git config --global user.name`.strip | |
commit_message = ENV['TRAVIS_BUILD_NUMBER'] ? 'Travis build: $TRAVIS_BUILD_NUMBER' : 'Documentation update' | |
github_repository = 'elpassion/whats-my-serp-documentation' | |
github_token = ENV['GITHUB_TOKEN'] | |
generate_documentation | |
setup_git(email, name) if email.empty? || name.empty? | |
commit_documentation(commit_message) | |
push_new_documentation(github_repository, github_token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment