From 21f0a5a9a8eff06a44a7ad3d0f8050ea29930241 Mon Sep 17 00:00:00 2001 From: sjayellis <43828519+sjayellis@users.noreply.github.com> Date: Mon, 25 Sep 2023 11:37:56 -0400 Subject: [PATCH 1/2] Create generate_json.yml Adding action to generate a json file on push and pull request. --- .github/workflows/generate_json.yml | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/generate_json.yml diff --git a/.github/workflows/generate_json.yml b/.github/workflows/generate_json.yml new file mode 100644 index 0000000..a72effd --- /dev/null +++ b/.github/workflows/generate_json.yml @@ -0,0 +1,52 @@ +# This is a basic workflow to help you get started with Actions + +name: Generate_Json + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "main" branch + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout repo content + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4.7.0 + with: + python-version: 3.11 + + - name: install python packages + run: | + python -m pip install --upgrade pip + pip install PyYAML + + - name: Execute json_generator + run: python json_generator.py + + - name: Commit json file + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add datasets.json + git commit -m "Generating new json file." + + - name: Push changes to json branch + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: json + + From d895474485b6999f69606ab8031ed0ad3567e122 Mon Sep 17 00:00:00 2001 From: test Date: Mon, 25 Sep 2023 11:38:35 -0400 Subject: [PATCH 2/2] Adding script to generate json file based on the yaml files in the repo. --- json_generator.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 json_generator.py diff --git a/json_generator.py b/json_generator.py new file mode 100644 index 0000000..82b4745 --- /dev/null +++ b/json_generator.py @@ -0,0 +1,10 @@ +import yaml, glob, json + +import glob +dataset = {"data": []} +for file in glob.glob("./datasets/*.yaml"): + with open(file, 'r') as yaml_file: + dataset['data'].append(yaml.safe_load(yaml_file)) + +with open('datasets.json', 'w') as file: + file.write(json.dumps(dataset, indent=2)) \ No newline at end of file