Created
February 2, 2023 12:05
-
-
Save atemate/1dc792814d01d368cef473141c1d596d to your computer and use it in GitHub Desktop.
Helper script for GitHub Actions to construct json from individual values (to be used by matrix and fromJson)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# $ export KEY=kek OTHER_KEYS="aa bb" OTHER_VALS="AA BB" | |
# $ echo "12 34" | python .github/workflows/helpers/construct_json_list_of_values.py | |
# [{"kek": "12", "aa": "AA", "bb": "BB"}, {"kek": "34", "aa": "AA", "bb": "BB"}] | |
import json | |
import os | |
import sys | |
KEY = os.environ["KEY"] | |
OTHER_KEYS = os.environ["OTHER_KEYS"].strip().split() | |
OTHER_VALS = os.environ["OTHER_VALS"].strip().split() | |
values = sys.stdin.read().strip().split() | |
others = {k: v for k, v in zip(OTHER_KEYS, OTHER_VALS)} | |
out_list = [{**others, KEY: v} for v in values] | |
print(json.dumps(out_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment