From 5cf94ab58b27288583c4a1b4513f2c90c383f729 Mon Sep 17 00:00:00 2001 From: chrishalcrow Date: Wed, 29 Oct 2025 17:03:38 +0000 Subject: [PATCH 1/3] add look for json changes action --- .../check_for_changes_in_NP_jsons.yml | 74 +++++++++++++++++++ .github/workflows/check_for_new_probes.yml | 3 - 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/check_for_changes_in_NP_jsons.yml diff --git a/.github/workflows/check_for_changes_in_NP_jsons.yml b/.github/workflows/check_for_changes_in_NP_jsons.yml new file mode 100644 index 0000000..37ff53d --- /dev/null +++ b/.github/workflows/check_for_changes_in_NP_jsons.yml @@ -0,0 +1,74 @@ +name: Check for changes in NP json files + +on: + schedule: + - cron: '0 0 * * 2' # Every Tuesday at 00:00 UTC + workflow_dispatch: + +# Grant permissions for the job to write to contents (push) and create PRs. +permissions: + contents: write + pull-requests: write + +jobs: + build-and-pr: + runs-on: ubuntu-latest + steps: + + - name: Check out local repository + uses: actions/checkout@v4 + + # Set up a Python environment + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + # Clone dev version of probeinterface + - name: Clone external repository + run: | + # --- USER ACTION REQUIRED --- + # Replace this URL with the repository you want to clone. + # If it's a private repo, your GH_PAT must have access. + git clone https://github.com/spikeinterface/probeinterface ./probeinterface + + - name: Install probeinterface and matplotlib + run: pip install ./probeinterface matplotlib + + - name: Generate full NP library + run: | + cd scripts/ + python ../probeinterface/resources/generate_neuropixels_library.py + + # Check for any new probes + - name: Run local script + run: | + rsync -av --include='*/' --include='*.json' --exclude='*' scripts/neuropixels_library_generated/ imec/ + rm -r scripts/neuropixels_library_generated/ + rm -r ./probeinterface + + - name: Commit changes if any + id: commit + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + + git add imec/* + + # Only commit if there are changes + if git diff --staged --quiet; then + echo "No changes to commit" + echo "changes=false" >> $GITHUB_OUTPUT + else + git commit -m "Update json files for NP probes" + echo "changes=true" >> $GITHUB_OUTPUT + fi + + - name: Create pull request to add probes + if: steps.commit.outputs.changes == 'true' + uses: peter-evans/create-pull-request@v7 + with: + title: "Update Neuropixels json files" + body: "This PR updates the Neuropixel probes in probeinterace library, based on new data from the ProbeTable repository or because of a new ProbeInterface release." + branch-suffix: short-commit-hash + base: "main" diff --git a/.github/workflows/check_for_new_probes.yml b/.github/workflows/check_for_new_probes.yml index 47683d8..329ce71 100644 --- a/.github/workflows/check_for_new_probes.yml +++ b/.github/workflows/check_for_new_probes.yml @@ -43,9 +43,6 @@ jobs: # Check for any new probes - name: Run local script run: | - # --- USER ACTION REQUIRED --- - # Replace this path with the correct path to your local script - ls cd scripts/ python check_for_new_NP_probes.py rm -r neuropixels_library_generated/ From a2c919770da4b28293e7108982d773a9730600f0 Mon Sep 17 00:00:00 2001 From: chrishalcrow Date: Wed, 29 Oct 2025 17:06:40 +0000 Subject: [PATCH 2/3] remove unnecessary comments --- .github/workflows/check_for_changes_in_NP_jsons.yml | 3 --- .github/workflows/check_for_new_probes.yml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/check_for_changes_in_NP_jsons.yml b/.github/workflows/check_for_changes_in_NP_jsons.yml index 37ff53d..a640fa2 100644 --- a/.github/workflows/check_for_changes_in_NP_jsons.yml +++ b/.github/workflows/check_for_changes_in_NP_jsons.yml @@ -27,9 +27,6 @@ jobs: # Clone dev version of probeinterface - name: Clone external repository run: | - # --- USER ACTION REQUIRED --- - # Replace this URL with the repository you want to clone. - # If it's a private repo, your GH_PAT must have access. git clone https://github.com/spikeinterface/probeinterface ./probeinterface - name: Install probeinterface and matplotlib diff --git a/.github/workflows/check_for_new_probes.yml b/.github/workflows/check_for_new_probes.yml index 329ce71..77f3440 100644 --- a/.github/workflows/check_for_new_probes.yml +++ b/.github/workflows/check_for_new_probes.yml @@ -27,9 +27,6 @@ jobs: # Clone dev version of probeinterface - name: Clone external repository run: | - # --- USER ACTION REQUIRED --- - # Replace this URL with the repository you want to clone. - # If it's a private repo, your GH_PAT must have access. git clone https://github.com/spikeinterface/probeinterface ./probeinterface - name: Install probeinterface and matplotlib From fa4c7ddfeb681e595e3b8a18c6e479e8d63ddade Mon Sep 17 00:00:00 2001 From: chrishalcrow Date: Tue, 11 Nov 2025 15:05:39 +0000 Subject: [PATCH 3/3] update gh action --- .../check_for_changes_in_NP_jsons.yml | 18 +++++++++--- .../check_for_json_changes_in_NP_probes.py | 28 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 scripts/check_for_json_changes_in_NP_probes.py diff --git a/.github/workflows/check_for_changes_in_NP_jsons.yml b/.github/workflows/check_for_changes_in_NP_jsons.yml index a640fa2..f1777f1 100644 --- a/.github/workflows/check_for_changes_in_NP_jsons.yml +++ b/.github/workflows/check_for_changes_in_NP_jsons.yml @@ -24,13 +24,21 @@ jobs: with: python-version: '3.10' + # we just install probeinterface to get the version number + - name: Install probeinterface and matplotlib + run: | + pip install probeinterface matplotlib + PROBEINTERFACE_VERSION=$(pip show pip | grep Version | awk '{print $2}') + pip uninstall probeinterface + # Clone dev version of probeinterface - name: Clone external repository run: | git clone https://github.com/spikeinterface/probeinterface ./probeinterface + git fetch + git checkout tags/$PROBEINTERFACE_VERSION + pip install ./probeinterface - - name: Install probeinterface and matplotlib - run: pip install ./probeinterface matplotlib - name: Generate full NP library run: | @@ -40,8 +48,10 @@ jobs: # Check for any new probes - name: Run local script run: | - rsync -av --include='*/' --include='*.json' --exclude='*' scripts/neuropixels_library_generated/ imec/ - rm -r scripts/neuropixels_library_generated/ + cd scripts/ + python check_for_json_changes_in_NP_probes.py + rm -r neuropixels_library_generated/ + cd .. rm -r ./probeinterface - name: Commit changes if any diff --git a/scripts/check_for_json_changes_in_NP_probes.py b/scripts/check_for_json_changes_in_NP_probes.py new file mode 100644 index 0000000..a253067 --- /dev/null +++ b/scripts/check_for_json_changes_in_NP_probes.py @@ -0,0 +1,28 @@ +from pathlib import Path +import shutil + +old_dir = Path('../imec') +new_dir = Path('./neuropixels_library_generated') + +new_dir = Path("/Users/christopherhalcrow/Work/fromgit/probeinterface/neuropixels_library_generated") + +for temp_probe_directory in new_dir.iterdir(): + + probe_name = str(temp_probe_directory.name) + + temp_probe_json_path = temp_probe_directory / (probe_name + '.json') + old_probe_json_path = old_dir / probe_name / (probe_name + '.json') + + if old_probe_json_path.is_file(): + with open(temp_probe_json_path, 'r') as f1, open(old_probe_json_path, 'r') as f2: + # Read in json files + lines1 = f1.readlines() + lines2 = f2.readlines() + + # We don't want to update the probes just because of a probeinterface version update. + # The probeinterface version is stored on the 3rd line of the json file, so we only + # compare the json files from line 3 and down. + if lines1[3:] == lines2[3:]: + continue + else: + shutil.copy(f"{temp_probe_json_path}", f"../imec/{probe_name}") \ No newline at end of file