Skip to content

add script to check whether JSON data for available software has been updated (ignoring timestamp) #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/workflows/update_available_software.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ jobs:
- name: update overview of available software
id: update_available_software
run: |
cd scripts/available_software

# install required Python packages in virtual environment
python -m venv venv
. venv/bin/activate
pip install -r requirements.txt

python available_software.py
# copy current JSON data, so we can compare after updating it
cp docs/available_software/data/json_data.json docs/available_software/data/json_data.json.orig
cp docs/available_software/data/json_data_detail.json docs/available_software/data/json_data_detail.json.orig

python scripts/available_software/available_software.py
git status

# determine whether pull request should be opened:
# if JSON files in docs/available_software/data have been updated, then a PR should be opened
json_data_changed=$((git diff --exit-code ../../docs/available_software/data > /dev/null && echo 'no') || echo 'yes')
if [[ ${json_data_changed} == "yes" ]]; then
echo "JSON files in docs/available_software/data have been changed, PR should be opened"
else
json_data_changed=$(python scripts/available_software/check_json_updates.py docs/available_software/data/json_data.json.orig docs/available_software/data/json_data.json)
json_data_detail_changed=$(python scripts/available_software/check_json_updates.py docs/available_software/data/json_data_detail.json.orig docs/available_software/data/json_data_detail.json)
if [[ ${json_data_changed} == "no changes" ]] && [[ ${json_data_detail_changed} == "no changes" ]]; then
echo "JSON files in docs/available_software/data have not been changed, no need to open PR"
echo "json_data_changed=no" >> $GITHUB_OUTPUT
else
echo "JSON files in docs/available_software/data have been changed, PR should be opened"
echo "json_data_changed=yes" >> $GITHUB_OUTPUT
fi
echo "json_data_changed=${json_data_changed}" >> $GITHUB_OUTPUT

- name: create pull request
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5
Expand Down
1 change: 1 addition & 0 deletions scripts/available_software/available_software.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
#
# Copyright 2023-2023 Ghent University
#
Expand Down
34 changes: 34 additions & 0 deletions scripts/available_software/check_json_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
#
# Copyright 2023-2023 Ghent University
#
# SPDX license identifier: GPL-3.0-or-later
#
"""
Python script to check for differences between provided JSON files
that contain data on available software.

@author: Kenneth Hoste (Ghent University)
"""
import json
import sys

if len(sys.argv) != 3:
sys.stderr.write(f"Usage: {sys.argv[0]} <one.json> <two.json>\n")
sys.exit(1)

json1_path = sys.argv[1]
json2_path = sys.argv[2]

with open(json1_path) as json1:
json1_data = json.load(json1)
with open(json2_path) as json2:
json2_data = json.load(json2)

json1_data_filtered = {k: v for (k, v) in json1_data.items() if k != 'time_generated'}
json2_data_filtered = {k: v for (k, v) in json2_data.items() if k != 'time_generated'}

if json1_data_filtered == json2_data_filtered:
print("no changes")
else:
print("differences found")
Loading