Fix release script
This commit is contained in:
parent
90b80ae529
commit
396e0e5c5f
1 changed files with 37 additions and 19 deletions
|
@ -1,4 +1,3 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from typing import Any, Dict, List, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
|
@ -10,9 +9,6 @@ import http.client
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
|
|
||||||
USER_AGENT = 'curl/7.70.0'
|
|
||||||
|
|
||||||
|
|
||||||
def parse_changelog(tag: str) -> Optional[str]:
|
def parse_changelog(tag: str) -> Optional[str]:
|
||||||
release_changelog: str = ''
|
release_changelog: str = ''
|
||||||
with open('CHANGELOG.md', 'r') as f:
|
with open('CHANGELOG.md', 'r') as f:
|
||||||
|
@ -32,11 +28,11 @@ def parse_changelog(tag: str) -> Optional[str]:
|
||||||
return release_changelog
|
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'
|
url: str = f'https://gitlab.com/api/v4/projects/{project_id}/pipelines/{pipeline_id}/jobs'
|
||||||
headers: Dict[str, str] = {
|
headers: Dict[str, str] = {
|
||||||
'Private-Token': api_token,
|
'Private-Token': api_token,
|
||||||
'User-Agent': USER_AGENT
|
'User-Agent': 'curl/7.70.0'
|
||||||
}
|
}
|
||||||
req = urllib.request.Request(url, headers=headers)
|
req = urllib.request.Request(url, headers=headers)
|
||||||
try:
|
try:
|
||||||
|
@ -55,9 +51,10 @@ def fetch_job_ids(project_id: int, pipeline_id: int, api_token: str) -> Dict[str
|
||||||
return jobidmap
|
return jobidmap
|
||||||
|
|
||||||
|
|
||||||
def fetch_single_shafile(url: str) -> str:
|
def fetch_single_shafile(url: str, api_token: str) -> str:
|
||||||
headers: Dict[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)
|
req = urllib.request.Request(url, headers=headers)
|
||||||
try:
|
try:
|
||||||
|
@ -71,18 +68,20 @@ def fetch_single_shafile(url: str) -> str:
|
||||||
return filename
|
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'
|
mybase: str = f'{base_url}/jobs/{job_ids["build_wheel"]}/artifacts/raw'
|
||||||
wheel_sha_url: str = f'{mybase}/dist/SHA256SUMS'
|
wheel_sha_url: str = f'https://gitlab.com/api/v4/projects/{project_id}/jobs/{job_ids["build_wheel"]}'\
|
||||||
wheel_filename: str = fetch_single_shafile(wheel_sha_url)
|
'/artifacts/dist/SHA256SUMS'
|
||||||
|
wheel_filename: str = fetch_single_shafile(wheel_sha_url, api_token)
|
||||||
wheel_url: str = f'{mybase}/dist/{wheel_filename}'
|
wheel_url: str = f'{mybase}/dist/{wheel_filename}'
|
||||||
return wheel_url, wheel_sha_url
|
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'
|
mybase: str = f'{base_url}/jobs/{job_ids["build_debian"]}/artifacts/raw'
|
||||||
debian_sha_url: str = f'{mybase}/package/debian/SHA256SUMS'
|
debian_sha_url: str = f'https://gitlab.com/api/v4/projects/{project_id}/jobs/{job_ids["build_debian"]}'\
|
||||||
debian_filename: str = fetch_single_shafile(debian_sha_url)
|
'/artifacts/package/debian/SHA256SUMS'
|
||||||
|
debian_filename: str = fetch_single_shafile(debian_sha_url, api_token)
|
||||||
debian_url: str = f'{mybase}/package/debian/{debian_filename}'
|
debian_url: str = f'{mybase}/package/debian/{debian_filename}'
|
||||||
return debian_url, debian_sha_url
|
return debian_url, debian_sha_url
|
||||||
|
|
||||||
|
@ -118,8 +117,8 @@ def main():
|
||||||
|
|
||||||
base_url: str = f'https://gitlab.com/{project_name}/-'
|
base_url: str = f'https://gitlab.com/{project_name}/-'
|
||||||
|
|
||||||
wheel_url, wheel_sha_url = fetch_wheel_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, job_ids)
|
debian_url, debian_sha_url = fetch_debian_url(base_url, project_id, job_ids, api_token)
|
||||||
|
|
||||||
augmented_changelog = f'''{changelog.strip()}
|
augmented_changelog = f'''{changelog.strip()}
|
||||||
|
|
||||||
|
@ -127,15 +126,34 @@ def main():
|
||||||
|
|
||||||
- [Python Wheel]({wheel_url}) ([sha256]({wheel_sha_url}))
|
- [Python Wheel]({wheel_url}) ([sha256]({wheel_sha_url}))
|
||||||
- [Debian Package]({debian_url}) ([sha256]({debian_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 = \
|
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] = {
|
headers: Dict[str, str] = {
|
||||||
'Private-Token': api_token,
|
'Private-Token': api_token,
|
||||||
'Content-Type': 'application/json; charset=utf-8',
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
'User-Agent': USER_AGENT
|
'User-Agent': 'curl/7.70.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
request = urllib.request.Request(
|
request = urllib.request.Request(
|
||||||
|
|
Loading…
Reference in a new issue