Giter Club home page Giter Club logo

git-directory-deploy's Introduction

This is a script for deploying generated files to a git branch, such as when building a single-page app using Yeoman and deploying to GitHub Pages. Unlike the git-subtree approach, it does not require the generated files be committed to the source branch. It keeps a linear history on the deploy branch and does not make superfluous commits or deploys when the generated files do not change.

Circle CI

For an example of use, see X1011/verge-mobile-bingo. For development info, see contributing.md.

configuration

Download the script (wget https://github.com/X1011/git-directory-deploy/raw/master/deploy.sh && chmod +x deploy.sh) and edit these variables within it as needed to fit your project:

  • deploy_directory: root of the tree of files to deploy
  • deploy_branch: branch to commit files to and push to origin
  • default_username, default_email: identity to use for git commits if none is set already. Useful for CI servers.
  • repo: repository to deploy to. Must be readable and writable. The default of "origin" will not work on Travis CI, since it uses the read-only git protocol. In that case, it is recommended to store a GitHub token in a secure environment variable and use it in an HTTPS URL like this: repo=https://$[email protected]/user/repo.git Warning: there is currently an issue where the repo URL may be output if an operation fails.

You can also define any of variables using environment variables and configuration files:

  • GIT_DEPLOY_DIR
  • GIT_DEPLOY_BRANCH
  • GIT_DEPLOY_REPO

The script will set these variables in this order of preference:

  1. Defaults set in the script itself.
  2. Environment variables.
  3. .env file in the path where you're running the script.
  4. File specified on the command-line (see the -c option below).

Whatever values set later in this list will override those set earlier.

run

Do this every time you want to deploy, or have your CI server do it.

  1. check out the branch or commit of the source you want to use. The script will use this commit to generate a message when it makes its own commit on the deploy branch.
  2. generate the files in deploy_directory
  3. make sure you have no uncommitted changes in git's index. The script will abort if you do. (It's ok to have uncommitted files in the work tree; the script does not touch the work tree.)
  4. if deploy_directory is a relative path (the default is), make sure you are in the directory you want to resolve against. (For the default, this means you should be in the project's root.)
  5. run ./deploy.sh

options

-h, --help: show the program's help info.

-c, --config-file: specify a file that overrides the script's default configuration, or those values set in .env. The syntax for this file should be normal var=value declarations. This option must come first on the command-line.

-m, --message <message>: specify message to be used for the commit on deploy_branch. By default, the message is the title of the source commit, prepended with 'publish: '.

-n, --no-hash: don't append the hash of the source commit to the commit message on deploy_branch. By default, the hash will be appended in a new paragraph, regardless of whether a message was specified with -m.

-v, --verbose: echo expanded commands as they are executed, using the xtrace option. This can be useful for debugging, as the output will include the values of variables that are being used, such as $commit_title and $deploy_directory. However, the script makes special effort to not output the value of $repo, as it may contain a secret authentication token.

-e, --allow-empty: allow deployment of an empty directory. By default, the script will abort if deploy_directory is empty.

git-directory-deploy's People

Contributors

chippers avatar connyay avatar moox avatar txchen avatar x1011 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-directory-deploy's Issues

"Deploy directory 'dist' is empty" but it isn't

I just grabbed the latest version of your script and I got this issue.
It guess the script need to be at the same level of dist?

~/Sync/Development/statinamic/demo master* ⇡./scripts/deploy.sh 
Deploy directory 'dist' is empty. Aborting. If you're sure you want to deploy an empty tree, use the --allow-empty / -e flag.

~/Sync/Development/statinamic/demo master* ⇡
❯❯ ls dist 
collection.json       docs                  index.html            index.json            statinamic-client.css statinamic-client.js

configuration with command-line arguments

I'm thinking about changing how the configuration is specified. Rather than having users modify the script or set environment variables, the script would take additional command-line arguments. I would do this for deploy_directory, deploy_branch, and repo. I would eliminate default_username and default_email and just require the user to have git sufficiently configured beforehand.

I'm considering a syntax like this: deploy.sh [<options>] [<directory> [<branch> [<repository>​]]]

pros:

  • the script doesn't need to be modified, so it can be shared across projects, installed as a package, and write protected
  • no polluting of environment variables, no chance of name collisions
  • makes apparent that a relative deploy_directory is relative to the current working directory, eliminating the need to mention this in the readme

cons:

  • complicates ad-hoc deployments not using the defaults, as you would now have to either remember to include the arguments every time or create a wrapper script
  • having 3 positional arguments, it may be hard to remember which is which
  • will probably complicate argument parsing

questions:

  • which arguments should be positional or named? (e.g., should we do something like this instead?: deploy.sh [-d <directory>] ...)
  • which arguments should still have defaults or be required?

Let me know if you think this is a good or bad idea.

Provide `-m` option to change the commit message

In some situations last commit message does not describe the purpose of a commit properly.
In these situations it would be nice if you provide -m option to change the commit message.

Anyway, thanks for sharing your amazing script. It really makes my life easier!

Consider adding your license in the script

Nice script!

You have a BSD-3 license which requires copying the license together with the script to the location it is used. But as per your own usage instructions, people are encouraged to only get the script and forget about the license. You could consider adding a --license option that prints the entire text, giving attribution to you and having the copyright notice. Note that you should add a URL to the repo as the location of the original work.

add tests

write (unit) tests using something like roundup, Bats, assert.sh, or shelltestrunner.

write tests for

  • attempting to deploy without setting up first
    • non-existent deploy_directory (#5)
    • empty deploy_directory (#5)
    • non-existent remote deploy_branch (#5)
    • non-existent local deploy_branch
  • non-writable remote repo
  • setup should not delete existing files in deploy_directory (i think it does currently if a file also exists in the repo's root)
  • don't expose repo URL
    • even when an operation fails (#7)

error: the following files have changes staged in the index

I'm getting this error from the command git --work-tree dist rm -r '*', would you recommend --cached or -f?

error: the following files have changes staged in the index
(use --cached to keep the file, or -f to force removal)

My guess is that it is caused by the branch having existed previously?

Btw, thanks for a great script. I use it at journster.com

Alternative

Just FYI here I described once how to accomplish very similar task using simple series of commands: docpad/docpad#385 (comment)

Sorry if that's not what your script intends to do.

Setup instructions

Hello @X1011,

Thanks for this script! I had trouble figuring out what to do after the last setup instruction. Here what I did:

git push origin gh-pages

(Your deploy.sh assumes the gh-pages exists on origin)

git --work-tree dist checkout master

(I could not figure out how to come back to master! git status was crazy messy with a lot of bower_components files)

Oh, and you might mention that people need to wget deploy.sh into their root directory, then chomd u+x it. Doesn't hurt :)

After that, ./deploy.sh worked like a charm! Thanks!

Hello 👋🏼

Hello! 👋🏼 I just wanted to thank you for making Git Directory Deploy and to inform you that we have forked and implemented the following changes:

  1. Replace Circle CI with GitHub Actions.
  2. Set up shellcheck.
  3. Integration test of deploy.sh that deploys to a temporary branch.
  4. Add support for directories that aren't Git-initialized.
  5. Refactored readme.md to make use of link references instead of inline links and wrap all text at 80 characters.

These are the most significant changes I can think of. We will probably make more changes going forward. We will be using Git Directory Deploy to deploy developer.swedbankpay.com by its inclusion in jekyll-plantuml.

If you would like pull-requests for any of the mentioned changes, please let me know. 😃 👍

refactor readme

i think the readme needs some refactoring now. It doesn't make sense anymore to instruct users to edit the variables in the script itself, especially considering how deeply buried those default values have gotten with the recent changes.

i'm thinking we merge the configuration and options sections, and the run section can be simplified, or maybe even mixed somewhere in with the rest, too.

overall, it should be more like a man page now that the script is more like a full-fledged command-line utility.

i hopefully will be able to tackle this in the next couple of days, but you, of course, are welcome to take a shot, too, @matro (or anyone else who happens to be lurking here).

Refusing to fetch into current branch refs/heads/master of non-bare repository

The following command

GIT_DEPLOY_DIR=deploy \
GIT_DEPLOY_BRANCH=master \
GIT_DEPLOY_REPO=https://<token>@github.com/<org>/<org>.github.io.git \
git-directory-deploy --verbose -m 'New: Deploy'

gives the following error

fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository

Any idea?

I think it depends on the fact that I'm pushing to the master branch (of another repository) while I am on the master locally.

deploy directory must be committed?

Hi

I've found this very useful trick to automatically deploy the contents of my deploy_folder as my gh-pages content. I've managed to get it working, but only when I add the deploy_folder to master.

If I don't add the deploy_folder to git, then there is no way for travis to access the files in the deploy_folder? Is this interpretation correct? Thus - to have travis run the deploy.cs, I do need to commit the deploy_folder contents, in my view. Please tell me if I am wrong in this?

Regards

Add development notes to readme

I've been kind of just winging it so far. Would it be worth adding a "development" section to the readme

Things like...

  • "fork & edit & open a pull request" is 👍 for this project (it isn't always)
  • rebase (or merge?) master before opening a PR, if it matters
  • to squash or not squash commits?

...might be nice to just lay out for folks. Tons of ways to use Git and Github.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.