Convert systems.csv to JSON #2
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/[email protected] | |
| 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/[email protected] | |
| - 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/[email protected] | |
| 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 json | |
| # Read the CSV | |
| df = pd.read_csv("systems.csv") | |
| # Convert to list of dicts | |
| data = df.to_dict(orient="records") | |
| # Wrap in "systems" | |
| wrapped = {"systems": data} | |
| # Write to systems.json | |
| with open("systems.json", "w", encoding="utf-8") as f: | |
| json.dump(wrapped, f, indent=2, ensure_ascii=False) | |
| EOF | |
| - name: Commit & Create Pull Request | |
| id: createpr | |
| uses: peter-evans/[email protected] | |
| 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.' |