dpl-pages 1.9.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c761870ed3d3d724095f4fd8173f4f92bb7a188
4
+ data.tar.gz: 5c8a3b0f3019e6fc97a97ea9222a4600a9d2a5f2
5
+ SHA512:
6
+ metadata.gz: ddf0dc3063439589750af489561202548d79f3923e14ad74569601b31e7e45447d08bc3b2c73ba9f7c7ea4dd31e6c4234385ad00a849d0c5b683dbd4cd2a0ff7
7
+ data.tar.gz: cad35745db487a095b8728c5bc8c0fdff300eeffc596f6834fb505aeff5bad374ddfa16cbb26c01f3cb27377c41ab65ff32f1a718ebe273ee70b07ace8bd7d10
@@ -0,0 +1,3 @@
1
+ require './gemspec_helper'
2
+
3
+ gemspec_for 'pages', [['octokit', '~> 4.6.2']]
@@ -0,0 +1,213 @@
1
+ require 'octokit'
2
+
3
+ module DPL
4
+ class Provider
5
+ class Pages < Provider
6
+ """Implements Github Pages deployment
7
+
8
+ Options:
9
+ - repo [optional, for pushed to other repos]
10
+ - github-token [required]
11
+ - github-url [optional, defaults to github.com]
12
+ - target-branch [optional, defaults to gh-pages]
13
+ - keep-history [optional, defaults to false]
14
+ - allow-empty-commit [optional, defaults to false]
15
+ - committer-from-gh [optional, defaults to false]
16
+ - verbose [optional, defaults to false]
17
+ - local-dir [optional, defaults to `pwd`]
18
+ - fqdn [optional]
19
+ - project-name [optional, defaults to fqdn or repo slug]
20
+ - email [optional, defaults to deploy@travis-ci.org]
21
+ - name [optional, defaults to Deployment Bot]
22
+ - deployment-file [optional, defaults to false]
23
+ """
24
+
25
+ require 'tmpdir'
26
+ experimental 'GitHub Pages'
27
+
28
+ def initialize(context, options)
29
+ super
30
+
31
+ @build_dir = File.join(src_dir, options[:local_dir] || '.')
32
+ print_step "The target dir for deployment is '#{@build_dir}'."
33
+
34
+ @project_name = options[:project_name] || fqdn || slug
35
+ @target_branch = options[:target_branch] || 'gh-pages'
36
+
37
+ @gh_fqdn = fqdn
38
+ @gh_url = options[:github_url] || 'github.com'
39
+ @keep_history = !!keep_history
40
+ @allow_empty_commit = !!allow_empty_commit
41
+ @committer_from_gh = !!committer_from_gh
42
+ @verbose = !!verbose
43
+
44
+ @gh_email = options[:email] || 'deploy@travis-ci.org'
45
+ @gh_name = "#{options[:name] || 'Deployment Bot'} (from Travis CI)"
46
+
47
+ @deployment_file = !!options[:deployment_file]
48
+
49
+ @gh_ref = "#{@gh_url}/#{slug}.git"
50
+ @git_push_opts = @keep_history ? '' : ' --force'
51
+ @git_commit_opts = (@allow_empty_commit and @keep_history) ? ' --allow-empty' : ''
52
+
53
+ print_step "The repo is configured to use committer user and email." if @committer_from_gh
54
+ end
55
+
56
+ def gh_token
57
+ @gh_token ||= option(:github_token)
58
+ end
59
+
60
+ def gh_remote_url
61
+ @gh_remote_url ||= "https://#{gh_token}@#{@gh_ref}"
62
+ end
63
+
64
+ def fqdn
65
+ options.fetch(:fqdn) { nil }
66
+ end
67
+
68
+ def slug
69
+ options.fetch(:repo) { context.env['TRAVIS_REPO_SLUG'] }
70
+ end
71
+
72
+ def src_dir
73
+ context.env['TRAVIS_BUILD_DIR'] or Dir.pwd
74
+ end
75
+
76
+ def keep_history
77
+ options.fetch(:keep_history, false)
78
+ end
79
+
80
+ def committer_from_gh
81
+ options.fetch(:committer_from_gh, false)
82
+ end
83
+
84
+ def allow_empty_commit
85
+ options.fetch(:allow_empty_commit, false)
86
+ end
87
+
88
+ def verbose
89
+ # Achtung! Never verbosify git, since it may expose user's token.
90
+ options.fetch(:verbose, false)
91
+ end
92
+
93
+ def api # Borrowed from Releases provider
94
+ error 'gh-token must be provided for Pages provider to work.' unless gh_token
95
+
96
+ return @api if @api
97
+
98
+ api_opts = { :access_token => @gh_token }
99
+ api_opts[:api_endpoint] = @gh_url == 'github.com' ? "https://api.github.com/" : "https://#{@gh_url}/api/v3/"
100
+
101
+ @api = Octokit::Client.new(api_opts)
102
+ end
103
+
104
+ def user
105
+ @user ||= api.user
106
+ end
107
+
108
+ def setup_auth
109
+ user.login
110
+ end
111
+
112
+ def check_auth
113
+ setup_auth
114
+
115
+ unless api.scopes.include? 'public_repo' or api.scopes.include? 'repo'
116
+ error "Dpl does not have permission to access #{@gh_url} using it. Make sure your token contains the repo or public_repo scope."
117
+ end
118
+
119
+ log "Logged in as @#{user.login} (#{user.name})"
120
+ rescue Octokit::Unauthorized => exc
121
+ error "gh-token is invalid. Details: #{exc}"
122
+ end
123
+
124
+ def needs_key?
125
+ false
126
+ end
127
+
128
+ def print_step(msg)
129
+ log msg if @verbose
130
+ end
131
+
132
+ def github_pull_or_init(target_dir)
133
+ unless @keep_history
134
+ github_init(target_dir)
135
+ return
136
+ end
137
+
138
+ print_step "Trying to clone a single branch #{@target_branch} from existing repo..."
139
+ unless context.shell "git clone --quiet --branch='#{@target_branch}' --depth=1 '#{@gh_remote_url}' '#{target_dir}' > /dev/null 2>&1"
140
+ # if such branch doesn't exist at remote, init it from scratch
141
+ print_step "Cloning #{@target_branch} branch failed"
142
+ Dir.mkdir(target_dir) # Restore dir destroyed by failed `git clone`
143
+ github_init(target_dir)
144
+ end
145
+ end
146
+
147
+ def github_init(target_dir)
148
+ FileUtils.cd(target_dir, :verbose => true) do
149
+ print_step "Creating a brand new local repo from scratch in dir #{Dir.pwd}..."
150
+ context.shell "git init" or raise 'Could not create new git repo'
151
+ print_step 'Repo created successfully'
152
+ context.shell "git checkout --orphan '#{@target_branch}'" or raise 'Could not create an orphan git branch'
153
+ print_step "An orphan branch #{@target_branch} created successfully"
154
+ end
155
+ end
156
+
157
+ def identify_preferred_committer
158
+ if @committer_from_gh and @gh_token
159
+ return (user.name or @gh_name), (user.email or @gh_email)
160
+ end
161
+ return @gh_name, @gh_email
162
+ end
163
+
164
+ def github_configure
165
+ committer_name, committer_email = identify_preferred_committer
166
+ print_step "Configuring git committer to be #{committer_name} <#{committer_email}> (workdir: #{Dir.pwd})"
167
+ context.shell "git config user.email '#{committer_email}'"
168
+ context.shell "git config user.name '#{committer_name}'"
169
+ end
170
+
171
+ def github_commit
172
+ committer_name, _ = identify_preferred_committer
173
+ print_step "Preparing to deploy #{@target_branch} branch to gh-pages (workdir: #{Dir.pwd})"
174
+ context.shell "touch \"deployed at `date` by #{committer_name}\"" if @deployment_file
175
+ context.shell "echo '#{@gh_fqdn}' > CNAME" if @gh_fqdn
176
+ context.shell 'git add -A .'
177
+ context.shell "git commit#{@git_commit_opts} -qm 'Deploy #{@project_name} to #{@gh_ref}:#{@target_branch}'"
178
+ context.shell 'git show --stat-count=10 HEAD'
179
+ end
180
+
181
+ def github_deploy
182
+ print_step "Doing the git push (workdir: #{Dir.pwd})..."
183
+ unless context.shell "git push#{@git_push_opts} --quiet '#{@gh_remote_url}' '#{@target_branch}':'#{@target_branch}' > /dev/null 2>&1"
184
+ error "Couldn't push the build to #{@gh_ref}:#{@target_branch}"
185
+ end
186
+ end
187
+
188
+ def push_app
189
+ print_step "Starting deployment of #{@target_branch} branch to GitHub Pages..."
190
+ print_step "The deployment is configured to preserve the target branch if it exists on remote" if @keep_history
191
+ Dir.mktmpdir do |tmpdir|
192
+ workdir = "#{tmpdir}/work"
193
+ Dir.mkdir(workdir)
194
+ print_step "Created a temporary work directory #{workdir}"
195
+
196
+ github_pull_or_init(workdir)
197
+
198
+ FileUtils.cd(workdir, :verbose => true) do
199
+ print_step "Copying #{@build_dir} contents to #{workdir} (workdir: #{Dir.pwd})..."
200
+ context.shell "rsync -r --exclude .git --delete '#{@build_dir}/' '#{workdir}'" or error "Could not copy #{@build_dir}."
201
+
202
+ github_configure
203
+ github_commit
204
+ github_deploy
205
+ context.shell "git status" if @verbose
206
+ end
207
+ end
208
+ print_step "App has been pushed"
209
+ end
210
+
211
+ end
212
+ end
213
+ end
File without changes
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dpl-pages
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dpl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.6.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.6.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json_pure
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tins
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: highline
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: deploy tool abstraction for clients
140
+ email: konstantin.mailinglists@googlemail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - dpl-pages.gemspec
146
+ - lib/dpl/provider/pages.rb
147
+ - spec/provider/pages_spec.rb
148
+ homepage: https://github.com/travis-ci/dpl
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '2.2'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.6.13
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: deploy tool
172
+ test_files:
173
+ - spec/provider/pages_spec.rb