Update systems.csv #5
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
| name: Convert systems.csv to JSON | |
| on: | |
| workflow_dispatch: | |
| push: | |
| paths: | |
| - systems.csv | |
| jobs: | |
| convert: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Setup global variables | |
| id: global_vars | |
| run: | | |
| echo "TODAYS_DAY=$(date '+%d')" >> $GITHUB_ENV # Ex.: 27 | |
| echo "TODAYS_MONTH=$(date '+%m')" >> $GITHUB_ENV # Ex.: 07 | |
| echo "TODAYS_YEAR=$(date '+%Y')" >> $GITHUB_ENV # Ex.: 2023 | |
| - name: Load secrets from 1Password | |
| id: onepw_secrets | |
| uses: 1password/load-secrets-action@v2.0.0 | |
| with: | |
| export-env: true # Export loaded secrets as environment variables | |
| env: | |
| OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | |
| GITHUB_TOKEN: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GitHub generic action token for all repos/credential" | |
| - name: Checkout repo | |
| uses: actions/checkout@v5.0.0 | |
| - name: Create branch name | |
| id: create_branch_name | |
| run: | | |
| echo "BRANCH=feat-update-systems-json-${{ env.TODAYS_YEAR }}-${{ env.TODAYS_MONTH }}-${{ env.TODAYS_DAY }}" >> $GITHUB_OUTPUT | |
| - name: Set up Python | |
| uses: actions/setup-python@v6.0.0 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: pip install pandas | |
| - name: Convert systems.csv to JSON | |
| run: | | |
| python - <<'EOF' | |
| import pandas as pd | |
| import numpy as np | |
| import json | |
| # Read the CSV | |
| df = pd.read_csv("systems.csv") | |
| # Replace NaN (and similar) with None | |
| df = df.replace({np.nan: None}) | |
| # Convert to list of dicts | |
| data = df.to_dict(orient="records") | |
| # Wrap in "systems" | |
| wrapped = {"systems": data} | |
| # Write to systems.json (safe JSON only) | |
| with open("systems.json", "w", encoding="utf-8") as f: | |
| json.dump(wrapped, f, indent=2, ensure_ascii=False, allow_nan=False) | |
| EOF | |
| - name: Commit & Create Pull Request | |
| id: createpr | |
| uses: peter-evans/create-pull-request@v7.0.6 | |
| with: | |
| token: ${{ env.GITHUB_TOKEN }} | |
| sign-commits: true | |
| assignees: "fredericsimard" | |
| branch: ${{ steps.create_branch_name.outputs.BRANCH }} | |
| commit-message: "chore: Update systems.json from systems.csv" | |
| title: 'Update `systems.json` file' | |
| body: 'Update `systems.json` file from the recently updated `systems.csv` file.' |