Skip to content

Commit

Permalink
Created mix publish task.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjh42 committed Jun 17, 2013
1 parent 2c7c8ab commit 56f26d9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
62 changes: 62 additions & 0 deletions lib/publish_task.ex
@@ -0,0 +1,62 @@
defmodule Mix.Tasks.Publish do
use Mix.Task

@shortdoc """
Publish your project on expm.
"""

@moduledoc """
Publish your project on expm.
## Options
`--repository url`
By default, this is [https://expm.co/](https://expm.co/)
`--username USER` and `--password PASSWORD`
If not available, uses config file.
"""

# Get the repo - finding authentication from config file
# if not available elsewhere.
defp get_repo(opts) do
url = opts[:repository] || "https://expm.co"
Expm.Repository.HTTP.new(url: url,
username: opts[:username], password: opts[:password])
end

# Update options based on the configuration file
defp read_config(opts) do
config_opts = [:username, :password]
update_config(opts, config_opts)
end

defp update_config(opts, []), do: opts
defp update_config(opts, [key|t]) do
if opts[key] == nil do
opts = Keyword.put opts, key, Expm.UserConfig.get key
end
update_config(opts, t)
end

def run(args) do
{ opts, [] } = OptionParser.parse(args)
opts = read_config(opts)
Application.Behaviour.start :expm
publish get_repo(opts)
end

def publish(repo) do
proj = Mix.project
package = Expm.Package.new(name: atom_to_binary(proj[:app]),
version: proj[:version],
description: proj[:description],
keywords: proj[:keywords],
maintainers: proj[:maintainers],
repositories: proj[:repositories]
)
Expm.Package.publish repo, package
end
end
6 changes: 6 additions & 0 deletions test/repository_auth_test.exs
Expand Up @@ -16,6 +16,12 @@ defmodule Expm.Test.Repository.Auth do
assert package.metadata[:published_by] == "user"
end

test "uploading a new package with mix", data do
auth = Expm.Repository.Auth.new(repository: data[:repo], username: "user", auth_token: "password")
package = Mix.Tasks.Publish.publish(auth)
assert package.metadata[:published_by] == "user"
end

test "uploading a package with the same version", data do
package = Expm.Package.new(name: "test", version: "0.1")
auth = Expm.Repository.Auth.new(repository: data[:repo], username: "user", auth_token: "password")
Expand Down

0 comments on commit 56f26d9

Please sign in to comment.