Spaces:
Sleeping
Sleeping
Fixed github pages deployment
Browse files- app/services/github_service.py +29 -63
app/services/github_service.py
CHANGED
|
@@ -45,38 +45,12 @@ class GitHubService:
|
|
| 45 |
# Wait a bit for the repository to be ready
|
| 46 |
import time
|
| 47 |
time.sleep(2)
|
| 48 |
-
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
# Set repo homepage and default branch (default remains main)
|
| 56 |
-
repo.edit(
|
| 57 |
-
homepage=f"https://{self.username}.github.io/{repo_name}/",
|
| 58 |
-
default_branch="main"
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
# Configure Pages source via REST to branch gh-pages
|
| 62 |
-
pages_url = f"https://api.github.com/repos/{self.username}/{repo_name}/pages"
|
| 63 |
-
headers = {
|
| 64 |
-
"Accept": "application/vnd.github.v3+json",
|
| 65 |
-
"Authorization": f"Bearer {self.token}"
|
| 66 |
-
}
|
| 67 |
-
import httpx
|
| 68 |
-
with httpx.Client() as client:
|
| 69 |
-
response = client.post(
|
| 70 |
-
pages_url,
|
| 71 |
-
json={"source": {"branch": "gh-pages", "path": "/"}},
|
| 72 |
-
headers=headers
|
| 73 |
-
)
|
| 74 |
-
if response.status_code not in (201, 204):
|
| 75 |
-
print(f"Warning: Early Pages configuration returned status {response.status_code}: {response.text}")
|
| 76 |
-
else:
|
| 77 |
-
print("Configured GitHub Pages to gh-pages before first content push")
|
| 78 |
-
except Exception as e:
|
| 79 |
-
print(f"Warning: Early Pages setup encountered an error: {e}")
|
| 80 |
|
| 81 |
# Update README with task-specific content
|
| 82 |
readme_content = f"# {task}\n\nGenerated by builder.\n"
|
|
@@ -88,7 +62,7 @@ class GitHubService:
|
|
| 88 |
except Exception:
|
| 89 |
license_content = f"""MIT License
|
| 90 |
|
| 91 |
-
Copyright (c)
|
| 92 |
|
| 93 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 94 |
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -108,38 +82,30 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
| 108 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 109 |
SOFTWARE."""
|
| 110 |
self._safe_create_file(repo, "LICENSE", "chore: add MIT license", license_content)
|
| 111 |
-
|
| 112 |
-
# Add pages workflow
|
| 113 |
-
workflow = """
|
| 114 |
-
name: Deploy Pages
|
| 115 |
-
on:
|
| 116 |
-
push:
|
| 117 |
-
branches: [ main ]
|
| 118 |
-
|
| 119 |
-
permissions:
|
| 120 |
-
contents: write
|
| 121 |
-
pages: write
|
| 122 |
-
id-token: write
|
| 123 |
-
|
| 124 |
-
jobs:
|
| 125 |
-
build-and-deploy:
|
| 126 |
-
runs-on: ubuntu-latest
|
| 127 |
-
steps:
|
| 128 |
-
- uses: actions/checkout@v4
|
| 129 |
-
|
| 130 |
-
# Deploy content to gh-pages branch
|
| 131 |
-
- name: Deploy to GitHub Pages
|
| 132 |
-
uses: JamesIves/github-pages-deploy-action@v4
|
| 133 |
-
with:
|
| 134 |
-
branch: gh-pages
|
| 135 |
-
folder: .
|
| 136 |
-
clean: true
|
| 137 |
-
"""
|
| 138 |
-
repo.create_file(".github/workflows/deploy-pages.yml", "chore: add pages workflow", workflow, branch="main")
|
| 139 |
-
# Add generated files
|
| 140 |
for path, content in files.items():
|
| 141 |
self._safe_create_file(repo, path, f"feat: add {path}", content)
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
return {
|
| 145 |
"repo_url": repo.html_url,
|
|
|
|
| 45 |
# Wait a bit for the repository to be ready
|
| 46 |
import time
|
| 47 |
time.sleep(2)
|
| 48 |
+
# Single-branch mode: we'll serve Pages directly from main
|
| 49 |
+
# Set repo homepage and ensure default branch is main
|
| 50 |
+
repo.edit(
|
| 51 |
+
homepage=f"https://{self.username}.github.io/{repo_name}/",
|
| 52 |
+
default_branch="main"
|
| 53 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Update README with task-specific content
|
| 56 |
readme_content = f"# {task}\n\nGenerated by builder.\n"
|
|
|
|
| 62 |
except Exception:
|
| 63 |
license_content = f"""MIT License
|
| 64 |
|
| 65 |
+
Copyright (c) 2025
|
| 66 |
|
| 67 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 68 |
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
| 82 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 83 |
SOFTWARE."""
|
| 84 |
self._safe_create_file(repo, "LICENSE", "chore: add MIT license", license_content)
|
| 85 |
+
# Add generated files to main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
for path, content in files.items():
|
| 87 |
self._safe_create_file(repo, path, f"feat: add {path}", content)
|
| 88 |
+
|
| 89 |
+
# Configure GitHub Pages to serve from main branch root via REST
|
| 90 |
+
try:
|
| 91 |
+
pages_url = f"https://api.github.com/repos/{self.username}/{repo_name}/pages"
|
| 92 |
+
headers = {
|
| 93 |
+
"Accept": "application/vnd.github.v3+json",
|
| 94 |
+
"Authorization": f"Bearer {self.token}"
|
| 95 |
+
}
|
| 96 |
+
import httpx
|
| 97 |
+
with httpx.Client() as client:
|
| 98 |
+
response = client.post(
|
| 99 |
+
pages_url,
|
| 100 |
+
json={"source": {"branch": "main", "path": "/"}},
|
| 101 |
+
headers=headers
|
| 102 |
+
)
|
| 103 |
+
if response.status_code not in (201, 204):
|
| 104 |
+
print(f"Warning: Pages configuration (main) returned status {response.status_code}: {response.text}")
|
| 105 |
+
else:
|
| 106 |
+
print("Configured GitHub Pages to serve from main branch root")
|
| 107 |
+
except Exception as e:
|
| 108 |
+
print(f"Warning: Pages setup encountered an error: {e}")
|
| 109 |
|
| 110 |
return {
|
| 111 |
"repo_url": repo.html_url,
|