Skip to content

Commit 66047c2

Browse files
committed
fix: make a json dict for the GitHub outputs
GitHub supports dynamic outputs only if the action use "using: node". This does not work for "using: composite" or "docker" action. The workaround is to dump the json into the output. Then the GitHub workflow will be able to use fromJSON to read it: ``` if: fromJSON(steps.action.outputs.scopes).everything ``` Change-Id: I294c5f828801ad06a6ed613a127ed1b9315e40aa
1 parent a0ecd36 commit 66047c2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

mergify_cli/ci/scopes/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import os
45
import pathlib
56
import typing
@@ -17,6 +18,8 @@
1718
if typing.TYPE_CHECKING:
1819
from collections import abc
1920

21+
GITHUB_ACTIONS_OUTPUT_NAME = "scopes"
22+
2023

2124
def match_scopes(
2225
files: abc.Iterable[str],
@@ -57,9 +60,8 @@ def maybe_write_github_outputs(
5760
if not gha:
5861
return
5962
with pathlib.Path(gha).open("a", encoding="utf-8") as fh:
60-
for key in sorted(all_scopes):
61-
val = "true" if key in scopes_hit else "false"
62-
fh.write(f"{key}={val}\n")
63+
data = {key: key in scopes_hit for key in sorted(all_scopes)}
64+
fh.write(f"{GITHUB_ACTIONS_OUTPUT_NAME}={json.dumps(data)}")
6365

6466

6567
class InvalidDetectedScopeError(exceptions.ScopesError):

mergify_cli/tests/ci/scopes/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,7 @@ def test_maybe_write_github_outputs(
289289
cli.maybe_write_github_outputs(all_scopes, scopes_hit)
290290

291291
content = output_file.read_text()
292-
assert "backend=true\n" in content
293-
assert "docs=true\n" in content
294-
assert "frontend=false\n" in content
292+
assert content == """scopes={"backend": true, "docs": true, "frontend": false}"""
295293

296294

297295
def test_maybe_write_github_outputs_no_env(

0 commit comments

Comments
 (0)