Skip to content

Commit

Permalink
feat: Add generic CI support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Oct 26, 2019
1 parent 42d316e commit 7ffc2e9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Read all about it here: https://blog.greenkeeper.io/announcing-native-lockfile-s
* ✅ Drone.io _Thank you [@donny-dont](https://github.com/greenkeeperio/greenkeeper-lockfile/pull/141) 👏_
* ✅ AppVeyor _Thank you [@patkub](https://github.com/greenkeeperio/greenkeeper-lockfile/pull/142) 👏_
* ✅ GitLab CI _Thank you [@baer95](https://github.com/greenkeeperio/greenkeeper-lockfile/pull/227) 👏_
*[Any generic CI](#generic-setup)


* 🙏 [Contribute your own](#contributing-a-ci-service)
Expand Down Expand Up @@ -160,6 +161,20 @@ the following environment variables:
- VCS_ROOT_URL from the vcsroot.<vcsrootid>.url parameter
- VCS_ROOT_BRANCH from the teamcity.build.branch parameter

## Generic Setup

A generic CI setup allows greenkeeper-lockfile to function in any CI by getting all the data from environment variables.
All the environment variables are required; boolean values should be provided as the string "true" or "false".

| **Variable** | **Description** | **Type** | **Example** |
|----------------------------------|-----------------------------------------------------------------------------------------------|----------|----------------------------------|
| GK_LOCK_GENERIC_CI | Set this to `true` to trigger generic CI | boolean | true |
| GK_LOCK_GENERIC_CI_REPO_SLUG | Your GitHub repo slug | string | greenkeeper/greenkeeper-lockfile |
| GK_LOCK_GENERIC_CI_BRANCH_NAME | Name of the current branch | string | greenkeeper/lodash-4.0.0 |
| GK_LOCK_GENERIC_CI_FIRST_PUSH | Whether this is the first push to the branch or not | boolean | true |
| GK_LOCK_GENERIC_CI_CORRECT_BUILD | Is this a regular build (not a pull request for example) | boolean | false |
| GK_LOCK_GENERIC_CI_UPLOAD_BUILD | Should the lockfile be uploaded from this build (relevant for testing multiple node versions) | boolean | true |

## Configuration options

| Environment Variable | default value | what is it for? |
Expand Down
33 changes: 33 additions & 0 deletions ci-services/generic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const forEach = require('lodash/forEach');
const env = process.env;

const _export = {
// The GitHub repo slug
repoSlug: env.GK_LOCK_GENERIC_CI_REPO_SLUG,
// The name of the current branch
branchName: env.GK_LOCK_GENERIC_CI_BRANCH_NAME,
// Is this the first push of the build
firstPush: env.GK_LOCK_GENERIC_CI_FIRST_PUSH,
// Is this a regular build
correctBuild: env.GK_LOCK_GENERIC_CI_CORRECT_BUILD,
// Should the lockfile be uploaded from this build
uploadBuild: env.GK_LOCK_GENERIC_CI_UPLOAD_BUILD
};

let hasMissingVars = false;
forEach(_export, (value, key) => {
if (!value) {
console.error(`${key} missing`);
hasMissingVars = true;
}
});

if (!hasMissingVars) {
for (const k of ['firstPush', 'correctBuild', 'uploadBuild']) {
_export[k] = _export[k] === 'true';
}

module.exports = _export;
}
3 changes: 2 additions & 1 deletion ci-services/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = {
appveyor: () => env.APPVEYOR === 'True' || env.APPVEYOR === 'true',
gitlab: () => env.GITLAB_CI === 'true',
buddyworks: () => env.BUDDY_EXECUTION_ID !== undefined,
cirrus: () => env.CIRRUS_CI === 'true'
cirrus: () => env.CIRRUS_CI === 'true',
generic: () => env.GK_LOCK_GENERIC_CI === 'true'
}

0 comments on commit 7ffc2e9

Please sign in to comment.