Skip to content

Instantly share code, notes, and snippets.

@jjh42
Created June 9, 2013 05:38
Show Gist options
  • Save jjh42/5737777 to your computer and use it in GitHub Desktop.
Save jjh42/5737777 to your computer and use it in GitHub Desktop.
Mix job for putting Elixir docs in github pages.
defmodule Mix.Tasks.Docs.Ghpages do
use Mix.Task
@moduledoc """
A task for uploading documentation to gh-pages.
"""
defp run!(command) do
if Mix.shell.cmd(command) != 0 do
raise Mix.Error, message: "command `#{command}` failed"
end
:ok
end
def run(_) do
File.rm_rf "docs"
Mix.Task.run "docs"
# First figure out the git remote to use based on the
# git remote here.
git_remote = Keyword.get(
Regex.captures(%r/\: (?<git>.*)/g,
:os.cmd 'git remote show -n origin | grep "Push URL"'), :git)
Mix.shell.info "Git remote #{git_remote}"
File.cd! "docs"
run! "git init ."
run! "git add ."
run! "git commit -a -m \"Generated docs\""
run! "git remote add origin #{git_remote}"
run! "git push origin master:gh-pages --force"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment