summaryrefslogtreecommitdiff
path: root/.gitlab
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-01-05 14:16:56 -0500
committerBen Gamari <ben@well-typed.com>2019-01-07 10:20:14 -0500
commitc0448c18946e63bf47fc7da51c9bea2ee1b1740e (patch)
tree51938561165d5d46b44c08d14fd4fdf64d4441df /.gitlab
parent9ea8dcea3e5ba96808ef91028e0efde9d31f7272 (diff)
downloadhaskell-c0448c18946e63bf47fc7da51c9bea2ee1b1740e.tar.gz
gitlab-ci: Clone haddock from its upstream repository
This ensures that changes requiring haddock changes can be built under CI.
Diffstat (limited to '.gitlab')
-rwxr-xr-x[-rw-r--r--].gitlab/fix-submodules.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/.gitlab/fix-submodules.py b/.gitlab/fix-submodules.py
index 2ff8e41974..621d692edb 100644..100755
--- a/.gitlab/fix-submodules.py
+++ b/.gitlab/fix-submodules.py
@@ -1,8 +1,54 @@
-#!/usr/bin/python
+#!/usr/bin/env python3
+"""
+Fix submodule upstream URLs. This ensures that CI builds of GHC forks
+clone their submodules from its usual location. Otherwise users would need to
+fork all submodules before their CI builds would succeed.
+"""
+
+from typing import List, Dict
+from pathlib import Path
import re
x = open('.gitmodules').read()
x = re.sub(r"url *= *\.\.", "url = https://gitlab.haskell.org/ghc", x)
open('.gitmodules', 'w').write(x)
+import subprocess
+
+def get_configs(config_file: Path) -> Dict[str, str]:
+ args = ['git', 'config', '-f', config_file.as_posix(), '--list']
+ out = subprocess.check_output(args)
+ configs = {}
+ for line in out.decode('UTF-8').split('\n'):
+ if '=' in line:
+ k,v = line.split('=')
+ configs[k] = v
+
+ return configs
+
+def set_config(config_file: Path, key: str, value: str) -> None:
+ args = ['git', 'config', '-f', config_file.as_posix(), '--replace', key, value]
+ subprocess.check_call(args)
+
+upstreams = {
+ 'utils/haddock': 'https://github.com/haskell/haddock'
+}
+
+modules_config = Path('.gitmodules')
+
+def main():
+ for k,v in get_configs(modules_config).items():
+ match = re.match('submodule\.(.+)\.url', k)
+ if match is not None:
+ submod = match.group(1)
+ if submod in upstreams:
+ url = upstreams[submod]
+ else:
+ url = re.sub('\.\.', 'https://gitlab.haskell.org/ghc', v)
+
+ print('Using {submod} from {url}'.format(submod=submod, url=url))
+ set_config(modules_config, k, url)
+
+if __name__ == '__main__':
+ main()