Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
feat: continuous delivery option
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jun 1, 2016
1 parent 00f7acd commit 757fc5e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
20 changes: 20 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ module.exports = yeoman.Base.extend({
this.props
);

this.fs.copyTpl(
this.templatePath('.travis/publish.sh'),
this.destinationPath('.travis/publish.sh'),
this.props
);
this.fs.copyTpl(
this.templatePath('GENERATOR_INFO.md'),
this.destinationPath('GENERATOR_INFO.md'),
this.props
);

this.fs.copyTpl(
this.templatePath('readme.md'),
this.destinationPath('readme.md'),
Expand Down Expand Up @@ -291,6 +302,15 @@ module.exports = yeoman.Base.extend({
this.log('\n' + chalk.green('Edit readme.md:'));
this.log(chalk.yellow('- change ' + chalk.cyan('ADD_YOUR_ID') + ' in the AppVeyor badge.'));
this.log(chalk.yellow('- change ' + chalk.cyan('YOUR_LICENSE') + ' in the License badge.') + '\n');

// Travis CI with continuous delivery
this.log('\n' + chalk.green('Active continuous delivery:'));
this.log(chalk.yellow('- generate encrypted SSH key.'));
this.log(chalk.yellow('- change ' + chalk.cyan('$encrypted_xxxx_key') +
' and ' + chalk.cyan('$encrypted_xxxx_iv') +
' in ' + chalk.cyan('.travis/publish.sh') + '.'));
this.log(chalk.yellow('- add the SSH key to your Github account.'));
this.log(chalk.yellow('- add ' + chalk.cyan('ATOM_ACCESS_TOKEN') + ' to Travis UI.'));
}

});
3 changes: 3 additions & 0 deletions generators/app/templates/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ addons:
- git
- libgnome-keyring-dev
- fakeroot

after_success:
- ./.travis/publish.sh
51 changes: 51 additions & 0 deletions generators/app/templates/.travis/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
## version 1.0.0
## author: Ludovic Fernandez (@ldez/@ludnadez)

set -e

## Custom variables
USER_EMAIL="<%= authorEmail %>"
USER_NAME="<%= authorName %>"
GIT_REPOSITORY='git@github.com:<%= githubAccount %>/<%= name %>.git'
SSH_KEY_NAME="travis_rsa"
AUTHORIZED_BRANCH='master'
PUBLISH_TYPE=${PUBLISH_TYPE:="patch"}

## Fix apm path to the Atom stable channel
APM_SCRIPT_PATH=${APM_SCRIPT_PATH:="$HOME/atom/usr/bin/apm"}

cd "$TRAVIS_BUILD_DIR"

## Prevent publish on tags
CURRENT_TAG=$(git tag --contains HEAD)

if [ -n "${PUBLISH}" ] && [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$ATOM_CHANNEL" = "stable" ] && [ "$TRAVIS_BRANCH" = "$AUTHORIZED_BRANCH" ] && [ -z "$CURRENT_TAG" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]
then
echo 'Publishing...'
else
echo 'Skipping publishing'
exit 0
fi

## Git configuration
git config --global user.email "${USER_EMAIL}"
git config --global user.name "${USER_NAME}"

## Loading SSH key
echo "Loading key..."
## TODO you must change `$encrypted_xxxx_key` and `$encrypted_xxxx_iv`
openssl aes-256-cbc -K "$encrypted_xxxx_key" -iv "$encrypted_xxxx_iv" -in .travis/${SSH_KEY_NAME}.enc -out ~/.ssh/${SSH_KEY_NAME} -d
eval "$(ssh-agent -s)"
chmod 600 ~/.ssh/${SSH_KEY_NAME}
ssh-add ~/.ssh/${SSH_KEY_NAME}

## Change origin url to use SSH
git remote set-url origin "${GIT_REPOSITORY}"

## Force checkout master branch (because Travis uses a detached head)
git checkout ${AUTHORIZED_BRANCH}

## Publish
"$APM_SCRIPT_PATH" login --token "${ATOM_ACCESS_TOKEN}"
"$APM_SCRIPT_PATH" publish "${PUBLISH_TYPE}"
28 changes: 28 additions & 0 deletions generators/app/templates/GENERATOR_INFO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# For generator's user

## `readme.md`

Edit `readme.md`:

- change `ADD_YOUR_ID` in the AppVeyor badge.
- change `YOUR_LICENSE` in the License badge.

## Package publising with continuous delivery

How to use [Travis CI](https://travis-ci.org) to publish package?

Every merged PR is released as a new version (by default a `patch`).

We use the [Travis CI UI](https://travis-ci.org/<%= githubAccount %>/<%= name %>/settings) to manage the publishing system via secure environment variables:

* `PUBLISH_TYPE`: default `patch`, can be change to `minor`, `major`.
* `PUBLISH`: if not defined, prevent the publishing.
* `$encrypted_xxxx_key` and `$encrypted_xxxx_iv`: defined the main key and vector to encrypt the SSH key.
* `ATOM_ACCESS_TOKEN`: defined the Atom token for `apm`.

Active continuous delivery:

* generate encrypted SSH key.
* change `$encrypted_xxxx_key` and `$encrypted_xxxx_iv` in `.travis/publish.sh`.
* add the SSH key to your Github account. (https://github.com/settings/keys)
* add `ATOM_ACCESS_TOKEN` to [Travis CI UI](https://travis-ci.org/<%= githubAccount %>/<%= name %>/settings).
2 changes: 2 additions & 0 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('generator-atom-package-plus:app', function() {
'.github/CONTRIBUTING.md',
'.github/ISSUE_TEMPLATE.md',
'.github/PULL_REQUEST_TEMPLATE.md',
'.travis/publish.sh',
'lib/main.coffee',
'spec/package-spec.coffee',
'grammars/package-generator-test.cson',
Expand Down Expand Up @@ -138,6 +139,7 @@ describe('generator-atom-package-plus:app', function() {
'.github/CONTRIBUTING.md',
'.github/ISSUE_TEMPLATE.md',
'.github/PULL_REQUEST_TEMPLATE.md',
'.travis/publish.sh',
'lib/main.coffee',
'spec/package-spec.coffee',
]);
Expand Down

0 comments on commit 757fc5e

Please sign in to comment.