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 + + 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