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:
parent
59214019ba
commit
6d7c03fb3d
1 changed files with 43 additions and 34 deletions
|
@ -43,9 +43,11 @@ if not API_PASSWORD:
|
||||||
MAX_RETRY = from_env('MAX_RETRIES', None)
|
MAX_RETRY = from_env('MAX_RETRIES', None)
|
||||||
|
|
||||||
REPO_NAME = from_env('REPO_NAME', 'stable')
|
REPO_NAME = from_env('REPO_NAME', 'stable')
|
||||||
|
PREFIX = from_env('PREFIX', '.')
|
||||||
REPO_COMPONENT = from_env('REPO_COMPONENT', 'main')
|
REPO_COMPONENT = from_env('REPO_COMPONENT', 'main')
|
||||||
INPUT_PATH = from_env('PATH', 'dist')
|
INPUT_PATH = from_env('PATH', 'dist')
|
||||||
SOURCE_NAME = from_env('SOURCE_PACKAGE_NAME', None)
|
SOURCE_NAME = from_env('SOURCE_PACKAGE_NAME', None)
|
||||||
|
DISTRIBUTIONS = []
|
||||||
|
|
||||||
# List changes files
|
# List changes files
|
||||||
changes_files_regex = (
|
changes_files_regex = (
|
||||||
|
@ -96,13 +98,14 @@ def list_files_in_changes_file(filepath):
|
||||||
files = []
|
files = []
|
||||||
for infos in parser.parse():
|
for infos in parser.parse():
|
||||||
for info in infos:
|
for info in infos:
|
||||||
if info['tag'].lower() != 'files':
|
if info['tag'].lower() == 'files':
|
||||||
continue
|
|
||||||
|
|
||||||
for line in info['value'].split(' '):
|
for line in info['value'].split(' '):
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
files.append(os.path.join(dirpath, line.split()[-1]))
|
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
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,7 +148,9 @@ def include_file(package_name, changes_file):
|
||||||
result.status_code == 200 and
|
result.status_code == 200 and
|
||||||
data.get('Report', {}).get('Added')
|
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 False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -158,9 +163,8 @@ for changes_file in changes_files:
|
||||||
for filepath in filepaths:
|
for filepath in filepaths:
|
||||||
if not upload_file(package_name, filepath):
|
if not upload_file(package_name, filepath):
|
||||||
print(
|
print(
|
||||||
f' - {filepath}: fail to upload file, pass this changes '
|
f' - {filepath}: fail to upload file. See APTLY API logs '
|
||||||
'file'
|
'for details.')
|
||||||
)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print(f' - {filepath}')
|
print(f' - {filepath}')
|
||||||
|
@ -190,30 +194,35 @@ error = (
|
||||||
not data.get('CreatedAt')
|
not data.get('CreatedAt')
|
||||||
)
|
)
|
||||||
if error:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# Update published snapshot of repository
|
# Update published snapshot of repository for each distributions
|
||||||
print(
|
for distribution in DISTRIBUTIONS:
|
||||||
f'Update published snapshot of repository "{REPO_NAME}" to "{snap_name}"')
|
print(
|
||||||
url = f'{API_URL}/publish/:./{REPO_NAME}'
|
f'Update published snapshot of distribution "{distribution}" to '
|
||||||
payload = {
|
f'"{snap_name}" (prefix: {PREFIX})')
|
||||||
|
url = f'{API_URL}/publish/:{PREFIX}/{distribution}'
|
||||||
|
payload = {
|
||||||
'Snapshots': [
|
'Snapshots': [
|
||||||
{
|
{
|
||||||
'Component': REPO_COMPONENT,
|
'Component': REPO_COMPONENT,
|
||||||
'Name': snap_name
|
'Name': snap_name
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
result = session.put(url, json=payload)
|
result = session.put(url, json=payload)
|
||||||
if (
|
if (
|
||||||
result.status_code < 200 or
|
result.status_code < 200 or
|
||||||
result.status_code > 299
|
result.status_code > 299
|
||||||
):
|
):
|
||||||
print(
|
print(
|
||||||
f'Fail to update published snapshot of repository "{REPO_NAME}" to '
|
f'Fail to update published snapshot of distribution "{distribution}" '
|
||||||
f'"{snap_name}"')
|
f'to "{snap_name}" (prefix: {PREFIX}). See APTLY API logs for '
|
||||||
|
'details.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
|
Loading…
Reference in a new issue