|
32 | 32 | async def update_repo(repo: Path, delivery: str, name: str): |
33 | 33 | """Update a git repo at the given path.""" |
34 | 34 | log.info('%s: Running git pull for %s at %s', delivery, name, repo) |
35 | | - proc = await asyncio.create_subprocess_exec('git', 'pull', cwd=repo) |
| 35 | + |
| 36 | + proc = await asyncio.create_subprocess_exec('git', 'fetch', cwd=repo) |
| 37 | + await proc.wait() |
| 38 | + if proc.returncode != 0: |
| 39 | + log.error('%s: Running git fetch for %s at %s failed: %d', |
| 40 | + delivery, name, repo, proc.returncode) |
| 41 | + return False |
| 42 | + |
| 43 | + # Updates must be done this way because we force push away previous |
| 44 | + # gh-pages commits to keep the repository from ballooning in size. |
| 45 | + proc = await asyncio.create_subprocess_exec( |
| 46 | + 'git', 'reset', '--hard', '@{upstream}', cwd=repo) |
36 | 47 | await proc.wait() |
37 | 48 | if proc.returncode != 0: |
38 | | - log.error('%s: Running git pull for %s at %s failed: %d', |
| 49 | + log.error('%s: Running git reset for %s at %s failed: %d', |
39 | 50 | delivery, name, repo, proc.returncode) |
| 51 | + return False |
| 52 | + |
| 53 | + return True |
40 | 54 |
|
41 | 55 |
|
42 | 56 | def handle_update_repo_result(task: asyncio.Task): |
@@ -134,10 +148,12 @@ async def github_webhook(request: web.Request): |
134 | 148 | log.info('%s: Ignoring webhook for unused event %s', delivery, event) |
135 | 149 | return web.Response(status=200) |
136 | 150 |
|
| 151 | + expected_branch = ('main' if repository == 'matplotlib.github.com' |
| 152 | + else 'gh-pages') |
137 | 153 | ref = data.get('ref', '') |
138 | | - if ref != 'refs/heads/gh-pages': |
139 | | - log.info('%s: Ignoring push event on branch %s other than gh-pages', |
140 | | - delivery, ref) |
| 154 | + if ref != f'refs/heads/{expected_branch}': |
| 155 | + log.info('%s: Ignoring push event on branch %s other than %s', |
| 156 | + delivery, ref, expected_branch) |
141 | 157 | return web.Response(status=200) |
142 | 158 |
|
143 | 159 | checkout = Path(os.environ.get('SITE_DIR', 'sites'), repository) |
|
0 commit comments