travis_github_deployer 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md
CHANGED
@@ -20,23 +20,25 @@ You can set up these environment variables in a secure way using the travis gem,
|
|
20
20
|
{% highlight bash %}
|
21
21
|
$ gem install travis
|
22
22
|
$ cd <name of your repository>
|
23
|
-
$ curl -u <your username> -d '{"scopes":["public_repo"],"note":"Travis CI deployer"}'
|
24
|
-
|
23
|
+
$ curl -u <your username> -d '{"scopes":["public_repo"],"note":"Travis CI deployer"}' \
|
24
|
+
https://api.github.com/authorizations
|
25
|
+
$ travis encrypt 'GIT_NAME="<your name>" GIT_EMAIL=<your email> \
|
26
|
+
GH_TOKEN=<your token>' --add
|
25
27
|
{% endhighlight %}
|
26
28
|
|
27
29
|
### How does this work?
|
28
30
|
|
29
31
|
The following command:
|
30
32
|
|
31
|
-
|
33
|
+
```bash
|
32
34
|
$ curl -u <your username> -d '{"scopes":["public_repo"],"note":"Travis CI deployer"}' https://api.github.com/authorizations
|
33
|
-
|
35
|
+
```
|
34
36
|
|
35
37
|
This will get an authentication token. With it, Travis CI can commit under your name. So be careful with it. Then with the following command:
|
36
38
|
|
37
|
-
|
39
|
+
```bash
|
38
40
|
$ travis encrypt 'GIT_NAME="<your name>" GIT_EMAIL=<your email> GH_TOKEN=<your token>' --add
|
39
|
-
|
41
|
+
```
|
40
42
|
|
41
43
|
This will take the taken and add it to a 'secure' section in your travis.yml. The Travis Github Deployer will grab it from that section and use it to push up the changes to your repository
|
42
44
|
|
@@ -46,22 +48,38 @@ The Travis Github Deployer uses one config file: ".travis_github_deployer"
|
|
46
48
|
|
47
49
|
A typical file looks like this:
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
+
```yml
|
51
52
|
destination_repository: https://github.com/basvodde/travis_github_deployer.git
|
52
53
|
|
53
54
|
files_to_deploy:
|
54
55
|
source_dir/source_file: destination_dir/destination_file
|
55
56
|
another_file: another_dir/new_name
|
56
57
|
|
57
|
-
|
58
|
+
```
|
58
59
|
|
59
60
|
This yaml file configures the repository to push to to be travis_github_deployer.git and it will copy 2 files from the build into the repository: source_dir/source_file and another_file. It will copy them to destination: destination_dir/destination_file and another_dir/new_name.
|
60
61
|
|
61
62
|
## Running Travis Github Deployer
|
62
63
|
|
64
|
+
Then... running the travis_github_deployer is all you need to do, that is, after installing the gem:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ gem install travis_github_deployer
|
68
|
+
$ travis_github_deployer
|
69
|
+
```
|
70
|
+
|
71
|
+
By default, the deployer will check whether there is a pull request or not and skip deploying on a pull request
|
63
72
|
|
73
|
+
# Contributions
|
64
74
|
|
75
|
+
At the time I write this README, the project is at a very initial stage and just written to get something of myself to work. However, I've thought about more improvements...
|
65
76
|
|
77
|
+
* Support for putting configuration inside the .travis.yml instead
|
78
|
+
* Support for passing the configuration to the script as parameter
|
79
|
+
* Support for committing in the same repository as was checked out by travis CI (no need to clone)
|
80
|
+
* Support for wildcards on files
|
81
|
+
* Some integration tests
|
82
|
+
* More
|
66
83
|
|
84
|
+
Contributions are more than welcome, please send your pull requests. Do remember, code is test-driven and no code will be accepted without tests...
|
67
85
|
|
@@ -25,6 +25,11 @@ class TravisGithubDeployer
|
|
25
25
|
## Deployment
|
26
26
|
|
27
27
|
def deploy
|
28
|
+
if (environment_variable_value('TRAVIS_PULL_REQUEST') != "false")
|
29
|
+
puts "In pull request and won't be deploying"
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
28
33
|
load_configuration
|
29
34
|
clone_destination_repository
|
30
35
|
change_current_directory_to_cloned_repository
|
@@ -77,7 +82,7 @@ class TravisGithubDeployer
|
|
77
82
|
value
|
78
83
|
end
|
79
84
|
|
80
|
-
def
|
85
|
+
def copy_files_in_destination_repository
|
81
86
|
|
82
87
|
files_to_deploy.each { |source_location, destination_location|
|
83
88
|
source = Pathname.new(source_location)
|
@@ -11,6 +11,7 @@ describe "travis github deployer" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "can deploy to an destination repository" do
|
14
|
+
ENV['TRAVIS_PULL_REQUEST']="false"
|
14
15
|
subject.should_receive(:load_configuration)
|
15
16
|
subject.should_receive(:clone_destination_repository)
|
16
17
|
subject.should_receive(:change_current_directory_to_cloned_repository)
|
@@ -20,6 +21,13 @@ describe "travis github deployer" do
|
|
20
21
|
subject.deploy
|
21
22
|
end
|
22
23
|
|
24
|
+
it "will not deploy on a pull request" do
|
25
|
+
ENV['TRAVIS_PULL_REQUEST']="10"
|
26
|
+
subject.should_not_receive(:load_configuration)
|
27
|
+
subject.should_receive(:puts).with("In pull request and won't be deploying")
|
28
|
+
subject.deploy
|
29
|
+
end
|
30
|
+
|
23
31
|
context "Prepare repository for being able to commit" do
|
24
32
|
|
25
33
|
it "can clone the destination repository" do
|
@@ -77,14 +85,14 @@ describe "travis github deployer" do
|
|
77
85
|
it "should be able to copy a file from the root of the source repository to the root of the destination reportistory" do
|
78
86
|
subject.should_receive(:files_to_deploy).and_return( { "sourcefile" => ""})
|
79
87
|
FileUtils.should_receive(:copy).with(Pathname.new("sourcefile"), Pathname.new("github_pages/sourcefile"))
|
80
|
-
subject.
|
88
|
+
subject.copy_files_in_destination_repository
|
81
89
|
end
|
82
90
|
|
83
91
|
it "Should be able to copy multiple files" do
|
84
92
|
subject.should_receive(:files_to_deploy).and_return({ "dir/onefile" => "destonefile", "twofile" => "dir/desttwofile"})
|
85
93
|
FileUtils.should_receive(:copy).with(Pathname.new("dir/onefile"), Pathname.new("github_pages/destonefile"))
|
86
94
|
FileUtils.should_receive(:copy).with(Pathname.new("twofile"), Pathname.new("github_pages/dir/desttwofile"))
|
87
|
-
subject.
|
95
|
+
subject.copy_files_in_destination_repository
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|