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: add simple multibranch #147

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
19 changes: 10 additions & 9 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ test('prints help', async () => {
'--help',
'--version',
'--skip-git-check',
'--preset',
'Use any combination of the following with --preset flag to specify your own set of workflows to generate',
'--lint',
'--jest',
'--ts',
'--prettier',
'--eas',
'--detox',
'--maestro',
'-pull-request [...workflows]',
'-main [...workflows]',
'Use any combination of the following with -pull-request and -main flags to specify your own set of workflows to generate',
'lint',
'jest',
'ts',
'prettier',
'eas',
'detox',
'maestro',
]) {
expect(output).toContain(message)
}
Expand Down
14 changes: 7 additions & 7 deletions __tests__/recipes/detox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getPackageJsonWithoutVersions,
installDependencies,
NON_INTERACTIVE_FLAG,
PRESET_FLAG,
PULL_REQUEST_FLAG,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('detox recipe', () => {
TEST_PROJECTS[projectName]

const output = await cli(
[PRESET_FLAG, NON_INTERACTIVE_FLAG, `--${FLAG}`],
[PULL_REQUEST_FLAG, FLAG, NON_INTERACTIVE_FLAG],
{
cwd: appRoot,
}
Expand All @@ -88,12 +88,12 @@ describe('detox recipe', () => {
'https://wix.github.io/Detox/docs/next/introduction/project-setup/#step-4-additional-android-configuration.',
'You can do it now or after the script finishes.',
`Detected ${packageManager} as your package manager.`,
'Generating Detox workflow',
'Configuring project for Detox',
'Created Android release build workflow.',
'Created iOS release build workflow.',
'Consider adding "modulePathIgnorePatterns": ["e2e"] to your jest config.',
'Remember to edit example test in e2e/starter.test.ts to match your app.',
'Created Detox workflow.',
'Created Detox workflow for events: [pull_request]',
'Follow Step 4 of https://wix.github.io/Detox/docs/next/introduction/project-setup/#step-4-additional-android-configuration to patch native code for Detox.',
]) {
expect(output).toContain(message)
Expand All @@ -116,20 +116,20 @@ describe('detox recipe', () => {

installDependencies(appRoot, packageManager)

const output = await cli([PRESET_FLAG, `--${FLAG}`], {
const output = await cli([PULL_REQUEST_FLAG, FLAG], {
cwd: appRoot,
})

for (const message of [
`Detected ${packageManager} as your package manager.`,
'Generating Detox workflow',
'Configuring project for Detox',
'Running Expo prebuild...',
'Finished running Expo prebuild.',
'Created Android release build workflow.',
'Created iOS release build workflow.',
'Consider adding "modulePathIgnorePatterns": ["e2e"] to your jest config.',
'Remember to edit example test in e2e/starter.test.ts to match your app.',
'Created Detox workflow.',
'Created Detox workflow for events: [pull_request]',
]) {
expect(output).toContain(message)
}
Expand Down
8 changes: 4 additions & 4 deletions __tests__/recipes/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path'
import {
cli,
getPackageJsonWithoutVersions,
PRESET_FLAG,
PULL_REQUEST_FLAG,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
Expand All @@ -30,14 +30,14 @@ describe('jest recipe', () => {
const { packageManager, repoRoot, appRoot, workflowNamePrefix } =
TEST_PROJECTS[projectName]

const output = await cli([PRESET_FLAG, `--${FLAG}`], {
const output = await cli([PULL_REQUEST_FLAG, FLAG], {
cwd: appRoot,
})

for (const message of [
`Detected ${packageManager} as your package manager.`,
'Generating Jest workflow',
'Created Jest workflow.',
'Configuring project for Jest',
'Created Jest workflow for events: [pull_request]',
]) {
expect(output).toContain(message)
}
Expand Down
14 changes: 8 additions & 6 deletions __tests__/recipes/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path'
import {
cli,
getPackageJsonWithoutVersions,
PRESET_FLAG,
PULL_REQUEST_FLAG,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
Expand Down Expand Up @@ -37,14 +37,14 @@ describe('lint recipe', () => {
existingConfig,
} = TEST_PROJECTS[projectName]

const output = await cli([PRESET_FLAG, `--${FLAG}`], {
const output = await cli([PULL_REQUEST_FLAG, FLAG], {
cwd: appRoot,
})

for (const message of [
`Detected ${packageManager} as your package manager.`,
'Generating ESLint workflow',
'Created ESLint workflow.',
'Configuring project for ESLint',
'Created ESLint workflow for events: [pull_request]',
]) {
expect(output).toContain(message)
}
Expand Down Expand Up @@ -75,11 +75,13 @@ describe('lint recipe', () => {
setupTestProject('rn-setup-ci-yarn-flat')
const { appRoot } = TEST_PROJECTS['rn-setup-ci-yarn-flat']

const output = await cli([PRESET_FLAG, `--${FLAG}`, `--${PRETTIER_FLAG}`], {
const output = await cli([PULL_REQUEST_FLAG, FLAG, PRETTIER_FLAG], {
cwd: appRoot,
})

expect(output).toContain('Created ESLint workflow.')
expect(output).toContain(
'Created ESLint workflow for events: [pull_request]'
)

const packageJson = await getPackageJsonWithoutVersions(
join(appRoot, 'package.json')
Expand Down
8 changes: 4 additions & 4 deletions __tests__/recipes/prettier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path'
import {
cli,
getPackageJsonWithoutVersions,
PRESET_FLAG,
PULL_REQUEST_FLAG,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
Expand Down Expand Up @@ -35,14 +35,14 @@ describe('prettier check recipe', () => {
existingConfig,
} = TEST_PROJECTS[projectName]

const output = await cli([PRESET_FLAG, `--${FLAG}`], {
const output = await cli([PULL_REQUEST_FLAG, FLAG], {
cwd: appRoot,
})

for (const message of [
`Detected ${packageManager} as your package manager.`,
'Generating Prettier check workflow',
'Created Prettier check workflow.',
'Configuring project for Prettier check',
'Created Prettier check workflow for events: [pull_request]',
]) {
expect(output).toContain(message)
}
Expand Down
8 changes: 4 additions & 4 deletions __tests__/recipes/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path'
import {
cli,
getPackageJsonWithoutVersions,
PRESET_FLAG,
PULL_REQUEST_FLAG,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
Expand All @@ -30,14 +30,14 @@ describe('typescript check recipe', () => {
const { packageManager, repoRoot, appRoot, workflowNamePrefix } =
TEST_PROJECTS[projectName]

const output = await cli([PRESET_FLAG, `--${FLAG}`], {
const output = await cli([PULL_REQUEST_FLAG, FLAG], {
cwd: appRoot,
})

for (const message of [
`Detected ${packageManager} as your package manager.`,
'Generating Typescript check workflow',
'Created Typescript check workflow.',
'Configuring project for Typescript check',
'Created Typescript check workflow for events: [pull_request]',
]) {
expect(output).toContain(message)
}
Expand Down
5 changes: 3 additions & 2 deletions __tests__/runtime-version-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from 'path'
import { readFileSync } from 'fs'
import {
cli,
PULL_REQUEST_FLAG,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
Expand All @@ -17,7 +18,7 @@ describe('should create runtime version files if necessary', () => {
const { appRoot } = TEST_PROJECTS['rn-setup-ci-create-expo-stack']
setupTestProject('rn-setup-ci-create-expo-stack')

const output = await cli(['--skip-git-check', '--preset', '--lint'], {
const output = await cli(['--skip-git-check', PULL_REQUEST_FLAG, 'lint'], {
cwd: appRoot,
})

Expand All @@ -43,7 +44,7 @@ describe('should create runtime version files if necessary', () => {
const { appRoot } = TEST_PROJECTS['rn-setup-ci-create-expo-stack-bun']
setupTestProject('rn-setup-ci-create-expo-stack-bun')

const output = await cli(['--skip-git-check', '--preset', '--lint'], {
const output = await cli(['--skip-git-check', PULL_REQUEST_FLAG, 'lint'], {
cwd: appRoot,
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const PATH_TO_TEST_PROJECTS = join(__dirname, TEST_PROJECTS_FOLDER)
const PATH_TO_TEST_PROJECT = join(__dirname, TEST_PROJECT_NAME)

export const NON_INTERACTIVE_FLAG = '--non-interactive'
export const PRESET_FLAG = '--preset'
export const PULL_REQUEST_FLAG = '-pull-request'

const INSTALL_DEPENDENCIES_COMMAND = {
yarn: 'yarn',
Expand Down
17 changes: 11 additions & 6 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GluegunCommand, GluegunToolbox } from 'gluegun'
import { CycliCommand } from './setup-ci'
import { HELP_FLAG } from '../constants'
import { HELP_FLAG, MAIN_FLAG, PULL_REQUEST_FLAG } from '../constants'

module.exports = {
name: HELP_FLAG,
Expand Down Expand Up @@ -28,30 +28,35 @@ module.exports = {

const maxFlagLength = Math.max(
...[...cycliCommand.options, ...cycliCommand.featureOptions].map(
(op) => op.flag.length + 2
(op) => op.flag.length + 2 + (op.params ? '[...workflows]'.length : 0)
)
)

for (const option of cycliCommand.options) {
toolbox.interactive.info(
' ' +
cyan(`--${option.flag}`.padEnd(maxFlagLength + 2, ' ')) +
cyan(
(option.params
? `-${option.flag} [...workflows]`
: `--${option.flag}`
).padEnd(maxFlagLength + 2, ' ')
) +
'\t' +
option.description
)
}

interactive.vspace()
interactive.info(
'Use any combination of the following with --preset flag to specify your own set of workflows to generate'
`Use any combination of the following with -${PULL_REQUEST_FLAG} and -${MAIN_FLAG} flags to specify your own set of workflows to generate`
)
interactive.vspace()
interactive.info(bold(underline('Feature flags:')))
interactive.info(bold(underline('Available workflows:')))

for (const option of cycliCommand.featureOptions) {
toolbox.interactive.info(
' ' +
cyan(`--${option.flag}`.padEnd(maxFlagLength + 2, ' ')) +
cyan(option.flag.padEnd(maxFlagLength + 2, ' ')) +
'\t' +
option.description
)
Expand Down
Loading
Loading