Skip to content

Commit

Permalink
feat: pass the working directory with build command to the install job (
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jan 20, 2021
1 parent 9c23d2d commit 8f60e51
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ Because we need to see the effective config for a few basic orb uses, please ins
npm run manual:tests
```

If you want to run a single test file

```shell
npx ava-ts manual-tests/<filename>.ts
```

Any changes that modify the effective configs will probably not match previously saved snapshots.

### Production
Expand Down
26 changes: 25 additions & 1 deletion manual-tests/install-job.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava'
import { stripIndent } from 'common-tags'
import { effectiveConfig } from '../scripts/utils'
import { effectiveConfig, extractBuildStep } from '../scripts/utils'

test('install job', async (t) => {
const workflows = stripIndent`
Expand Down Expand Up @@ -53,3 +53,27 @@ test('use custom verify command', async (t) => {
const result = await effectiveConfig(workflows)
t.snapshot(result, 'using custom verify command')
})

test('install with build command uses working directory', async (t) => {
const workflows = stripIndent`
workflows:
build:
jobs:
- cypress/install:
working_directory: examples/subfolder
build: npm run build
`
t.is(typeof workflows, 'string')
const yml = await effectiveConfig(workflows)

const buildStep = extractBuildStep(yml, 'cypress/install')
t.deepEqual(
buildStep,
{
name: 'Build',
command: 'npm run build',
working_directory: 'examples/subfolder',
},
'build step has the working directory',
)
})
22 changes: 22 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export const effectiveConfig = (workflows: string): Promise<any> => {
export const removeNewLines = (runCommand: string) =>
runCommand.replace(/\\\n/g, '').replace(/\s+/g, ' ').trim()

/**
* Given Circle YML text finds the Cypress run command object.
*/
export const extractCypressRun = (circleText: string) => {
const parsed = yaml.safeLoad(circleText)
debug('parsed %o', parsed)
Expand All @@ -159,3 +162,22 @@ export const extractCypressRun = (circleText: string) => {

return runTestsStep.run
}

/**
* Given Circle YML text finds the build command object.
*/
export const extractBuildStep = (
circleText: string,
jobName: string = 'cypress/run',
) => {
const parsed = yaml.safeLoad(circleText)
debug('parsed %o', parsed)

const isBuildStep = (step) => step.run && step.run.name === 'Build'
const found = find(isBuildStep)(parsed.jobs[jobName].steps)
debug('found build step %o', found)

found.run.command = removeNewLines(found.run.command)

return found.run
}
28 changes: 15 additions & 13 deletions src/orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ commands:
type: steps
default: []
build:
description: Optional build command(s)
type: steps
default: []
description: Optional build command
type: string
default: ''
install-command:
description: Overrides the default NPM or Yarn command
type: string
Expand Down Expand Up @@ -265,7 +265,13 @@ commands:
paths:
- ~/.npm
- ~/.cache
- steps: << parameters.build >>
- when:
condition: << parameters.build >>
steps:
- run:
name: 'Build'
command: << parameters.build >>
working_directory: << parameters.working_directory >>

write_workspace:
steps:
Expand All @@ -291,9 +297,9 @@ commands:
type: steps
default: []
build:
type: steps
default: []
description: Custom build commands to run after install
type: string
default: ''
description: Custom build command to run after install
yarn:
description: Use yarn instead of npm
type: boolean
Expand Down Expand Up @@ -593,8 +599,7 @@ jobs:
post-install: << parameters.post-install >>
cache-key: << parameters.cache-key >>
no-workspace: << parameters.no-workspace >>
build:
- run: << parameters.build >>
build: << parameters.build >>
working_directory: << parameters.working_directory >>
- unless:
condition: <<parameters.build>>
Expand Down Expand Up @@ -769,10 +774,7 @@ jobs:
verify-command: << parameters.verify-command >>
yarn: << parameters.yarn >>
post-install: << parameters.post-install >>
build:
- run:
name: 'Build'
command: << parameters.build >>
build: << parameters.build >>
working_directory: << parameters.working_directory >>
cache-key: << parameters.cache-key >>
- unless:
Expand Down

0 comments on commit 8f60e51

Please sign in to comment.