dpl 1.8.44.travis.2325.5 → 1.8.44.travis.2397.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/dpl/provider/pages.rb +136 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96db389ba15f857fcd34a3d50ddf2f481c1d3f89f52a3c4fce9a225ae22f3842
|
4
|
+
data.tar.gz: 3d988dcf5742808aab0d971fb55709ed9dab143a228634c51f92b4f2485fb8f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a08487a04ed053ab383786f5f7d0be67e583e48b1ad8baf8e0143641687f2ba17407fb670e911dcc191a4212deb47e8838e44614ec22e6eb56d440e9234dd36c
|
7
|
+
data.tar.gz: 3b64e60e39dfd7485bb1c0a70a235d832d5d764d3abfa3a6aec76dedb889ca869bc234708b66a5ea3a9a291441df3ddda303c7a0f61d47f4e25e182fa5050a80
|
data/README.md
CHANGED
@@ -519,11 +519,15 @@ You first need to create an [Atlas account](https://atlas.hashicorp.com/account/
|
|
519
519
|
* **github-token**: GitHub oauth token with `repo` permission.
|
520
520
|
* **repo**: Repo slug, defaults to current one.
|
521
521
|
* **target-branch**: Branch to push force to, defaults to gh-pages.
|
522
|
+
* **keep-history**: Optional, create incremental commit instead of doing push force, defaults to false.
|
523
|
+
* **allow-empty-commit**: Optional, defaults to false. Enabled if only keep-history is true.
|
524
|
+
* **committer-from-gh**: Optional, defaults to false. Allows to use token's owner name and email for commit. Overrides `email` and `name` options.
|
525
|
+
* **verbose**: Optional, be verbose about internal steps, defaults to false.
|
522
526
|
* **local-dir**: Directory to push to GitHub Pages, defaults to current.
|
523
527
|
* **fqdn**: Optional, no default, sets a main domain for your website.
|
524
528
|
* **project-name**: Defaults to fqdn or repo slug, used for metadata.
|
525
|
-
* **email**: Optional,
|
526
|
-
* **name**: Optional,
|
529
|
+
* **email**: Optional, committer info, defaults to deploy@travis-ci.org.
|
530
|
+
* **name**: Optional, committer, defaults to Deployment Bot.
|
527
531
|
|
528
532
|
#### Examples:
|
529
533
|
|
data/lib/dpl/provider/pages.rb
CHANGED
@@ -8,6 +8,10 @@ module DPL
|
|
8
8
|
- github-token [required]
|
9
9
|
- github-url [optional, defaults to github.com]
|
10
10
|
- target-branch [optional, defaults to gh-pages]
|
11
|
+
- keep-history [optional, defaults to false]
|
12
|
+
- allow-empty-commit [optional, defaults to false]
|
13
|
+
- committer-from-gh [optional, defaults to false]
|
14
|
+
- verbose [optional, defaults to false]
|
11
15
|
- local-dir [optional, defaults to `pwd`]
|
12
16
|
- fqdn [optional]
|
13
17
|
- project-name [optional, defaults to fqdn or repo slug]
|
@@ -17,23 +21,38 @@ module DPL
|
|
17
21
|
|
18
22
|
require 'tmpdir'
|
19
23
|
|
24
|
+
if RUBY_VERSION >= "2.0.0"
|
25
|
+
requires 'octokit', version: '~> 4.6.2'
|
26
|
+
else
|
27
|
+
requires 'octokit', version: '~> 4.3.0'
|
28
|
+
end
|
29
|
+
|
20
30
|
experimental 'GitHub Pages'
|
21
31
|
|
22
32
|
def initialize(context, options)
|
23
33
|
super
|
24
34
|
|
25
|
-
@build_dir = options[:local_dir] || '.'
|
35
|
+
@build_dir = File.join(Dir.pwd, options[:local_dir] || '.')
|
26
36
|
@project_name = options[:project_name] || fqdn || slug
|
27
37
|
@target_branch = options[:target_branch] || 'gh-pages'
|
28
38
|
|
29
39
|
@gh_fqdn = fqdn
|
30
40
|
@gh_url = options[:github_url] || 'github.com'
|
31
41
|
@gh_token = option(:github_token)
|
42
|
+
@keep_history = !!keep_history
|
43
|
+
@allow_empty_commit = !!allow_empty_commit
|
44
|
+
@committer_from_gh = !!committer_from_gh
|
45
|
+
@verbose = !!verbose
|
32
46
|
|
33
47
|
@gh_email = options[:email] || 'deploy@travis-ci.org'
|
34
48
|
@gh_name = "#{options[:name] || 'Deployment Bot'} (from Travis CI)"
|
35
49
|
|
36
50
|
@gh_ref = "#{@gh_url}/#{slug}.git"
|
51
|
+
@gh_remote_url = "https://#{@gh_token}@#{@gh_ref}"
|
52
|
+
@git_push_opts = @keep_history ? '' : ' --force'
|
53
|
+
@git_commit_opts = (@allow_empty_commit and @keep_history) ? ' --allow-empty' : ''
|
54
|
+
|
55
|
+
print_step "The repo is configured to use committer user and email." if @committer_from_gh
|
37
56
|
end
|
38
57
|
|
39
58
|
def fqdn
|
@@ -44,34 +63,134 @@ module DPL
|
|
44
63
|
options.fetch(:repo) { context.env['TRAVIS_REPO_SLUG'] }
|
45
64
|
end
|
46
65
|
|
66
|
+
def keep_history
|
67
|
+
options.fetch(:keep_history, false)
|
68
|
+
end
|
69
|
+
|
70
|
+
def committer_from_gh
|
71
|
+
options.fetch(:committer_from_gh, false)
|
72
|
+
end
|
73
|
+
|
74
|
+
def allow_empty_commit
|
75
|
+
options.fetch(:allow_empty_commit, false)
|
76
|
+
end
|
77
|
+
|
78
|
+
def verbose
|
79
|
+
# Achtung! Never verbosify git, since it may expose user's token.
|
80
|
+
options.fetch(:verbose, false)
|
81
|
+
end
|
82
|
+
|
83
|
+
def api # Borrowed from Releases provider
|
84
|
+
error 'gh-token must be provided for Pages provider to work.' unless @gh_token
|
85
|
+
|
86
|
+
@api ||= Octokit::Client.new(:access_token => @gh_token)
|
87
|
+
end
|
88
|
+
|
89
|
+
def user
|
90
|
+
@user ||= api.user
|
91
|
+
end
|
92
|
+
|
93
|
+
def setup_auth
|
94
|
+
user.login
|
95
|
+
end
|
96
|
+
|
47
97
|
def check_auth
|
98
|
+
setup_auth
|
99
|
+
|
100
|
+
unless api.scopes.include? 'public_repo' or api.scopes.include? 'repo'
|
101
|
+
error "Dpl does not have permission to access #{@gh_url} using it. Make sure your token contains the repo or public_repo scope."
|
102
|
+
end
|
103
|
+
|
104
|
+
log "Logged in as @#{user.login} (#{user.name})"
|
105
|
+
rescue Octokit::Unauthorized => exc
|
106
|
+
error "gh-token is invalid. Details: #{exc}"
|
48
107
|
end
|
49
108
|
|
50
109
|
def needs_key?
|
51
110
|
false
|
52
111
|
end
|
53
112
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
113
|
+
def print_step(msg)
|
114
|
+
log msg if @verbose
|
115
|
+
end
|
116
|
+
|
117
|
+
def github_pull_or_init(target_dir)
|
118
|
+
unless @keep_history
|
119
|
+
github_init(target_dir)
|
120
|
+
return
|
121
|
+
end
|
122
|
+
|
123
|
+
print_step "Trying to clone a single branch #{@target_branch} from existing repo..."
|
124
|
+
unless context.shell "git clone --quiet --branch='#{@target_branch}' --depth=1 '#{@gh_remote_url}' '#{target_dir}' > /dev/null 2>&1"
|
125
|
+
# if such branch doesn't exist at remote, init it from scratch
|
126
|
+
print_step "Cloning #{@target_branch} branch failed"
|
127
|
+
Dir.mkdir(target_dir) # Restore dir destroyed by failed `git clone`
|
128
|
+
github_init(target_dir)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def github_init(target_dir)
|
133
|
+
FileUtils.cd(target_dir, :verbose => true) do
|
134
|
+
print_step "Creating a brand new local repo from scratch in dir #{Dir.pwd}..."
|
135
|
+
context.shell "git init" or raise 'Could not create new git repo'
|
136
|
+
print_step 'Repo created successfully'
|
137
|
+
context.shell "git checkout --orphan '#{@target_branch}'" or raise 'Could not create an orphan git branch'
|
138
|
+
print_step "An orphan branch #{@target_branch} created successfully"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def identify_preferred_committer
|
143
|
+
if @committer_from_gh and @gh_token
|
144
|
+
return (user.name or @gh_name), (user.email or @gh_email)
|
145
|
+
end
|
146
|
+
return @gh_name, @gh_email
|
147
|
+
end
|
148
|
+
|
149
|
+
def github_configure
|
150
|
+
committer_name, committer_email = identify_preferred_committer
|
151
|
+
print_step "Configuring git committer to be #{committer_name} <#{committer_email}> (workdir: #{Dir.pwd})"
|
152
|
+
context.shell "git config user.email '#{committer_email}'"
|
153
|
+
context.shell "git config user.name '#{committer_name}'"
|
154
|
+
end
|
155
|
+
|
156
|
+
def github_commit
|
157
|
+
committer_name, _ = identify_preferred_committer
|
158
|
+
print_step "Preparing to deploy #{@target_branch} branch to gh-pages (workdir: #{Dir.pwd})"
|
159
|
+
context.shell "touch \"deployed at `date` by #{committer_name}\""
|
60
160
|
context.shell "echo '#{@gh_fqdn}' > CNAME" if @gh_fqdn
|
61
|
-
context.shell 'git add .'
|
62
|
-
context.shell "
|
63
|
-
context.shell
|
161
|
+
context.shell 'git add -A .'
|
162
|
+
context.shell "git commit#{@git_commit_opts} -qm 'Deploy #{@project_name} to #{@gh_ref}:#{@target_branch}'"
|
163
|
+
context.shell 'git show --stat-count=10 HEAD'
|
164
|
+
end
|
165
|
+
|
166
|
+
def github_deploy
|
167
|
+
print_step "Doing the git push (workdir: #{Dir.pwd})..."
|
168
|
+
unless context.shell "git push#{@git_push_opts} --quiet '#{@gh_remote_url}' '#{@target_branch}':'#{@target_branch}' > /dev/null 2>&1"
|
169
|
+
error "Couldn't push the build to #{@gh_ref}:#{@target_branch}"
|
170
|
+
end
|
64
171
|
end
|
65
172
|
|
66
173
|
def push_app
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
174
|
+
print_step "Starting deployment of #{@target_branch} branch to GitHub Pages..."
|
175
|
+
print_step "The deployment is configured to preserve the target branch if it exists on remote" if @keep_history
|
176
|
+
Dir.mktmpdir do |tmpdir|
|
177
|
+
workdir = "#{tmpdir}/work"
|
178
|
+
Dir.mkdir(workdir)
|
179
|
+
print_step "Created a temporary work directory #{workdir}"
|
180
|
+
|
181
|
+
github_pull_or_init(workdir)
|
182
|
+
|
183
|
+
FileUtils.cd(workdir, :verbose => true) do
|
184
|
+
print_step "Copying #{@build_dir} contents to #{workdir} (workdir: #{Dir.pwd})..."
|
185
|
+
context.shell "rsync -r --exclude .git --delete '#{@build_dir}/' '#{workdir}'" or error "Could not copy #{@build_dir}."
|
186
|
+
|
187
|
+
github_configure
|
188
|
+
github_commit
|
189
|
+
github_deploy
|
190
|
+
context.shell "git status" if @verbose
|
73
191
|
end
|
74
|
-
|
192
|
+
end
|
193
|
+
print_step "App has been pushed"
|
75
194
|
end
|
76
195
|
|
77
196
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.44.travis.
|
4
|
+
version: 1.8.44.travis.2397.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: 1.3.1
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.7.
|
233
|
+
rubygems_version: 2.7.4
|
234
234
|
signing_key:
|
235
235
|
specification_version: 4
|
236
236
|
summary: deploy tool
|