Fix publishing snapshot

When calling APTLY publish API, we have to pass the distribution name
and not the repository name. Distribution names are now collected from
changes files and a call to the APTLY publish API will be made for all
updated distribution.

Also add a PREFIX parameter to permit to specify the APTLY prefix (and
storage if it need to be specified).
This commit is contained in:
Benjamin Renard 2022-11-30 20:23:41 +01:00
parent 59214019ba
commit 6d7c03fb3d

View file

@ -43,9 +43,11 @@ if not API_PASSWORD:
MAX_RETRY = from_env('MAX_RETRIES', None)
REPO_NAME = from_env('REPO_NAME', 'stable')
PREFIX = from_env('PREFIX', '.')
REPO_COMPONENT = from_env('REPO_COMPONENT', 'main')
INPUT_PATH = from_env('PATH', 'dist')
SOURCE_NAME = from_env('SOURCE_PACKAGE_NAME', None)
DISTRIBUTIONS = []
# List changes files
changes_files_regex = (
@ -96,13 +98,14 @@ def list_files_in_changes_file(filepath):
files = []
for infos in parser.parse():
for info in infos:
if info['tag'].lower() != 'files':
continue
if info['tag'].lower() == 'files':
for line in info['value'].split(' '):
if not line:
continue
files.append(os.path.join(dirpath, line.split()[-1]))
if info['tag'].lower() == 'distribution':
if info['value'] not in DISTRIBUTIONS:
DISTRIBUTIONS.append(info['value'])
return files
@ -145,7 +148,9 @@ def include_file(package_name, changes_file):
result.status_code == 200 and
data.get('Report', {}).get('Added')
):
print(f'Unknown error occurred including {changes_file}')
print(
f'Unknown error occurred including {changes_file}'
'See APTLY API logs for details.')
return False
return True
@ -158,9 +163,8 @@ for changes_file in changes_files:
for filepath in filepaths:
if not upload_file(package_name, filepath):
print(
f' - {filepath}: fail to upload file, pass this changes '
'file'
)
f' - {filepath}: fail to upload file. See APTLY API logs '
'for details.')
sys.exit(1)
else:
print(f' - {filepath}')
@ -190,14 +194,18 @@ error = (
not data.get('CreatedAt')
)
if error:
print(f'Fail to create snapshot "{snap_name}" of repository "{REPO_NAME}"')
print(
f'Fail to create snapshot "{snap_name}" of repository "{REPO_NAME}".'
'See APTLY API logs for details.')
sys.exit(1)
# Update published snapshot of repository
# Update published snapshot of repository for each distributions
for distribution in DISTRIBUTIONS:
print(
f'Update published snapshot of repository "{REPO_NAME}" to "{snap_name}"')
url = f'{API_URL}/publish/:./{REPO_NAME}'
f'Update published snapshot of distribution "{distribution}" to '
f'"{snap_name}" (prefix: {PREFIX})')
url = f'{API_URL}/publish/:{PREFIX}/{distribution}'
payload = {
'Snapshots': [
{
@ -212,8 +220,9 @@ if (
result.status_code > 299
):
print(
f'Fail to update published snapshot of repository "{REPO_NAME}" to '
f'"{snap_name}"')
f'Fail to update published snapshot of distribution "{distribution}" '
f'to "{snap_name}" (prefix: {PREFIX}). See APTLY API logs for '
'details.')
sys.exit(1)
print("Done.")