Skip to content

Commit 81fd993

Browse files
committedNov 12, 2024
feat: add vendor id
1 parent 2a6f8e6 commit 81fd993

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
 

‎create-typings.js

+6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ export const isPR: boolean | null;
3131
* to use \`ci.TRAVIS\` instead.
3232
*/
3333
export const name: string | null;
34+
/**
35+
* Returns a string containing the identifier of the CI server the code is running on. If
36+
* CI server is not detected, it returns \`null\`.
37+
*/
38+
export const id: string | null;
3439
40+
/* Vendor constants */
3541
`
3642

3743
for (const { constant } of vendors) {

‎index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ export const isPR: boolean | null;
2525
* to use `ci.TRAVIS` instead.
2626
*/
2727
export const name: string | null;
28+
/**
29+
* Returns a string containing the identifier of the CI server the code is running on. If
30+
* CI server is not detected, it returns `null`.
31+
*/
32+
export const id: string | null;
2833

34+
/* Vendor constants */
2935
export const AGOLA: boolean;
3036
export const APPCIRCLE: boolean;
3137
export const APPVEYOR: boolean;

‎index.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Object.defineProperty(exports, '_vendors', {
1313

1414
exports.name = null
1515
exports.isPR = null
16+
exports.id = null
1617

1718
vendors.forEach(function (vendor) {
1819
const envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env]
@@ -28,6 +29,7 @@ vendors.forEach(function (vendor) {
2829

2930
exports.name = vendor.name
3031
exports.isPR = checkPR(vendor)
32+
exports.id = vendor.constant
3133
})
3234

3335
exports.isCI = !!(

‎test.js

+56
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test('Not CI', function (t) {
3535
t.equal(ci.isCI, false)
3636
t.equal(ci.isPR, null)
3737
t.equal(ci.name, null)
38+
t.equal(ci.id, null)
3839
t.equal(ci.TRAVIS, false)
3940
assertVendorConstants(null, ci, t)
4041

@@ -61,6 +62,7 @@ test('Unknown CI', function (t) {
6162
t.equal(ci.isCI, true)
6263
t.equal(ci.isPR, null)
6364
t.equal(ci.name, null)
65+
t.equal(ci.id, null)
6466
t.equal(ci.TRAVIS, false)
6567
assertVendorConstants(null, ci, t)
6668

@@ -82,6 +84,7 @@ test('Anonymous CI', function (t) {
8284
t.equal(ci.isCI, true)
8385
t.equal(ci.isPR, null)
8486
t.equal(ci.name, null)
87+
t.equal(ci.id, null)
8588
}
8689

8790
t.end()
@@ -98,6 +101,7 @@ test('AppVeyor - PR', function (t) {
98101
t.equal(ci.isPR, true)
99102
t.equal(ci.name, 'AppVeyor')
100103
t.equal(ci.APPVEYOR, true)
104+
t.equal(ci.id, 'APPVEYOR')
101105
assertVendorConstants('APPVEYOR', ci, t)
102106

103107
delete process.env.APPVEYOR
@@ -116,6 +120,7 @@ test('AppVeyor - Not PR', function (t) {
116120
t.equal(ci.isPR, false)
117121
t.equal(ci.name, 'AppVeyor')
118122
t.equal(ci.APPVEYOR, true)
123+
t.equal(ci.id, 'APPVEYOR')
119124
assertVendorConstants('APPVEYOR', ci, t)
120125

121126
delete process.env.APPVEYOR
@@ -134,6 +139,7 @@ test('Azure Pipelines - PR', function (t) {
134139
t.equal(ci.isPR, true)
135140
t.equal(ci.name, 'Azure Pipelines')
136141
t.equal(ci.AZURE_PIPELINES, true)
142+
t.equal(ci.id, 'AZURE_PIPELINES')
137143
assertVendorConstants('AZURE_PIPELINES', ci, t)
138144

139145
delete process.env.TF_BUILD
@@ -152,6 +158,7 @@ test('Azure Pipelines - Not PR', function (t) {
152158
t.equal(ci.isPR, false)
153159
t.equal(ci.name, 'Azure Pipelines')
154160
t.equal(ci.AZURE_PIPELINES, true)
161+
t.equal(ci.id, 'AZURE_PIPELINES')
155162
assertVendorConstants('AZURE_PIPELINES', ci, t)
156163

157164
delete process.env.TF_BUILD
@@ -170,6 +177,7 @@ test('Bitbucket Pipelines - PR', function (t) {
170177
t.equal(ci.isPR, true)
171178
t.equal(ci.name, 'Bitbucket Pipelines')
172179
t.equal(ci.BITBUCKET, true)
180+
t.equal(ci.id, 'BITBUCKET')
173181
assertVendorConstants('BITBUCKET', ci, t)
174182

175183
delete process.env.BITBUCKET_COMMIT
@@ -188,6 +196,7 @@ test('Bitbucket Pipelines - Not PR', function (t) {
188196
t.equal(ci.isPR, false)
189197
t.equal(ci.name, 'Bitbucket Pipelines')
190198
t.equal(ci.BITBUCKET, true)
199+
t.equal(ci.id, 'BITBUCKET')
191200
assertVendorConstants('BITBUCKET', ci, t)
192201

193202
delete process.env.BITBUCKET_COMMIT
@@ -206,6 +215,7 @@ test('Buildkite - PR', function (t) {
206215
t.equal(ci.isPR, true)
207216
t.equal(ci.name, 'Buildkite')
208217
t.equal(ci.BUILDKITE, true)
218+
t.equal(ci.id, 'BUILDKITE')
209219
assertVendorConstants('BUILDKITE', ci, t)
210220

211221
delete process.env.BUILDKITE
@@ -225,6 +235,7 @@ test('Buildkite - Not PR', function (t) {
225235
t.equal(ci.isPR, false)
226236
t.equal(ci.name, 'Buildkite')
227237
t.equal(ci.BUILDKITE, true)
238+
t.equal(ci.id, 'BUILDKITE')
228239
assertVendorConstants('BUILDKITE', ci, t)
229240

230241
delete process.env.BUILDKITE
@@ -244,6 +255,7 @@ test('CircleCI - PR', function (t) {
244255
t.equal(ci.isPR, true)
245256
t.equal(ci.name, 'CircleCI')
246257
t.equal(ci.CIRCLE, true)
258+
t.equal(ci.id, 'CIRCLE')
247259
assertVendorConstants('CIRCLE', ci, t)
248260

249261
delete process.env.CIRCLECI
@@ -262,6 +274,7 @@ test('CircleCI - Not PR', function (t) {
262274
t.equal(ci.isPR, false)
263275
t.equal(ci.name, 'CircleCI')
264276
t.equal(ci.CIRCLE, true)
277+
t.equal(ci.id, 'CIRCLE')
265278
assertVendorConstants('CIRCLE', ci, t)
266279

267280
delete process.env.CIRCLECI
@@ -280,6 +293,7 @@ test('Cirrus CI - PR', function (t) {
280293
t.equal(ci.isPR, true)
281294
t.equal(ci.name, 'Cirrus CI')
282295
t.equal(ci.CIRRUS, true)
296+
t.equal(ci.id, 'CIRRUS')
283297
assertVendorConstants('CIRRUS', ci, t)
284298

285299
delete process.env.CIRRUS_CI
@@ -298,6 +312,7 @@ test('Cirrus CI - Not PR', function (t) {
298312
t.equal(ci.isPR, false)
299313
t.equal(ci.name, 'Cirrus CI')
300314
t.equal(ci.CIRRUS, true)
315+
t.equal(ci.id, 'CIRRUS')
301316
assertVendorConstants('CIRRUS', ci, t)
302317

303318
delete process.env.CIRRUS_CI
@@ -316,6 +331,7 @@ test('Codefresh - PR', function (t) {
316331
t.equal(ci.isPR, true)
317332
t.equal(ci.name, 'Codefresh')
318333
t.equal(ci.CODEFRESH, true)
334+
t.equal(ci.id, 'CODEFRESH')
319335
assertVendorConstants('CODEFRESH', ci, t)
320336

321337
delete process.env.CF_BUILD_ID
@@ -334,6 +350,7 @@ test('Codefresh - Not PR', function (t) {
334350
t.equal(ci.isPR, false)
335351
t.equal(ci.name, 'Codefresh')
336352
t.equal(ci.CODEFRESH, true)
353+
t.equal(ci.id, 'CODEFRESH')
337354
assertVendorConstants('CODEFRESH', ci, t)
338355

339356
delete process.env.CF_BUILD_ID
@@ -352,6 +369,7 @@ test('LayerCI - PR', function (t) {
352369
t.equal(ci.isPR, true)
353370
t.equal(ci.name, 'LayerCI')
354371
t.equal(ci.LAYERCI, true)
372+
t.equal(ci.id, 'LAYERCI')
355373
assertVendorConstants('LAYERCI', ci, t)
356374

357375
delete process.env.LAYERCI
@@ -370,6 +388,7 @@ test('LayerCI - Not PR', function (t) {
370388
t.equal(ci.isPR, false)
371389
t.equal(ci.name, 'LayerCI')
372390
t.equal(ci.LAYERCI, true)
391+
t.equal(ci.id, 'LAYERCI')
373392
assertVendorConstants('LAYERCI', ci, t)
374393

375394
delete process.env.LAYERCI
@@ -386,6 +405,7 @@ test('Appcircle', function (t) {
386405
t.equal(ci.isCI, true)
387406
t.equal(ci.name, 'Appcircle')
388407
t.equal(ci.APPCIRCLE, true)
408+
t.equal(ci.id, 'APPCIRCLE')
389409
assertVendorConstants('APPCIRCLE', ci, t)
390410

391411
delete process.env.AC_APPCIRCLE
@@ -404,6 +424,7 @@ test('Render - PR', function (t) {
404424
t.equal(ci.isPR, true)
405425
t.equal(ci.name, 'Render')
406426
t.equal(ci.RENDER, true)
427+
t.equal(ci.id, 'RENDER')
407428
assertVendorConstants('RENDER', ci, t)
408429

409430
delete process.env.RENDER
@@ -423,6 +444,7 @@ test('Render - Not PR', function (t) {
423444
t.equal(ci.isPR, false)
424445
t.equal(ci.name, 'Render')
425446
t.equal(ci.RENDER, true)
447+
t.equal(ci.id, 'RENDER')
426448
assertVendorConstants('RENDER', ci, t)
427449

428450
delete process.env.RENDER
@@ -442,6 +464,7 @@ test('Semaphore - PR', function (t) {
442464
t.equal(ci.isPR, true)
443465
t.equal(ci.name, 'Semaphore')
444466
t.equal(ci.SEMAPHORE, true)
467+
t.equal(ci.id, 'SEMAPHORE')
445468
assertVendorConstants('SEMAPHORE', ci, t)
446469

447470
delete process.env.SEMAPHORE
@@ -460,6 +483,7 @@ test('Semaphore - Not PR', function (t) {
460483
t.equal(ci.isPR, false)
461484
t.equal(ci.name, 'Semaphore')
462485
t.equal(ci.SEMAPHORE, true)
486+
t.equal(ci.id, 'SEMAPHORE')
463487
assertVendorConstants('SEMAPHORE', ci, t)
464488

465489
delete process.env.SEMAPHORE
@@ -478,6 +502,7 @@ test('Travis CI - PR', function (t) {
478502
t.equal(ci.isPR, true)
479503
t.equal(ci.name, 'Travis CI')
480504
t.equal(ci.TRAVIS, true)
505+
t.equal(ci.id, 'TRAVIS')
481506
assertVendorConstants('TRAVIS', ci, t)
482507

483508
delete process.env.TRAVIS
@@ -497,6 +522,7 @@ test('Travis CI - Not PR', function (t) {
497522
t.equal(ci.isPR, false)
498523
t.equal(ci.name, 'Travis CI')
499524
t.equal(ci.TRAVIS, true)
525+
t.equal(ci.id, 'TRAVIS')
500526
assertVendorConstants('TRAVIS', ci, t)
501527

502528
delete process.env.TRAVIS
@@ -516,6 +542,7 @@ test('Netlify CI - PR', function (t) {
516542
t.equal(ci.isPR, true)
517543
t.equal(ci.name, 'Netlify CI')
518544
t.equal(ci.NETLIFY, true)
545+
t.equal(ci.id, 'NETLIFY')
519546
assertVendorConstants('NETLIFY', ci, t)
520547

521548
delete process.env.NETLIFY
@@ -535,6 +562,7 @@ test('Netlify CI - Not PR', function (t) {
535562
t.equal(ci.isPR, false)
536563
t.equal(ci.name, 'Netlify CI')
537564
t.equal(ci.NETLIFY, true)
565+
t.equal(ci.id, 'NETLIFY')
538566
assertVendorConstants('NETLIFY', ci, t)
539567

540568
delete process.env.NETLIFY
@@ -553,6 +581,7 @@ test('Vercel - NOW_BUILDER', function (t) {
553581
t.equal(ci.isPR, false)
554582
t.equal(ci.name, 'Vercel')
555583
t.equal(ci.VERCEL, true)
584+
t.equal(ci.id, 'VERCEL')
556585
assertVendorConstants('VERCEL', ci, t)
557586

558587
delete process.env.NOW_BUILDER
@@ -570,6 +599,7 @@ test('Vercel - VERCEL', function (t) {
570599
t.equal(ci.isPR, false)
571600
t.equal(ci.name, 'Vercel')
572601
t.equal(ci.VERCEL, true)
602+
t.equal(ci.id, 'VERCEL')
573603
assertVendorConstants('VERCEL', ci, t)
574604

575605
delete process.env.VERCEL
@@ -588,6 +618,7 @@ test('Vercel - PR', function (t) {
588618
t.equal(ci.isPR, true)
589619
t.equal(ci.name, 'Vercel')
590620
t.equal(ci.VERCEL, true)
621+
t.equal(ci.id, 'VERCEL')
591622
assertVendorConstants('VERCEL', ci, t)
592623

593624
delete process.env.VERCEL
@@ -606,6 +637,7 @@ test('Nevercode - PR', function (t) {
606637
t.equal(ci.isPR, true)
607638
t.equal(ci.name, 'Nevercode')
608639
t.equal(ci.NEVERCODE, true)
640+
t.equal(ci.id, 'NEVERCODE')
609641
assertVendorConstants('NEVERCODE', ci, t)
610642

611643
delete process.env.NEVERCODE
@@ -625,6 +657,7 @@ test('Nevercode - Not PR', function (t) {
625657
t.equal(ci.isPR, false)
626658
t.equal(ci.name, 'Nevercode')
627659
t.equal(ci.NEVERCODE, true)
660+
t.equal(ci.id, 'NEVERCODE')
628661
assertVendorConstants('NEVERCODE', ci, t)
629662

630663
delete process.env.NEVERCODE
@@ -643,6 +676,7 @@ test('Expo Application Services', function (t) {
643676
t.equal(ci.isPR, null)
644677
t.equal(ci.name, 'Expo Application Services')
645678
t.equal(ci.EAS, true)
679+
t.equal(ci.id, 'EAS')
646680
assertVendorConstants('EAS', ci, t)
647681

648682
delete process.env.EAS_BUILD
@@ -661,6 +695,7 @@ test('GitHub Actions - PR', function (t) {
661695
t.equal(ci.isPR, true)
662696
t.equal(ci.name, 'GitHub Actions')
663697
t.equal(ci.GITHUB_ACTIONS, true)
698+
t.equal(ci.id, 'GITHUB_ACTIONS')
664699
assertVendorConstants('GITHUB_ACTIONS', ci, t)
665700

666701
delete process.env.GITHUB_ACTIONS
@@ -680,6 +715,7 @@ test('GitHub Actions - Not PR', function (t) {
680715
t.equal(ci.isPR, false)
681716
t.equal(ci.name, 'GitHub Actions')
682717
t.equal(ci.GITHUB_ACTIONS, true)
718+
t.equal(ci.id, 'GITHUB_ACTIONS')
683719
assertVendorConstants('GITHUB_ACTIONS', ci, t)
684720

685721
delete process.env.GITHUB_ACTIONS
@@ -699,6 +735,7 @@ test('Screwdriver - PR', function (t) {
699735
t.equal(ci.isPR, true)
700736
t.equal(ci.name, 'Screwdriver')
701737
t.equal(ci.SCREWDRIVER, true)
738+
t.equal(ci.id, 'SCREWDRIVER')
702739
assertVendorConstants('SCREWDRIVER', ci, t)
703740

704741
delete process.env.SCREWDRIVER
@@ -718,6 +755,7 @@ test('Screwdriver - Not PR', function (t) {
718755
t.equal(ci.isPR, false)
719756
t.equal(ci.name, 'Screwdriver')
720757
t.equal(ci.SCREWDRIVER, true)
758+
t.equal(ci.id, 'SCREWDRIVER')
721759
assertVendorConstants('SCREWDRIVER', ci, t)
722760

723761
delete process.env.SCREWDRIVER
@@ -736,6 +774,7 @@ test('Visual Studio App Center', function (t) {
736774
// t.equal(ci.isPR, false)
737775
t.equal(ci.name, 'Visual Studio App Center')
738776
t.equal(ci.APPCENTER, true)
777+
t.equal(ci.id, 'APPCENTER')
739778
assertVendorConstants('APPCENTER', ci, t)
740779

741780
delete process.env.APPCENTER_BUILD_ID
@@ -754,6 +793,7 @@ test('Codemagic - PR', function (t) {
754793
t.equal(ci.isPR, true)
755794
t.equal(ci.name, 'Codemagic')
756795
t.equal(ci.CODEMAGIC, true)
796+
t.equal(ci.id, 'CODEMAGIC')
757797
assertVendorConstants('CODEMAGIC', ci, t)
758798

759799
delete process.env.CM_BUILD_ID
@@ -772,6 +812,7 @@ test('Codemagic - Not PR', function (t) {
772812
t.equal(ci.isPR, false)
773813
t.equal(ci.name, 'Codemagic')
774814
t.equal(ci.CODEMAGIC, true)
815+
t.equal(ci.id, 'CODEMAGIC')
775816
assertVendorConstants('CODEMAGIC', ci, t)
776817

777818
delete process.env.CM_BUILD_ID
@@ -790,6 +831,7 @@ test('Xcode Cloud - PR', function (t) {
790831
t.equal(ci.isPR, true)
791832
t.equal(ci.name, 'Xcode Cloud')
792833
t.equal(ci.XCODE_CLOUD, true)
834+
t.equal(ci.id, 'XCODE_CLOUD')
793835
assertVendorConstants('XCODE_CLOUD', ci, t)
794836

795837
delete process.env.CI_XCODE_PROJECT
@@ -808,6 +850,7 @@ test('Xcode Cloud - Not PR', function (t) {
808850
t.equal(ci.isPR, false)
809851
t.equal(ci.name, 'Xcode Cloud')
810852
t.equal(ci.XCODE_CLOUD, true)
853+
t.equal(ci.id, 'XCODE_CLOUD')
811854
assertVendorConstants('XCODE_CLOUD', ci, t)
812855

813856
delete process.env.CI_XCODE_PROJECT
@@ -825,6 +868,7 @@ test('Xcode Server - Not PR', function (t) {
825868
// t.equal(ci.isPR, false)
826869
t.equal(ci.name, 'Xcode Server')
827870
t.equal(ci.XCODE_SERVER, true)
871+
t.equal(ci.id, 'XCODE_SERVER')
828872
assertVendorConstants('XCODE_SERVER', ci, t)
829873

830874
delete process.env.XCS
@@ -842,6 +886,7 @@ test('Heroku', function (t) {
842886
t.equal(ci.isCI, true)
843887
t.equal(ci.name, 'Heroku')
844888
t.equal(ci.HEROKU, true)
889+
t.equal(ci.id, 'HEROKU')
845890
assertVendorConstants('HEROKU', ci, t)
846891

847892
process.env.NODE = realNode
@@ -857,6 +902,7 @@ test('Sourcehit', function (t) {
857902
t.equal(ci.isCI, true)
858903
t.equal(ci.name, 'Sourcehut')
859904
t.equal(ci.SOURCEHUT, true)
905+
t.equal(ci.id, 'SOURCEHUT')
860906
assertVendorConstants('SOURCEHUT', ci, t)
861907

862908
delete process.env.CI_NAME
@@ -873,6 +919,7 @@ test('ReleaseHub', function (t) {
873919
t.equal(ci.isCI, true)
874920
t.equal(ci.name, 'ReleaseHub')
875921
t.equal(ci.RELEASEHUB, true)
922+
t.equal(ci.id, 'RELEASEHUB')
876923
assertVendorConstants('RELEASEHUB', ci, t)
877924

878925
delete process.env.RELEASE_BUILD_ID
@@ -889,6 +936,7 @@ test('Gitea Actions', function (t) {
889936
t.equal(ci.isCI, true)
890937
t.equal(ci.name, 'Gitea Actions')
891938
t.equal(ci.GITEA_ACTIONS, true)
939+
t.equal(ci.id, 'GITEA_ACTIONS')
892940
assertVendorConstants('GITEA_ACTIONS', ci, t)
893941

894942
delete process.env.GITEA_ACTIONS
@@ -907,6 +955,7 @@ test('Agola CI', function (t) {
907955
t.equal(ci.isPR, false)
908956
t.equal(ci.name, 'Agola CI')
909957
t.equal(ci.AGOLA, true)
958+
t.equal(ci.id, 'AGOLA')
910959
assertVendorConstants('AGOLA', ci, t)
911960

912961
delete process.env.AGOLA_GIT_REF
@@ -926,6 +975,7 @@ test('Agola CI - PR', function (t) {
926975
t.equal(ci.isPR, true)
927976
t.equal(ci.name, 'Agola CI')
928977
t.equal(ci.AGOLA, true)
978+
t.equal(ci.id, 'AGOLA')
929979
assertVendorConstants('AGOLA', ci, t)
930980

931981
delete process.env.AGOLA_GIT_REF
@@ -945,6 +995,7 @@ test('Vela', function (t) {
945995
t.equal(ci.isPR, false)
946996
t.equal(ci.name, 'Vela')
947997
t.equal(ci.VELA, true)
998+
t.equal(ci.id, 'VELA')
948999
assertVendorConstants('VELA', ci, t)
9491000

9501001
delete process.env.VELA
@@ -964,6 +1015,7 @@ test('Vela - PR', function (t) {
9641015
t.equal(ci.isPR, true)
9651016
t.equal(ci.name, 'Vela')
9661017
t.equal(ci.VELA, true)
1018+
t.equal(ci.id, 'VELA')
9671019
assertVendorConstants('VELA', ci, t)
9681020

9691021
delete process.env.VELA
@@ -981,6 +1033,7 @@ test('Prow', function (t) {
9811033
t.equal(ci.isCI, true)
9821034
t.equal(ci.name, 'Prow')
9831035
t.equal(ci.PROW, true)
1036+
t.equal(ci.id, 'PROW')
9841037
assertVendorConstants('PROW', ci, t)
9851038

9861039
delete process.env.PROW_JOB_ID
@@ -997,6 +1050,7 @@ test('Earthly CI', function (t) {
9971050
t.equal(ci.isCI, true)
9981051
t.equal(ci.name, 'Earthly')
9991052
t.equal(ci.EARTHLY, true)
1053+
t.equal(ci.id, 'EARTHLY')
10001054
assertVendorConstants('EARTHLY', ci, t)
10011055

10021056
delete process.env.EARTHLY_CI
@@ -1013,6 +1067,7 @@ test('AWS Codebuild', function (t) {
10131067
t.equal(ci.isCI, true)
10141068
t.equal(ci.name, 'AWS CodeBuild')
10151069
t.equal(ci.CODEBUILD, true)
1070+
t.equal(ci.id, 'CODEBUILD')
10161071
assertVendorConstants('CODEBUILD', ci, t)
10171072

10181073
delete process.env.CODEBUILD_BUILD_ARN
@@ -1031,6 +1086,7 @@ test('AWS Codebuild - PR', function (t) {
10311086
t.equal(ci.isPR, true)
10321087
t.equal(ci.name, 'AWS CodeBuild')
10331088
t.equal(ci.CODEBUILD, true)
1089+
t.equal(ci.id, 'CODEBUILD')
10341090
assertVendorConstants('CODEBUILD', ci, t)
10351091

10361092
delete process.env.CODEBUILD_BUILD_ARN

0 commit comments

Comments
 (0)
Please sign in to comment.