diff --git a/package/release.py b/package/release.py index 263b674..44dd32b 100755 --- a/package/release.py +++ b/package/release.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -from typing import Any, Dict, Optional, Tuple +from typing import Any, Dict, List, Optional, Tuple import os import sys @@ -10,6 +10,10 @@ import http.client from urllib.error import HTTPError +encoder = json.encoder.JSONEncoder() +decoder = json.decoder.JSONDecoder() + + def parse_changelog(tag: str) -> Optional[str]: release_changelog: str = '' with open('CHANGELOG.md', 'r') as f: @@ -29,6 +33,28 @@ def parse_changelog(tag: str) -> Optional[str]: return release_changelog +def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str, str]: + url: str = f'https://gitlab.com/api/v4/projects/{project_id}/pipelines/{pipeline_id}/jobs' + headers: Dict[str, str] = { + 'Private-Token': api_token + } + req = urllib.request.Request(url, headers=headers) + try: + resp: http.client.HTTPResponse = urllib.request.urlopen(req) + except HTTPError as e: + print(e.read().decode()) + sys.exit(1) + resp_data: bytes = resp.read() + joblist: List[Dict[str, Any]] = decoder.decode(resp_data.decode()) + + jobidmap: Dict[str, str] = {} + for job in joblist: + name: str = job['name'] + id: str = job['id'] + jobidmap[name] = id + return jobidmap + + def fetch_single_shafile(url: str) -> str: req = urllib.request.Request(url) try: @@ -42,24 +68,27 @@ def fetch_single_shafile(url: str) -> str: return filename -def fetch_wheel_url(base_url: str) -> Optional[Tuple[str, str]]: - wheel_sha_url: str = f'{base_url}/dist/SHA256SUMS?job=build_wheel' +def fetch_wheel_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: + mybase: str = f'{base_url}/jobs/{job_ids["build_wheel"]}/artifacts/raw' + wheel_sha_url: str = f'{mybase}/dist/SHA256SUMS' wheel_filename: str = fetch_single_shafile(wheel_sha_url) - wheel_url: str = f'{base_url}/dist/{wheel_filename}?job=build_wheel' + wheel_url: str = f'{mybase}/dist/{wheel_filename}' return wheel_url, wheel_sha_url -def fetch_debian_url(base_url: str) -> Optional[Tuple[str, str]]: - debian_sha_url: str = f'{base_url}/package/debian/SHA256SUMS?job=build_debian' +def fetch_debian_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: + mybase: str = f'{base_url}/jobs/{job_ids["build_debian"]}/artifacts/raw' + debian_sha_url: str = f'{mybase}/package/debian/SHA256SUMS' debian_filename: str = fetch_single_shafile(debian_sha_url) - debian_url: str = f'{base_url}/package/debian/{debian_filename}?job=build_debian' + debian_url: str = f'{mybase}/package/debian/{debian_filename}' return debian_url, debian_sha_url -def fetch_arch_url(base_url: str) -> Optional[Tuple[str, str]]: - arch_sha_url: str = f'{base_url}/package/archlinux/SHA256SUMS?job=build_archlinux' +def fetch_arch_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: + mybase: str = f'{base_url}/jobs/{job_ids["build_archlinux"]}/artifacts/raw' + arch_sha_url: str = f'{mybase}/package/archlinux/SHA256SUMS' arch_filename: str = fetch_single_shafile(arch_sha_url) - arch_url: str = f'{base_url}/package/archlinux/{arch_filename}?job=build_archlinux' + arch_url: str = f'{mybase}/package/archlinux/{arch_filename}' return arch_url, arch_sha_url @@ -68,6 +97,7 @@ def main(): release_tag: Optional[str] = os.getenv('CI_COMMIT_TAG') project_name: Optional[str] = os.getenv('CI_PROJECT_PATH') project_id: Optional[str] = os.getenv('CI_PROJECT_ID') + pipeline_id: Optional[str] = os.getenv('CI_PIPELINE_ID') if api_token is None: print('GITLAB_API_TOKEN is not set.', file=sys.stderr) sys.exit(1) @@ -80,17 +110,22 @@ def main(): if project_id is None: print('CI_PROJECT_ID is not set.', file=sys.stderr) sys.exit(1) + if pipeline_id is None: + print('CI_PIPELINE_ID is not set.', file=sys.stderr) + sys.exit(1) changelog: Optional[str] = parse_changelog(release_tag) if changelog is None: print('Changelog could not be parsed.', file=sys.stderr) sys.exit(1) - base_url: str = f'https://gitlab.com/{project_name}/-/jobs/artifacts/{release_tag}/raw' + job_ids: Dict[str, str] = fetch_job_ids(project_id, pipeline_id, api_token) - wheel_url, wheel_sha_url = fetch_wheel_url(base_url) - debian_url, debian_sha_url = fetch_wheel_url(base_url) - arch_url, arch_sha_url = fetch_wheel_url(base_url) + base_url: str = f'https://gitlab.com/{project_name}/-' + + wheel_url, wheel_sha_url = fetch_wheel_url(base_url, job_ids) + debian_url, debian_sha_url = fetch_wheel_url(base_url, job_ids) + arch_url, arch_sha_url = fetch_wheel_url(base_url, job_ids) augmented_changelog = f'''{changelog.strip()} @@ -101,8 +136,6 @@ def main(): - [Arch Linux Package]({arch_url}) ([sha256]({arch_sha_url})) - Docker image: registry.gitlab.com/{project_name}:{release_tag}''' - encoder = json.encoder.JSONEncoder() - decoder = json.decoder.JSONDecoder() post_body: str = encoder.encode({'description': augmented_changelog}) gitlab_release_api_url: str = \ diff --git a/touchkey.html b/touchkey.html deleted file mode 100644 index 5d5b427..0000000 --- a/touchkey.html +++ /dev/null @@ -1,147 +0,0 @@ - - -
- - - - -