Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extract and set the LayerCI env variables #16233

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/server/__snapshots__/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The ciBuildId is automatically detected if you are running Cypress in any of the
- teamfoundation
- travis
- netlify
- layerci
Because the ciBuildId could not be auto-detected you must pass the --ci-build-id flag manually.
Expand Down Expand Up @@ -117,6 +118,7 @@ The ciBuildId is automatically detected if you are running Cypress in any of the
- teamfoundation
- travis
- netlify
- layerci
Because the ciBuildId could not be auto-detected you must pass the --ci-build-id flag manually.
Expand Down Expand Up @@ -155,6 +157,7 @@ The ciBuildId is automatically detected if you are running Cypress in any of the
- teamfoundation
- travis
- netlify
- layerci
Because the ciBuildId could not be auto-detected you must pass the --ci-build-id flag manually.
Expand Down
19 changes: 18 additions & 1 deletion packages/server/lib/util/ci_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const CI_PROVIDERS = {
'travis': 'TRAVIS',
'wercker': isWercker,
netlify: 'NETLIFY',
layerci: 'LAYERCI',
}

const _detectProviderName = () => {
Expand All @@ -128,7 +129,7 @@ const _detectProviderName = () => {
})
}

// TODO: dont forget about buildNumber!
// TODO: don't forget about buildNumber!
// look at the old commit that was removed to see how we did it
const _providerCiParams = () => {
return {
Expand Down Expand Up @@ -387,6 +388,17 @@ const _providerCiParams = () => {
'DEPLOY_PRIME_URL',
'DEPLOY_ID',
]),
// https://layerci.com/docs/layerfile-reference/build-env
layerci: extract([
'LAYERCI_JOB_ID',
'LAYERCI_RUNNER_ID',
'RETRY_INDEX',
'LAYERCI_PULL_REQUEST',
'LAYERCI_REPO_NAME',
'LAYERCI_REPO_OWNER',
'LAYERCI_BRANCH',
'GIT_TAG', // short hex for commits
]),
}
}

Expand Down Expand Up @@ -571,6 +583,11 @@ const _providerCommitParams = () => {
branch: env.BRANCH,
remoteOrigin: env.REPOSITORY_URL,
},
layerci: {
sha: env.GIT_COMMIT,
branch: env.LAYERCI_BRANCH,
message: env.GIT_COMMIT_TITLE,
},
}
}

Expand Down
37 changes: 37 additions & 0 deletions packages/server/test/unit/ci_provider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,43 @@ describe('lib/util/ci_provider', () => {
})
})

it('layerci', () => {
resetEnv = mockedEnv({
LAYERCI: 'true',

LAYERCI_JOB_ID: 'jobId',
LAYERCI_RUNNER_ID: 'runnerId',
RETRY_INDEX: 'retryIndex',

// git info
LAYERCI_PULL_REQUEST: 'pullRequest',
LAYERCI_REPO_NAME: 'repoName',
LAYERCI_REPO_OWNER: 'repoOwner',
LAYERCI_BRANCH: 'branch',
GIT_TAG: 'tag',
GIT_COMMIT: 'commit',
GIT_COMMIT_TITLE: 'commitTitle',
}, { clear: true })

expectsName('layerci')
expectsCiParams({
layerciJobId: 'jobId',
layerciRunnerId: 'runnerId',
retryIndex: 'retryIndex',
gitTag: 'tag',
layerciBranch: 'branch',
layerciPullRequest: 'pullRequest',
layerciRepoName: 'repoName',
layerciRepoOwner: 'repoOwner',
})

return expectsCommitParams({
sha: 'commit',
branch: 'branch',
message: 'commitTitle',
})
})

it('azure', () => {
resetEnv = mockedEnv({
// these two variables tell us it is Azure CI
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38973,12 +38973,7 @@ ws@^6.0.0, ws@^6.1.2, ws@^6.2.1:
dependencies:
async-limiter "~1.0.0"

ws@^7.2.0, ws@^7.2.3, ws@~7.4.2:
version "7.4.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.3.tgz#1f9643de34a543b8edb124bdcbc457ae55a6e5cd"
integrity sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA==

ws@^7.4.1:
ws@^7.2.0, ws@^7.2.3, ws@^7.4.1, ws@~7.4.2:
version "7.4.4"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.4.tgz#383bc9742cb202292c9077ceab6f6047b17f2d59"
integrity sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw==
Expand Down