forked from greenkeeperio/greenkeeper-lockfile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for monorepos and dependencies from monorepos BREAKING CHANGE: multiple breaking changes, see list below. - needs testing with CI services other than TravisCI - CI Environment Variable needed for default branches other than `master`
- Loading branch information
Showing
51 changed files
with
2,166 additions
and
1,809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# greenkeeper-lockfile | ||
# Greenkeeper Lockfile | ||
|
||
After [enabling Greenkeeper for your repository](https://github.com/integration/greenkeeper) you can use this package to make it work with lockfiles, such as `npm-shrinkwrap.json`, `package-lock.json` or `yarn.lock`. | ||
|
||
|
@@ -11,6 +11,21 @@ After [enabling Greenkeeper for your repository](https://github.com/integration/ | |
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
|
||
- [Greenkeeper Lockfile](#greenkeeper-lockfile) | ||
- [Package Managers](#package-managers) | ||
- [CI Services](#ci-services) | ||
- [How does it work](#how-does-it-work) | ||
- [Setup](#setup) | ||
- [Using Greenkeeper with Monorepos](#using-greenkeeper-with-monorepos) | ||
- [Testing multiple node versions](#testing-multiple-node-versions) | ||
- [CircleCI workflows](#circleci-workflows) | ||
- [TeamCity Setup](#teamcity-setup) | ||
- [Configuration options](#configuration-options) | ||
- [Contributing a CI Service](#contributing-a-ci-service) | ||
- [Environment information](#environment-information) | ||
- [Detecting your service](#detecting-your-service) | ||
- [Testing your service](#testing-your-service) | ||
|
||
## Package Managers | ||
|
||
* ✅ npm _(including npm5)_ | ||
|
@@ -46,6 +61,10 @@ After [enabling Greenkeeper for your repository](https://github.com/integration/ | |
|
||
3. Configure your CI to run `greenkeeper-lockfile-update` right before it executes your tests and `greenkeeper-lockfile-upload` right after it executed your tests. | ||
|
||
_The next Step is only applicable greenkeeper-lockfile version 2 (with monorepo support)_ | ||
|
||
4. If you use a default branch that is **not** `master` then you have to add the environment variable `GK_LOCK_DEFAULT_BRANCH` with the name of your default branch to your CI. | ||
|
||
|
||
### Example Travis CI configurations | ||
|
||
|
@@ -80,6 +99,12 @@ after_script: greenkeeper-lockfile-upload | |
|
||
To run the lockfile-update script with custom command line arguments, set the `GK_LOCK_YARN_OPTS` environment variable to your needs (set it to `--ignore-engines`, for example). They will be appended to the `yarn add` command. | ||
|
||
## Using Greenkeeper with Monorepos | ||
|
||
greenkeeper-lockfile 2.0.0 offers support for monorepos. To use it make sure you install `greenkeeper-lockfile@2` explicitly. | ||
|
||
If you are using a default branch on Github that is **not** called `master`, please set an Environment Variable `GK_LOCK_DEFAULT_BRANCH` with the name of your default branch in your CI. | ||
|
||
## Testing multiple node versions | ||
|
||
It is common to test multiple node versions and therefor have multiple test jobs for one build. In this case the lockfile will automatically be updated for every job, but only uploaded for the first one. | ||
|
@@ -96,7 +121,7 @@ before_script: greenkeeper-lockfile-update | |
after_script: greenkeeper-lockfile-upload | ||
``` | ||
|
||
### CircleCI workflows | ||
## CircleCI workflows | ||
|
||
In order to use `greenkeeper-lockfile` with CircleCI workflows, it must be in the first job run. Use [sequential job execution](https://circleci.com/docs/2.0/workflows/#sequential-job-execution-example) to ensure the job that runs `greenkeeper-lockfile` is always executed first. For example, if `greenkeeper-lockfile` is run in the `lockfile` job, all other jobs in the workflow must require the `lockfile` job to finish before running: | ||
|
||
|
@@ -111,14 +136,23 @@ workflows: | |
- lockfile | ||
``` | ||
|
||
### TeamCity Setup | ||
## TeamCity Setup | ||
|
||
In order for this to work with TeamCity, the build configuration needs to set | ||
the following environment variables: | ||
|
||
- VCS_ROOT_URL from the vcsroot.<vcsrootid>.url parameter | ||
- VCS_ROOT_BRANCH from the teamcity.build.branch parameter | ||
|
||
## Configuration options | ||
|
||
| Environment Variable | default value | what is it for? | | ||
| ------------- | ------------- | ------------- | | ||
| GK_LOCK_YARN_OPTS | '' | Add yarn options that greenkeeper should use e.g. `--ignore-engines` | | ||
| GK_LOCK_DEFAULT_BRANCH | 'master' | Set your default github branch name | | ||
| GK_LOCK_COMMIT_AMEND | false | Lockfile commit should be amended to the regular Greenkeeper commit | | ||
| GK_LOCK_COMMIT_NAME | 'greenkeeperio-bot' | Set your prefered git commit name | | ||
| GK_LOCK_COMMIT_EMAIL | '[email protected]' | Set your prefered git commit email | | ||
|
||
## Contributing a CI Service | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const fs = require('fs') | ||
module.exports = function ignores () { | ||
const ignoreFile = '.gitignore' | ||
if (!fs.existsSync(ignoreFile)) { | ||
return [] | ||
} | ||
|
||
const ignoreContents = fs.readFileSync(ignoreFile).toString() | ||
return (ignoreContents.length && ignoreContents.split('\n')) || [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,14 +16,10 @@ const yarnFlags = { | |
'optionalDependencies': ' -O' | ||
} | ||
|
||
module.exports = function updateLockfile (dependency, options) { | ||
module.exports.updateLockfile = function updateLockfile (dependency, options) { | ||
if (!options.yarn && semver.lt(exec('npm --version').toString().trim(), '3.0.0')) { | ||
exec('npm shrinkwrap') | ||
} else { | ||
// revert and unstage the changes done by greenkeeper | ||
exec('git revert -n HEAD') | ||
exec('git reset HEAD') | ||
|
||
if (options.yarn) { | ||
const flag = yarnFlags[dependency.type] | ||
const envArgs = process.env.GK_LOCK_YARN_OPTS ? ` ${process.env.GK_LOCK_YARN_OPTS.trim()}` : '' | ||
|
@@ -40,29 +36,40 @@ module.exports = function updateLockfile (dependency, options) { | |
exec('npm5 -v') | ||
npmBin = 'npm5' | ||
} catch (err) {} | ||
|
||
exec(`${npmBin} install${args}`) | ||
} | ||
} | ||
} | ||
|
||
const commitEmail = process.env.GK_LOCK_COMMIT_EMAIL ? process.env.GK_LOCK_COMMIT_EMAIL.trim() : '[email protected]' | ||
const commitName = process.env.GK_LOCK_COMMIT_NAME ? process.env.GK_LOCK_COMMIT_NAME.trim() : 'greenkeeperio-bot' | ||
const shouldAmend = !_.includes([undefined, `0`, 'false', 'null', 'undefined'], process.env.GK_LOCK_COMMIT_AMEND) | ||
|
||
module.exports.stageLockfile = function stageLockfile () { | ||
// make sure that we have changes to add | ||
if (exec('git status --porcelain').toString() === '') return | ||
|
||
// stage the updated lockfile | ||
exec('git add npm-shrinkwrap.json 2>/dev/null || true') | ||
exec('git add package-lock.json 2>/dev/null || true') | ||
exec('git add yarn.lock 2>/dev/null || true') | ||
} | ||
|
||
module.exports.commitLockfiles = function commitLockfiles () { | ||
const commitEmail = process.env.GK_LOCK_COMMIT_EMAIL ? process.env.GK_LOCK_COMMIT_EMAIL.trim() : '[email protected]' | ||
const commitName = process.env.GK_LOCK_COMMIT_NAME ? process.env.GK_LOCK_COMMIT_NAME.trim() : 'greenkeeperio-bot' | ||
const shouldAmend = !_.includes([undefined, `0`, 'false', 'null', 'undefined'], process.env.GK_LOCK_COMMIT_AMEND) | ||
|
||
exec(`git config user.email "${commitEmail}"`) | ||
exec(`git config user.name "${commitName}"`) | ||
|
||
if (shouldAmend) { | ||
exec(`git commit --amend --author="${commitName} <${commitEmail}>" --no-edit`) | ||
} else { | ||
const updateMessage = 'chore(package): update lockfile\n\nhttps://npm.im/greenkeeper-lockfile' | ||
let lockfileWording | ||
// either say "lockfile" or "lockfiles" depending on how many files are changed | ||
if (exec('git status --porcelain').toString().split('\n').length > 2) { | ||
lockfileWording = 'lockfiles' | ||
} else { | ||
lockfileWording = 'lockfile' | ||
} | ||
const updateMessage = `chore(package): update ${lockfileWording}\n\nhttps://npm.im/greenkeeper-lockfile` | ||
exec(`git commit -m "${updateMessage}"`) | ||
} | ||
} |
Oops, something went wrong.