|
1 | | -import json |
2 | 1 | import logging |
3 | | -import urllib.request |
4 | 2 |
|
5 | 3 | import requests |
6 | 4 | import yaml |
|
10 | 8 | # USER_AGENT constant for marketplace API calls |
11 | 9 | USER_AGENT = "Mozilla_dc_core_eng" |
12 | 10 |
|
| 11 | +# Marketplace API base host. |
| 12 | +MARKETPLACE_BASE_URL = "https://marketplace.atlassian.com" |
| 13 | + |
13 | 14 | """ |
14 | 15 | This script is used to update the product versions in the helm charts descriptors (Chart.yaml). |
15 | 16 | It fetches the latest available version (LTS for products with LTS) from marketplace and updates the required |
16 | 17 | tag in the product chart. It also updates expected output for the product. |
17 | 18 |
|
18 | | -Script is currently executed manually and is in a fairly rough shape. |
| 19 | +Script is currently executed manually and is in a fairly rough shape. |
19 | 20 | """ |
20 | 21 |
|
21 | 22 | logging.basicConfig(level=logging.INFO, format="%(levelname).1s %(message)s") |
|
27 | 28 |
|
28 | 29 | def update_versions(product_to_update, new_version): |
29 | 30 | products_to_update = [product_to_update] |
30 | | - if product == 'bamboo': |
| 31 | + if product_to_update == 'bamboo': |
31 | 32 | products_to_update.append("bamboo-agent") |
32 | 33 |
|
33 | 34 | chart_files = [f'../../main/charts/{p}/Chart.yaml' for p in products_to_update] |
@@ -62,43 +63,19 @@ def update_expected_output(products_to_update, new_version): |
62 | 63 | logging.info('Updated expected output file: %s', output_file) |
63 | 64 |
|
64 | 65 |
|
65 | | -def product_versions_marketplace(product_key): |
66 | | - mac_url = 'https://marketplace.atlassian.com' |
67 | | - request_url = f'/rest/2/products/key/{product_key}/versions' |
68 | | - params = {'offset': 0, 'limit': 50} |
69 | | - versions = set() |
70 | | - page = 1 |
71 | | - while True: |
72 | | - logging.debug(f'Retrieving Marketplace product versions for {product_key}: page {page}') |
73 | | - headers = {'User-Agent': USER_AGENT} |
74 | | - r = requests.get(mac_url + request_url, params=params, headers=headers) |
75 | | - version_data = r.json() |
76 | | - for version in version_data['_embedded']['versions']: |
77 | | - if all(d.isdigit() for d in version['name'].split('.')): |
78 | | - logging.debug(f"Adding version {version['name']}") |
79 | | - versions.add(version['name']) |
80 | | - if 'next' not in version_data['_links']: |
81 | | - break |
82 | | - request_url = version_data['_links']['next']['href'] |
83 | | - page += 1 |
84 | | - params = {} |
85 | | - logging.debug(f'Found {len(versions)} versions') |
86 | | - return sorted(list(versions), reverse=True) |
87 | | - |
88 | | - |
89 | | -def latest_minor(version, mac_versions): |
90 | | - major_minor_version = '.'.join(version.split('.')[:2]) |
91 | | - minor_versions = [v for v in mac_versions |
92 | | - if v.startswith(f'{major_minor_version}.')] |
93 | | - minor_versions.sort(key=lambda s: [int(u) for u in s.split('.')]) |
94 | | - return minor_versions[-1] |
| 66 | +def latest_marketplace_version(product_key): |
| 67 | + """Return the latest version string for a host product via the v3 |
| 68 | + `parent-software` API. Uses `?limit=1`; v3 returns the list in |
| 69 | + descending buildNumber order, so the first item is the latest.""" |
| 70 | + url = f"{MARKETPLACE_BASE_URL}/rest/3/parent-software/{product_key}/versions" |
| 71 | + r = requests.get(url, params={'limit': 1}, headers={'User-Agent': USER_AGENT}) |
| 72 | + return r.json()['versions'][0]['versionNumber'] |
95 | 73 |
|
96 | 74 |
|
97 | 75 | def update_mesh_tag(): |
98 | 76 | logging.info("-------------------------------") |
99 | 77 | logging.info('- Updating Bitbucket Mesh tag -') |
100 | 78 | logging.info("-------------------------------") |
101 | | - mesh_repo = 'atlassian/bitbucket-mesh' |
102 | 79 | new_version = product_versions.get_lts_version(['mesh']).replace(tag_suffix, "") |
103 | 80 | bitbucket_values_file = '../../main/charts/bitbucket/values.yaml' |
104 | 81 | expected_bitbucket_output_file = '../resources/expected_helm_output/bitbucket/output.yaml' |
@@ -134,9 +111,7 @@ def update_mesh_tag(): |
134 | 111 | logging.info("Latest LTS version: %s", version) |
135 | 112 | else: |
136 | 113 | logging.info("Non-LTS product") |
137 | | - headers = {'User-Agent': USER_AGENT} |
138 | | - r = requests.get(f'https://marketplace.atlassian.com/rest/2/products/key/{product}/versions/latest', headers=headers) |
139 | | - version = r.json()['name'] |
| 114 | + version = latest_marketplace_version(product) |
140 | 115 |
|
141 | 116 | new_version_tag = f"{version}{tag_suffix}" |
142 | 117 | logging.info(f"Latest version: %s, tagname: {version}{tag_suffix}", version) |
|
0 commit comments