Skip to content
New issue

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

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

Already on GitHub? # to your account

add manual GH Action matrix smoke test and silent mode for init #63

Merged
merged 5 commits into from
May 9, 2024
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
5 changes: 5 additions & 0 deletions .changeset/pink-tables-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"dmno": patch
---

add --silent option to init
66 changes: 66 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Run tests
# this workflow is manually triggered
# TODO add inputs for node version and package manager
on: workflow_dispatch


jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
package-manager: ['npm', 'pnpm', 'yarn']

steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: create test dir dmno-${{ matrix.package-manager }}
run: mkdir dmno-${{ matrix.package-manager }} && cd dmno-${{ matrix.package-manager }}

- name: Install package manager ${{ matrix.package-manager }}
run: |
if [ "${{ matrix.package-manager }}" = "npm" ]; then
npm -v
elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then
npm install -g pnpm && pnpm -v
elif [ "${{ matrix.package-manager }}" = "yarn" ]; then
npm install --global yarn && yarn -v
fi

- name: Init package.json ${{ matrix.package-manager }}
run: |
if [ "${{ matrix.package-manager }}" = "npm" ]; then
npm init -y
elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then
pnpm init
elif [ "${{ matrix.package-manager }}" = "yarn" ]; then
yarn init -y
fi

- name: Install dmno ${{ matrix.package-manager }}
run: |
if [ "${{ matrix.package-manager }}" = "npm" ]; then
npm add dmno
elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then
pnpm add dmno
elif [ "${{ matrix.package-manager }}" = "yarn" ]; then
yarn add dmno
fi

- name: Init dmno ${{ matrix.package-manager }}
run: |
if [ "${{ matrix.package-manager }}" = "npm" ]; then
npm exec -- dmno init --silent
elif [ "${{ matrix.package-manager }}" = "pnpm" ]; then
pnpm exec dmno init --silent
elif [ "${{ matrix.package-manager }}" = "yarn" ]; then
yarn exec dmno init --silent
fi

- name: Verify .dmno/ dir exists ${{ matrix.package-manager }}
run: ls -la .dmno/

8 changes: 5 additions & 3 deletions packages/core/src/cli/commands/init.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ const TERMINAL_COLS = process.stdout.columns - 10 || 100;
const program = new DmnoCommand('init')
.summary('Sets up dmno')
.description('Sets up dmno in your repo, and can help add to new packages within your monorepo - safe to run multiple times')
.option('--silent', 'automatically select defaults and do not prompt for any input')
.example('dmno init', 'Set up dmno and uses interactive menus to make selections');

program.action(async (opts: {
silent?: boolean,
}, thisCommand) => {
console.log(DMNO_DEV_BANNER);
// console.log(kleur.gray('let us help you connect the dots ● ● ●'));
Expand Down Expand Up @@ -67,7 +69,7 @@ program.action(async (opts: {
}
const rootDmnoFolderExists = await pathExists(`${rootPackage.path}/.dmno`);
// we may change this logic later?
const showOnboarding = workspaceInfo.autoSelectedPackage.isRoot && !rootDmnoFolderExists;
const showOnboarding = (workspaceInfo.autoSelectedPackage.isRoot && !rootDmnoFolderExists) || !opts.silent;

// if in a specific service, we'll just init that service
if (!workspaceInfo.autoSelectedPackage.isRoot) {
Expand All @@ -89,9 +91,9 @@ program.action(async (opts: {
}

// first initialize in root
await initDmnoForService(workspaceInfo, rootPackage.path);
await initDmnoForService(workspaceInfo, rootPackage.path, opts.silent);

if (workspaceInfo.isMonorepo) {
if (workspaceInfo.isMonorepo && !opts.silent) {
if (workspaceInfo.workspacePackages.length === 1) {
console.log('No packages found in your monorepo.');
console.log('After you create them, you can rerun this command `dmno init`');
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/cli/lib/init-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const KNOWN_INTEGRATIONS_MAP = Object.freeze({
koa: 'dmno',
});

export async function initDmnoForService(workspaceInfo: ScannedWorkspaceInfo, servicePath: string) {
export async function initDmnoForService(workspaceInfo: ScannedWorkspaceInfo, servicePath: string, silent?: boolean) {
const rootPath = workspaceInfo.workspacePackages[0].path;
const { packageManager } = workspaceInfo;

Expand Down Expand Up @@ -191,7 +191,7 @@ export async function initDmnoForService(workspaceInfo: ScannedWorkspaceInfo, se
} else {
const recommendedName = service.isRoot ? 'root' : service.name.replace(/^@[^/]+\//, '');

let serviceName: string | undefined;
let serviceName: string | undefined = silent ? recommendedName : undefined;
while (serviceName === undefined) {
// TODO: better cli input with more options for dynamic help info
serviceName = await input({
Expand Down