Comparing version 2.0.1 to 2.1.0
@@ -20,9 +20,13 @@ const execa = require('execa'); | ||
try { | ||
const branch = execa | ||
.sync('git', ['show', '-s', '--pretty=%d', 'HEAD']) | ||
.stdout.replace(/^\(|\)$/g, '') | ||
.split(', ') | ||
.find(branch => branch.startsWith('origin/')); | ||
const headRef = execa.sync('git', ['rev-parse', '--abbrev-ref', 'HEAD']).stdout; | ||
return branch ? branch.match(/^origin\/(.+)/)[1] : execa.sync('git', ['rev-parse', '--abbrev-ref', 'HEAD']).stdout; | ||
if (headRef === 'HEAD') { | ||
const branch = execa | ||
.sync('git', ['show', '-s', '--pretty=%d', 'HEAD']) | ||
.stdout.replace(/^\(|\)$/g, '') | ||
.split(', ') | ||
.find(branch => branch.startsWith('origin/')); | ||
return branch ? branch.match(/^origin\/(.+)/)[1] : undefined; | ||
} | ||
return headRef; | ||
} catch (err) { | ||
@@ -29,0 +33,0 @@ return undefined; |
{ | ||
"name": "env-ci", | ||
"description": "Get environment variables exposed by CI services", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"author": "Pierre Vanduynslager (https://github.com/pvdlg)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -77,1 +77,15 @@ # env-ci | ||
If none of the above CI services is detected, `commit` and `branch` are determined based on the local Git repository, and `isCi` is determined based on the `CI` environment variable. | ||
## Caveats | ||
### Git `branch` determination | ||
Certain CI services don't provide an environment variable to determine the current Git branch being built. | ||
In such cases the branch is determined with the command `git rev-parse --abbrev-ref HEAD`. | ||
However, if the local repository is in a [detached head state](https://git-scm.com/docs/git-checkout#_detached_head) the branch cannot be determined directly. In such case, `env-ci` will look for the remote branches having the same HEAD as the local detached HEAD to determine the branch from which the detached HEAD was created. | ||
In the rare case where there is multiple remote branches with the same HEAD as the local detached HEAD, `env-ci` will arbitrarily pick the first one. This can lead to an inaccurate `branch` value for certain CI services in such circumstances. | ||
Affected CI services: | ||
- [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22562
392
91