middleman-deploy icon indicating copy to clipboard operation
middleman-deploy copied to clipboard

Git Force-Push Deploy Pushes Root Instead of Build Dir

Open JustinHardage opened this issue 9 years ago • 18 comments

I'm trying to push my middleman build directory to a GitHub Organization Page. This means that my GitHub repo master branch needs to get the output of a bundle exec middleman build command.

However, I haven't found any combination of options with deploy.method = :git that actually does this. I always get the root of the project - e.g. where the Gemfile lives - instead of something that GitHub Pages would recognize as a site with an index.html file.

How can I deploy to a GitHub Pages site?

#config.rb
activate :deploy do |deploy|
  deploy.method = :git
  deploy.remote   = 'https://github.com/FiercePunchStudios/deploy-test.git'
  deploy.branch   = 'master'
end
#Gemfile
source 'http://rubygems.org'
gem "middleman", "~> 3.4.0"
gem 'middleman-deploy', '~> 1.0'

JustinHardage avatar Dec 21 '15 19:12 JustinHardage

Same happening here.

# Gemfile

source "http://rubygems.org"
gem "middleman", '3.4.1'
gem "middleman-autoprefixer"
gem "middleman-deploy"
# config.rb

configure :build do
  # Relative assets needed to deploy to Github Pages
  activate :relative_assets
end

activate :deploy do |deploy|
  deploy.build_before = true
  deploy.method = :git
end

$ ruby -v -> ruby 2.2.3p173

juanpabloe avatar Dec 23 '15 01:12 juanpabloe

I came here to report this very issue. I've been using middleman-deploy for years without issue, yet this recently started pushing up the entire project rather than just the build folder.

hello-jason avatar Dec 25 '15 16:12 hello-jason

same problem here. it does push all project, not build folder. (2.0.0 alpha)

hovancik avatar Dec 26 '15 14:12 hovancik

In case you need temporary quick fix, middleman deploy works if there are no files on the master branch. I work from development branch so this is what works for me:

git checkout master && sudo rm -r Gemfile.lock build && git checkout development && middleman deploy

YMMV though

mehowte avatar Dec 26 '15 16:12 mehowte

Hmm, this appears to be a git issue. I tried locking all old versions of middleman and it's nothing there.

toobulkeh avatar Dec 27 '15 02:12 toobulkeh

Guys, I forked jekyll-github-deploy into https://github.com/hovancik/middleman-github-deploy, you might wanna check it out. For now it solved problem with middleman-deploy. It's a bit different approach, but you can easy deploy your site to GithubPages with it. Works for me.

hovancik avatar Dec 27 '15 11:12 hovancik

I fixed this issue, by removing build directory before each deploy. For this purposes I use small extension

#lib/build_cleaner.rb

class BuildCleaner < Middleman::Extension

  def initialize(app, options_hash={}, &block)
    super
    FileUtils.rm_rf app.config[:build_dir]
  end

end

::Middleman::Extensions.register(:build_cleaner, BuildCleaner)
#config.rb

require_relative "./lib/build_cleaner"

configure :build do
  activate :build_cleaner
end

robinbortlik avatar Dec 31 '15 07:12 robinbortlik

@robinbortlik I've found that your solution of deleting the build directory also is working for me. Where did you put this require in your config? I'm not sure when or why this started happening as everything was working fine for me about a week ago and I haven't changed anything that I know of since then.

christopherjanzen avatar Jan 01 '16 17:01 christopherjanzen

@robinbortlik 's fix worked for me. Any chance we can get this behavior as a default in middleman-deploy?

JustinHardage avatar Jan 04 '16 03:01 JustinHardage

@christopherjanzen @JustinHardage I'm glad that it helped. I put my require at the top of config.rb file. I also have no explanation why it stopped working. But I don't think, it should be included in the middleman deploy. This is more a hotfix. The reason why middleman don't delete whole build folder is to speedup build process. I guess. :)

robinbortlik avatar Jan 04 '16 08:01 robinbortlik

Also stumbled into this, thought I was going mad initially, so thanks for posting! The fix/tweak above resolves for me under mint/2.2.2 and git 1.9.1. HTH.

colindensem avatar Jan 12 '16 23:01 colindensem

Deleting build directory before each deploy made this work for me. Not sure what needs to be done to get this fixed.

ryankbales avatar Jan 17 '16 05:01 ryankbales

I've done some tests and that's my experience. I hope it could help.

