Skip to content

Commit

Permalink
Merge pull request #79 from alchem0x2A/master
Browse files Browse the repository at this point in the history
  • Loading branch information
alchem0x2A authored Nov 24, 2024
2 parents a858396 + 59e23be commit 245d20e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/api_version_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def compare_versions():

if version.parse(default_version) < version.parse(new_version):
print(f"Version changed from {default_version} to {new_version}")
sys.exit(1) # Exit with a non-zero status to indicate change
sys.exit(1)
else:
print("No version change")
sys.exit(0) # Exit with zero status to indicate no change
sys.exit(0)


if __name__ == "__main__":
Expand Down
29 changes: 23 additions & 6 deletions .github/workflows/update_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.10"
python-version: "3.11"
mamba-version: "*"
channels: conda-forge,alchem0x2a,defaults
channel-priority: true
Expand All @@ -39,23 +39,40 @@ jobs:
- name: Test if json api is newer than current
id: probe
run: |
# exit 0 --> no version change
if python .github/workflows/api_version_probe.py; then
echo "UPDATE_NEEDED=false" >> $GITHUB_ENV
else
echo "UPDATE_NEEDED=true" >> $GITHUB_ENV
fi
echo UPDATE_NEEDED is "${UPDATE_NEEDED}"
echo API version is "${API_VERSION}"
continue-on-error: true
- name: Create Pull Request
if: env.UPDATE_NEEDED == true
if: env.UPDATE_NEEDED == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Action Bot"
echo "New version is ${API_VERSION}"
git checkout -b api_version
BRANCH_NAME="update-api-${GITHUB_RUN_ID}"
echo "Checking new branch ${BRANCH_NAME}"
git checkout -b $BRANCH_NAME
mv parameters.json sparc/sparc_json_api/
git add sparc/sparc_json_api/parameters.json
git commit -m "Add new json api version ${API_VERSION}"
git push --set-upstream origin api_version
gh pr create --base master --title "[PR Bot] New JSON API version ${API_VERSION}" --body "Merge new JSON API version ${API_VERSION} into master" -R ${{ github.repository_owner }}/SPARC-X-API
git push --force --set-upstream origin ${BRANCH_NAME}
body_msg=""
body_msg="${body_msg}## Automated JSON API Update\n"
body_msg="${body_msg}Hello! This is an automatic pull request to merge the new JSON API version **${API_VERSION}** into the master branch.\n\n"
body_msg="${body_msg}### Details:\n"
body_msg="${body_msg}- **Workflow Trigger**: This update is triggered by the **Update JSON API (recurring job)** workflow.\n"
body_msg="${body_msg}- **Reason for Update**: A new JSON schema version was generated that differs from the existing one in the repository.\n\n"
body_msg="${body_msg}### Notes:\n"
body_msg="${body_msg}- If you notice any issues or have questions regarding this update, please contact @alchem0x2a or other maintainers of the repository.\n\n"
body_msg="${body_msg}Thank you for keeping the SPARC-X-API project up-to-date! 🚀\n"
gh pr create --base master \
--title "[PR Bot] New JSON API version ${API_VERSION}" \
--body "${body_msg}" \
-R ${{ github.repository_owner }}/SPARC-X-API
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 13 additions & 1 deletion sparc/docparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,23 @@ def json_from_directory(cls, directory=".", include_subdirs=True, **kwargs):
try:
sub_dict = cls(directory=subdir, parse_version=False).to_dict()
except FileNotFoundError:
print(subdir, " Latex files not found. Check naming conventions for Manual.tex. Expects format *Manual.tex")
print(
subdir,
" Latex files not found. Check naming conventions for Manual.tex. Expects format *Manual.tex",
)
continue
for param, param_desc in sub_dict["parameters"].items():
if param not in root_dict["parameters"]:
root_dict["parameters"][param] = param_desc
# Combine the subdir categories
for sub_category in sub_dict["categories"]:
if sub_category not in root_dict["categories"]:
root_dict["categories"].append(sub_category)
# Combine data types
for sub_dt in sub_dict["data_types"]:
if sub_dt not in root_dict["data_types"]:
root_dict["data_types"].append(sub_dt)

json_string = json.dumps(root_dict, indent=True)
return json_string

Expand Down

0 comments on commit 245d20e

Please sign in to comment.