From 396e0e5c5f7afb9f8aa7d6248b25c16fc6903332 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 19 Feb 2022 03:48:26 +0100 Subject: [PATCH] Fix release script --- package/release.py | 56 ++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/package/release.py b/package/release.py index fe19919..4f09ba3 100755 --- a/package/release.py +++ b/package/release.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 from typing import Any, Dict, List, Optional, Tuple @@ -10,9 +9,6 @@ import http.client from urllib.error import HTTPError -USER_AGENT = 'curl/7.70.0' - - def parse_changelog(tag: str) -> Optional[str]: release_changelog: str = '' with open('CHANGELOG.md', 'r') as f: @@ -32,11 +28,11 @@ 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]: +def fetch_job_ids(project_id: str, pipeline_id: str, 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, - 'User-Agent': USER_AGENT + 'User-Agent': 'curl/7.70.0' } req = urllib.request.Request(url, headers=headers) try: @@ -55,9 +51,10 @@ def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str return jobidmap -def fetch_single_shafile(url: str) -> str: +def fetch_single_shafile(url: str, api_token: str) -> str: headers: Dict[str, str] = { - 'User-Agent': USER_AGENT + 'User-Agent': 'curl/7.70.0', + 'Private-Token': api_token } req = urllib.request.Request(url, headers=headers) try: @@ -71,18 +68,20 @@ def fetch_single_shafile(url: str) -> str: return filename -def fetch_wheel_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: +def fetch_wheel_url(base_url: str, project_id: str, job_ids: Dict[str, str], api_token: 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_sha_url: str = f'https://gitlab.com/api/v4/projects/{project_id}/jobs/{job_ids["build_wheel"]}'\ + '/artifacts/dist/SHA256SUMS' + wheel_filename: str = fetch_single_shafile(wheel_sha_url, api_token) wheel_url: str = f'{mybase}/dist/{wheel_filename}' return wheel_url, wheel_sha_url -def fetch_debian_url(base_url: str, job_ids: Dict[str, str]) -> Optional[Tuple[str, str]]: +def fetch_debian_url(base_url: str, project_id: str, job_ids: Dict[str, str], api_token: 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_sha_url: str = f'https://gitlab.com/api/v4/projects/{project_id}/jobs/{job_ids["build_debian"]}'\ + '/artifacts/package/debian/SHA256SUMS' + debian_filename: str = fetch_single_shafile(debian_sha_url, api_token) debian_url: str = f'{mybase}/package/debian/{debian_filename}' return debian_url, debian_sha_url @@ -118,8 +117,8 @@ def main(): 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_debian_url(base_url, job_ids) + wheel_url, wheel_sha_url = fetch_wheel_url(base_url, project_id, job_ids, api_token) + debian_url, debian_sha_url = fetch_debian_url(base_url, project_id, job_ids, api_token) augmented_changelog = f'''{changelog.strip()} @@ -127,15 +126,34 @@ def main(): - [Python Wheel]({wheel_url}) ([sha256]({wheel_sha_url})) - [Debian Package]({debian_url}) ([sha256]({debian_sha_url}))''' + # Docker currently not working + # - Docker image: registry.gitlab.com/{project_name}:{release_tag} - post_body: str = json.dumps({'description': augmented_changelog}) + post_body: str = json.dumps({ + 'tag_name': release_tag, + 'description': augmented_changelog, + 'assets': { + 'links': [ + { + 'name': 'Python Wheel', + 'url': wheel_url, + 'link_type': 'package' + }, + { + 'name': 'Debian Package', + 'url': debian_url, + 'link_type': 'package' + } + ] + } + }) gitlab_release_api_url: str = \ - f'https://gitlab.com/api/v4/projects/{project_id}/repository/tags/{release_tag}/release' + f'https://gitlab.com/api/v4/projects/{project_id}/releases' headers: Dict[str, str] = { 'Private-Token': api_token, 'Content-Type': 'application/json; charset=utf-8', - 'User-Agent': USER_AGENT + 'User-Agent': 'curl/7.70.0' } request = urllib.request.Request(