In root project git remote -v gives

origin [email protected]:source/of/my/project.git gh-pages [email protected]:username/username.github.io.git

After the first middleman build (or first deploy with build-before enabled), the build directory became a git repo itself and git remote -v gives

origin [email protected]:username/username.github.io.git

That's ok. But calling again middleman build you can see in the output

identical build/stylesheets/site.css identical build/images/middleman-logo.svg identical build/javascripts/all.js identical build/index.html remove build/.gitignore remove build/.git/objects/69/57aee4a38c4390d330570ae8a4989907911b56 remove build/.git/objects/2b/ecd765c79234b8662c575fac6c259ba87d033c remove build/.git/objects/ff/d595503b2671ec3550df0b075ef60d7f535579 remove build/.git/objects/a5/e8ac2a41bdbef16c39fef16c69e4562db9c171 remove build/.git/objects/fa/2811b4915660d72191193c7bf5ef85750bbc4e remove build/.git/objects/20/f36b5326a73789af2ff0e4464a8e80518018c3 remove build/.git/objects/98/ef9fc3abdedb871beba12bf1097e38a4a4cd48 remove build/.git/objects/7d/fde9e9fb6c498760f9c026f77bdaf778aea0a6 remove build/.git/objects/91/33babd8b3722a65e50a5514313aa65ec596019 remove build/.git/logs/refs/heads/master remove build/.git/logs/HEAD remove build/.git/hooks/post-update.sample remove build/.git/hooks/pre-rebase.sample remove build/.git/hooks/pre-push.sample remove build/.git/hooks/update.sample remove build/.git/hooks/pre-applypatch.sample remove build/.git/hooks/commit-msg.sample remove build/.git/hooks/applypatch-msg.sample remove build/.git/hooks/prepare-commit-msg.sample remove build/.git/hooks/pre-commit.sample remove build/.git/index remove build/.git/info/exclude remove build/.git/config remove build/.git/refs/heads/master remove build/.git/description remove build/.git/COMMIT_EDITMSG remove build/.git/HEAD Project built successfully.

Build remove all git files, but not the .git directory. This inconsistency leads Middleman::Deploy::Strategies::Git::ForcePush::add_remote_url to produce side effects:

def add_remote_url url = get_remote_url

unless File.exist?('.git') git init git remote add origin #{url} git config user.name "#{user_name}" git config user.email "#{user_email}" else # check if the remote repo has changed unless url == git config --get remote.origin.url.chop git remote rm origin git remote add origin #{url} # <-- Here the root project origin is overwritten!! end

So .git data of build directory will be removed, origin of root project will be overwritten, and the root project will be pushed instead of builded one. Infact now in root project git remote -v gives

origin [email protected]:username/username.github.io.git gh-pages [email protected]:username/username.github.io.git

That's why removing each time the build directory seems to workaround.

In my opinion the build process should preserve the .git directory. Or the method above should do a more complex check process to see if remotes are ok..

MinasMazar avatar Jan 21 '16 16:01 MinasMazar

However this implementation of Middleman::Deploy::Strategies::Git::ForcePush::add_remote_url will regenerate .git data every time. Maybe it's a better solution than cleaning the entire build directory.

def add_remote_url
  url = get_remote_url

  `git init`
  `git remote add origin #{url}`
  `git config user.name "#{user_name}"`
  `git config user.email "#{user_email}"`
end

MinasMazar avatar Jan 22 '16 12:01 MinasMazar

The issue isn't with middleman-deploy or git so much as it is with middleman v4 which changed the build process. v4.1.0.rc.2 includes a config directive to change this behavior and resolve the above problem. See https://github.com/middleman/middleman/issues/1716 for the full details.

I don't use middleman-deploy and still had this issue, for what it's worth (I've been using https://github.com/edgecase/middleman-gh-pages successfully for a long while).

configure :deploy do
  set :skip_build_clean do |path|
    path =~ /\.git/
  end
end

coreyward avatar Jan 27 '16 22:01 coreyward

Experiencing the same behavior with my Middleman 4 project.

Yanchek99 avatar Jan 28 '16 16:01 Yanchek99

I used @egardner patch and it worked! Thanks!

jodosha avatar Jan 29 '16 10:01 jodosha

@coreyward 's information solved my Middeman v4.1 project's issue. Thank you!

KitaitiMakoto avatar Feb 09 '16 15:02 KitaitiMakoto