Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pages target dir #1170

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/dpl/providers/pages/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Git < Pages
opt '--allow_empty_commit', 'Allow an empty commit to be created', requires: :keep_history
opt '--verbose', 'Be verbose about the deploy process'
opt '--local_dir DIR', 'Directory to push to GitHub Pages', default: '.'
opt '--target_dir DIR', 'Target directory within repository', default: '.'
opt '--fqdn FQDN', 'Write the given domain name to the CNAME file'
opt '--project_name NAME', 'Used in the commit message only (defaults to fqdn or the current repo slug)'
opt '--name NAME', 'Committer name', note: 'defaults to the current git commit author name'
Expand All @@ -46,10 +47,11 @@ class Git < Pages
work_dir: 'Using temporary work directory %{work_dir}',
committer_from_gh: 'The repo is configured to use committer user and email.',
setup_dir: 'The source dir for deployment is %s',
target_dir: 'The target dir for deployment is %s',
git_clone: 'Cloning the branch %{target_branch} from the remote repo',
git_init: 'Initializing local git repo',
git_checkout: 'Checking out orphan branch %{target_branch}',
copy_files: 'Copying %{src_dir} contents to %{work_dir}',
copy_files: 'Copying %{src_dir} contents to %{dst_dir}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this can just be target_dir, in which case we wouldn't need the extra method dst_dir below.

git_config: 'Configuring git committer to be %{name} <%{email}>',
prepare: 'Preparing to deploy %{target_branch} branch to gh-pages',
git_push: 'Pushing to %{url}',
Expand All @@ -59,7 +61,7 @@ class Git < Pages
git_init: 'git init .',
git_checkout: 'git checkout --orphan "%{target_branch}"',
check_deploy_key: 'ssh -i %{key} -T git@github.com 2>&1 | grep successful > /dev/null',
copy_files: 'rsync -rl --exclude .git --delete "%{src_dir}/" .',
copy_files: 'rsync -rl --exclude .git --delete "%{src_dir}/" "%{dst_dir}"',
git_config_email: 'git config user.email %{quoted_email}',
git_config_name: 'git config user.name %{quoted_name}',
deployment_file: 'touch "deployed at %{now} by %{name}"',
Expand All @@ -82,6 +84,7 @@ def login

def setup
info :setup_dir, src_dir
info :target_dir, dst_dir
info :committer_from_gh if committer_from_gh?
info :git_config
end
Expand Down Expand Up @@ -231,6 +234,10 @@ def src_dir
@src_dir ||= expand(local_dir)
end

def dst_dir
@dst_dir ||= target_dir
end

def work_dir
@work_dir ||= tmp_dir
end
Expand Down
16 changes: 11 additions & 5 deletions spec/dpl/providers/pages/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
it { should have_run '[info] Deploying branch gh-pages to github.com/travis-ci/dpl.git' }
it { should have_run '[info] Cloning the branch gh-pages from the remote repo' }
it { should have_run 'git clone --quiet --branch="gh-pages" --depth=1 "https://token@github.com/travis-ci/dpl.git" . > /dev/null 2>&1' }
it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" .) }
it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" ".") }
it { should have_run 'git config user.name "author name (via Travis CI)"' }
it { should have_run 'git config user.email "author email"' }
it { should have_run 'git add -A .' }
Expand All @@ -36,7 +36,7 @@
it { should have_run '[info] Deploying branch gh-pages to github.com/travis-ci/dpl.git' }
it { should have_run '[info] Using temporary work directory tmp' }
it { should have_run "[info] Cloning the branch gh-pages from the remote repo" }
it { should have_run "[info] Copying #{cwd} contents to tmp" }
it { should have_run "[info] Copying #{cwd} contents to ." }
it { should have_run '[info] Configuring git committer to be author name (via Travis CI) <author email>' }
it { should have_run '[info] Preparing to deploy gh-pages branch to gh-pages' }
it { should have_run '[info] Pushing to github.com/travis-ci/dpl.git' }
Expand All @@ -57,7 +57,7 @@
it { should have_run '[info] Initializing local git repo' }
it { should have_run 'git init .' }
it { should have_run 'git checkout --orphan "gh-pages"' }
it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" .) }
it { should have_run %(rsync -rl --exclude .git --delete "#{cwd}/" ".") }
it { should have_run 'git add -A .' }
it { should have_run 'git commit -q -m "Deploy travis-ci/dpl to github.com/travis-ci/dpl.git:gh-pages"' }
it { should have_run 'git show --stat-count=10 HEAD' }
Expand All @@ -74,9 +74,15 @@
end

describe 'given --local_dir ./dir --verbose' do
it { should have_run "rsync -rl --exclude .git --delete \"#{cwd}/dir/\" ." }
it { should have_run "rsync -rl --exclude .git --delete \"#{cwd}/dir/\" \".\"" }
it { should have_run "[info] The source dir for deployment is #{cwd}/dir" }
it { should have_run "[info] Copying #{cwd}/dir contents to tmp" }
it { should have_run "[info] Copying #{cwd}/dir contents to ." }
end

describe 'given --target_dir ./dir --verbose' do
it { should have_run "rsync -rl --exclude .git --delete \"#{cwd}/\" \"./dir\"" }
it { should have_run "[info] The target dir for deployment is ./dir" }
it { should have_run "[info] Copying #{cwd} contents to ./dir" }
end

describe 'given --fqdn fqdn.com' do
Expand Down