Skip to content

Group prefix/suffix #529

Open
@romulof

Description

@romulof

Use-case

I'm trying to output a line before and after each command, to use Github Actions log grouping.

Concurrently's group option helps a lot, but it lacks an API to print stuff before and after.

Problem

There is no API to print stuff before and after commands.

In my use-case I only need 1 process, so I hacked my way around the start of the commands and when they are closed:

import { endGroup, startGroup } from '@actions/core';
import { GITHUB_ACTIONS } from 'ci-info';
import { concurrently } from 'concurrently';

// ...

const result = concurrently(commands, {
  raw: true,
  group: true,
  maxProcesses,
});

if (GITHUB_ACTIONS && maxProcesses === '1') {
  result.commands.forEach((command) => {
    if (command.state === 'started') {
      // Commands immediately started after calling concurrently()
      startGroup(command.name);
    } else {
      // Commands started later
      const originalStart = command.start.bind(command);
      command.start = () => {
        // Start is called before previous command close is called, so we need
        // to defer the start of the group until the close event is received.
        setTimeout(() => {
          startGroup(command.name);
        }, 0);
  
        return originalStart();
      };
    }
    command.close.subscribe(() => {
      endGroup();
    });
  });
}

Proposal

Extend group definition to allow prefix and suffixes:

import { endGroup, startGroup } from '@actions/core';
import { GITHUB_ACTIONS } from 'ci-info';
import { concurrently } from 'concurrently';

//...

concurrently(commands, {
  raw: true,
  group: {
    prefix: '::group::{name}',
    suffix: '::endgroup::',
  },
  maxProcesses,
});

Would also be nice to have an API to be informed when commands have started.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions