Skip to content

Commit 6f8dbad

Browse files
committed
fix: improve daily check workflow to handle Git errors
1 parent 01d7d32 commit 6f8dbad

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

.github/workflows/daily-check.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
- cron: "0 0 * * *" # Run daily at midnight UTC
66
workflow_dispatch: # Allow manual triggering
77

8+
permissions:
9+
contents: write # This gives the workflow permission to push to the repository
10+
811
jobs:
912
check-packages:
1013
runs-on: ubuntu-latest
@@ -14,6 +17,16 @@ jobs:
1417
uses: actions/checkout@v3
1518
with:
1619
fetch-depth: 0 # Fetch all history for proper commit messages
20+
token: ${{ secrets.GH_PAT }} # Use PAT for checkout to ensure push access
21+
22+
- name: Debug Git setup
23+
run: |
24+
echo "Current user: $(git config user.name)"
25+
echo "Current email: $(git config user.email)"
26+
echo "Remote URL: $(git remote -v)"
27+
echo "Current branch: $(git branch --show-current)"
28+
echo "GitHub Actor: ${{ github.actor }}"
29+
echo "GitHub Repository: ${{ github.repository }}"
1730
1831
- name: Set up Python
1932
uses: actions/setup-python@v4

scripts/daily_check.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ def compare_metadata(registry_package: Dict[str, Any], sop_data: Dict[str, Any])
8484
return True
8585

8686

87+
def run_git_command(command, error_message=None):
88+
"""Run a git command and handle errors gracefully."""
89+
try:
90+
result = subprocess.run(command, check=True,
91+
capture_output=True, text=True)
92+
return result.stdout.strip()
93+
except subprocess.CalledProcessError as e:
94+
msg = error_message or f"Git command failed: {' '.join(command)}"
95+
print(f"❌ {msg}")
96+
print(f"Error details: {e}")
97+
print(f"Command output: {e.stdout}")
98+
print(f"Command error: {e.stderr}")
99+
return None
100+
101+
87102
def main():
88103
"""Main function to check all packages in registry.json."""
89104
registry_path = "registry.json"
@@ -155,26 +170,41 @@ def main():
155170
sys.exit(1)
156171

157172
# Configure Git
158-
subprocess.run(["git", "config", "user.name", "sharafdin"], check=True)
159-
subprocess.run(["git", "config", "user.email",
160-
"isasharafdin@gmail.com"], check=True)
173+
run_git_command(["git", "config", "user.name", "sharafdin"],
174+
"Failed to configure Git username")
175+
run_git_command(["git", "config", "user.email", "isasharafdin@gmail.com"],
176+
"Failed to configure Git email")
161177

162178
# Use the repository URL from the GitHub environment if available
163179
repo_url = os.getenv("GITHUB_REPOSITORY", "soplang/registry")
164-
subprocess.run(["git", "remote", "set-url", "origin",
165-
f"https://x-access-token:{pat}@github.com/{repo_url}.git"], check=True)
180+
remote_url = f"https://x-access-token:{pat}@github.com/{repo_url}.git"
181+
run_git_command(["git", "remote", "set-url", "origin", remote_url],
182+
"Failed to set Git remote URL")
166183

167184
# Add, commit, and push changes
168-
subprocess.run(["git", "add", registry_path], check=True)
169-
subprocess.run(
170-
["git", "commit", "-m", "chore: update 'valid' status for packages"], check=True)
185+
if not run_git_command(["git", "add", registry_path],
186+
"Failed to stage changes"):
187+
sys.exit(1)
171188

172-
# Get current branch and push
173-
branch_name = subprocess.check_output(
174-
["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip().decode()
175-
subprocess.run(["git", "push", "origin", branch_name], check=True)
189+
if not run_git_command(["git", "commit", "-m", "chore: update 'valid' status for packages"],
190+
"Failed to commit changes"):
191+
sys.exit(1)
176192

177-
print("✅ Successfully updated and committed package validity status")
193+
# Get current branch
194+
branch_name = run_git_command(["git", "rev-parse", "--abbrev-ref", "HEAD"],
195+
"Failed to determine current branch")
196+
if not branch_name:
197+
branch_name = "main" # Default to main if we can't determine the branch
198+
199+
# Try to push changes
200+
print(f"Pushing changes to {branch_name} branch...")
201+
if run_git_command(["git", "push", "origin", branch_name],
202+
f"Failed to push changes to {branch_name}"):
203+
print("✅ Successfully updated and committed package validity status")
204+
else:
205+
print(
206+
"⚠️ Changes were made locally but could not be pushed to the repository")
207+
sys.exit(1)
178208
else:
179209
print("✅ No changes to package validity status")
180210

0 commit comments

Comments
 (0)