From 7d3270953b6e0d30e32fddb2f626f90db378938e Mon Sep 17 00:00:00 2001
From: Christopher Rhodes <christopher.rhodes@embl.de>
Date: Tue, 1 Oct 2024 15:26:07 +0200
Subject: [PATCH] Automate registration of conda build artifacts to GitLab

---
 .gitignore              |  1 +
 conda-recipe/publish.py | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 conda-recipe/publish.py

diff --git a/.gitignore b/.gitignore
index ea4b5423..08aaa8ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,5 +5,6 @@
 
 # build and conda-build artifacts
 build/*
+conda-bld/*
 dist/*
 *.egg-info/*
\ No newline at end of file
diff --git a/conda-recipe/publish.py b/conda-recipe/publish.py
new file mode 100644
index 00000000..5bc52442
--- /dev/null
+++ b/conda-recipe/publish.py
@@ -0,0 +1,39 @@
+"""
+Automate registration of conda build artifacts to EMBL GitLab;
+assumes API access token is recorded in ~/.pypirc shell configuration file
+"""
+from configparser import ConfigParser
+import json
+from pathlib import Path
+import requests
+
+id = '5668'
+proj = 'model_server'
+root = Path('../conda-bld/')
+
+# get authentication info from local config file
+cfg = ConfigParser()
+cfg.read(Path.home() / '.pypirc')
+user = cfg['gitlab-model-server']['username']
+pwd = cfg['gitlab-model-server']['password']
+
+with open(root / 'channeldata.json', 'r') as fh:
+    chdata = json.load(fh)
+
+# upload to GitLab API
+res = []
+for sd in ['noarch', 'win-64']:
+    with open(root / sd / 'repodata.json', 'r') as fh:
+        dd = json.load(fh)
+    for fn in dd['packages'].keys():
+        ver = dd['packages'][fn]['version']
+        stem = fn.split('.tar.bz2')[0]
+        pkgname = f'conda_{sd}_{stem}'
+        res.append(
+            requests.put(
+                f'https://git.embl.de/api/v4/projects/{id}/packages/generic/{pkgname}/{ver}/{fn}?status=default',
+                headers={'PRIVATE-TOKEN': pwd},
+            )
+        )
+print('Finished')
+print(res)
\ No newline at end of file
-- 
GitLab