GitHub Actions - Open/Write to two groups in paralell

Viewed 103

I'm creating a GitHub action, where I have two loops running in parallel, writing to the console.

Example:

async function loop(name) {
  core.startGroup(name);
  for (var i = 0; i < 10; i++) {
    core.info(`[INFO] {${name}}: ${i} { type = log, task = ${name} }`);
    await delay(1000); // delay = promise that wraps setTimeout
  }
  core.endGroup();
}

loop('a');
loop('b');

I expect each loop to write to its respective group

enter image description here

Instead, I see this in the job logs

enter image description here

Which isn't a surprise since loop('b') overrides the group opening.

Is there a way to write output to a specific group, even when running in parallel?

1 Answers

I couldn't reproduce your result using github-script, result here. Maybe it's fixed in that version. Here's the GH action I used:

name: "Checks loop"
on: [push]

jobs:
  check_group_loop:
    runs-on: ubuntu-latest
    steps:
      - name: Use Node.js
        uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
              function loop(name) {
                  core.startGroup(name);
                  for (var i = 0; i < 10; i++) {
                      core.info("[INFO] " + name + ": " + i );
                 }
                 core.endGroup();
              }

              loop('a');
              loop('b');

Maybe you can show the whole action so that we can check? Anyway, the problem seems to be the calls are asynchronous, so instead of using start/end, could you wrap loggging in a group

Related