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

Group prefix/suffix #529

Open
romulof opened this issue Feb 14, 2025 · 0 comments
Open

Group prefix/suffix #529

romulof opened this issue Feb 14, 2025 · 0 comments

Comments

@romulof
Copy link

romulof commented Feb 14, 2025

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.

@romulof romulof changed the title Be able to listen to start events Group prefix/suffix Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant