Automatically or manually deploy build artifacts to a Git repository. The tool works awesome with semantic-release and any CI service.
npm install --save-dev deploy-to-git
Configuration for the tool needs to be placed at config.deployToGit object inside package.json.
repository- a repositorybranch- a branch of the repository where you want to push the artifactsfolder- a folder where artifacts are generated by the build and where the repository is clonedscript- a script which runs the buildcommit- commit textuser- commitee information for Git - an object with keysnameandemailbeforePushScript(optional) - a command that should be run after a commit (e. g. add needed git tags).
Substrings started with $ are replaced by corresponding environment variables.
Let's say you want to deploy artifacts to branch called artifacts. Let's say used build tool compiles the artifacts to build folder via NPM script called build-my-app. You'll need:
- Create
artifactsbranch manually and remove all files from it (because you probably create the branch copying main branch contents). Push it to remote repository. - Add README or whatever you want to have at this branch.
- Add
buildfolder to.gitignoreof your main branch. - Configure
deploy-to-git
"scripts": {
"deploy": "deploy-to-git",
"build-my-app": "a-build-script"
}
"config": {
"deployToGit": {
"repository": "git@github.com:owner/your-repo.git",
"branch": "artifacts",
"folder": "build",
"script": "npm run build-my-app",
"commit": "Automatic commit text",
"user": {
"email": "you@example.com",
"name": "Your name"
}
}
}That's it. When you run npm run deploy the tool does the following:
- Clone the repository to
buildfolder. - Run script
npm run build-my-appwhich creates/replaces files atbuildfolder. - Commit and push changes.
Tip: remove build folder before deploy-to-git run.
For more info check out index.js.
To run it on Travis CI use the following format of repository field: https://$GH_TOKEN@github.com/owner/your-repo.git. You can generate GH_TOKEN at Github settings and add it to Travis CI manually. For more info just google it ("generate github token", "add environment variable to Travis") :)
It is generated automatically if you use semantic-release-cli.
Just add deploy-to-github to semantic-release script.
"deploy": "deploy-to-git",
"semantic-release": "semantic-release pre && npm run deploy && npm publish && semantic-release post",
Tip: You can use a release version in a commit message:
"commit": "Publising $npm_package_version",
Real example can be found there. The application is compiled via webpack to bundle folder and pushed to gh-pages branch.