Skip to content

Commit

Permalink
BLD: Attempt 6 to add a github pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Zabegaev committed Oct 17, 2024
1 parent 290edfc commit 3f70a75
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/update_protocol_docstrings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Update protocol docstrings

# Run this workflow on every push or pull request to the main branch
on:
pull_request:
branches:
- develop

permissions:
contents: write

jobs:
run-python-script:
runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3

# Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12.7'

# Run the Python script
- name: Run Python script
run: python build_tools/protocol_docstrings_script.py

# Configure Git to commit and push the changes
- name: Set up Git user info
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
# Check if there are any changes and commit them
- name: Commit and push changes
run: |
touch test.txt
git add .
git commit -m "Update files via Python script" || echo "No changes to commit"
git push
8 changes: 4 additions & 4 deletions build_tools/protocol_docstrings_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ def update_protocol_docstrings(protocols_path: Path):
)

# Write the updated file
with open(protocols_path, "w", encoding="utf8") as f:
f.write("\n".join(updated_lines))
print(f"Updated docstrings in {protocols_path}.")
if len(autodoc_functions) > 0:
with open(protocols_path, "w", encoding="utf8") as f:
f.write("\n".join(updated_lines))
print(f"Updated docstrings in {protocols_path}.")


if __name__ == "__main__":
try:
protocols_path = sys.argv[1]
except IndexError:
print(f"Assuming protocols path: {PROTOCOLS_DEFAULT_PATH}.")
protocols_path = PROTOCOLS_DEFAULT_PATH
update_protocol_docstrings(protocols_path)

0 comments on commit 3f70a75

Please sign in to comment.