Skip to content

Commit 8aa4d4e

Browse files
Jordan Lundallan-silva
authored andcommitted
adds new action in action map for creating a shipit release (mozilla-releng#75)
* adds new action in action map for creating a shipit release * Fix tox by importing functions properly * use shipitapi for interfacing with shipit * fix create_new_release_action typo * Add triggering phase logic * fixes up tox
1 parent d683f52 commit 8aa4d4e

File tree

4 files changed

+125
-11
lines changed

4 files changed

+125
-11
lines changed

shipitscript/shipitscript/script.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
get_task_action,
1313
validate_task_schema,
1414
)
15+
from shipitscript.utils import get_buildnum_from_version
1516

1617
log = logging.getLogger(__name__)
1718

@@ -36,8 +37,47 @@ def mark_as_shipped_action(context):
3637
ship_actions.mark_as_shipped_v2(context.ship_it_instance_config, release_name)
3738

3839

40+
def create_new_release_action(context):
41+
"""Determine if there is a shippable release and create it if so in Shipit """
42+
payload = context.task['payload']
43+
shipit_config = context.ship_it_instance_config
44+
# TODO actually include these in the payload from taskgraph
45+
product = payload["product"]
46+
channel = payload["channel"]
47+
repo = payload["repo"]
48+
phase = payload["phase"] # release phase we want to trigger
49+
50+
log.info(
51+
'Determining most recent shipped revision and next version / buildnum to release'
52+
)
53+
last_shipped_revision = ship_actions.get_most_recent_shipped_revision(
54+
product, channel, shipit_config
55+
)
56+
next_version = ship_actions.get_next_release_version(
57+
product, channel, shipit_config
58+
)
59+
log.info('Ensuring next version is a new version and not a buildnum increment')
60+
if get_buildnum_from_version(next_version) != 1:
61+
# TODO quit early, mark task as green though
62+
pass
63+
log.info('Determining most recent shippable revision')
64+
shippable_revision = ship_actions.get_shippable_revision(
65+
repo, last_shipped_revision
66+
)
67+
if not shippable_revision:
68+
# TODO quit early, mark task as green though
69+
pass
70+
log.info('create a new release')
71+
ship_actions.create_new_release(
72+
product, repo, channel, next_version, shippable_revision, phase, shipit_config
73+
)
74+
75+
3976
# ACTION_MAP {{{1
40-
ACTION_MAP = {'mark-as-shipped': mark_as_shipped_action}
77+
ACTION_MAP = {
78+
'mark-as-shipped': mark_as_shipped_action,
79+
'create-new-release': create_new_release_action,
80+
}
4181

4282

4383
def get_default_config():

shipitscript/shipitscript/ship_actions.py

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,66 @@
1010
log = logging.getLogger(__name__)
1111

1212

13-
def mark_as_shipped_v2(ship_it_instance_config, release_name):
14-
"""Function to make a simple call to Ship-it API v2 to change a release
15-
status to 'shipped'
16-
"""
13+
def get_shipit_api_instance(shipit_config):
1714
(
18-
taskcluster_client_id,
19-
taskcluster_access_token,
15+
tc_client_id,
16+
tc_access_token,
2017
api_root,
2118
timeout_in_seconds,
22-
) = get_auth_primitives_v2(ship_it_instance_config)
19+
) = get_auth_primitives_v2(shipit_config)
20+
2321
release_api = Release_V2(
24-
taskcluster_client_id=taskcluster_client_id,
25-
taskcluster_access_token=taskcluster_access_token,
22+
taskcluster_client_id=tc_client_id,
23+
taskcluster_access_token=tc_access_token,
2624
api_root=api_root,
2725
timeout=timeout_in_seconds,
2826
)
27+
headers = get_request_headers(api_root)
28+
29+
return release_api, headers
30+
31+
32+
def get_shippable_revision(repo, last_shipped_revision):
33+
pass
34+
35+
36+
def get_most_recent_shipped_revision(product, channel, shipit_config):
37+
release_api, headers = get_shipit_api_instance(shipit_config)
38+
39+
40+
def get_next_release_version(product, channel, shipit_config):
41+
release_api, headers = get_shipit_api_instance(shipit_config)
42+
43+
44+
def start_new_release(
45+
self,
46+
product,
47+
channel,
48+
release_name,
49+
version,
50+
revision,
51+
phase,
52+
shipit_config,
53+
headers={},
54+
):
55+
release_api, headers = get_shipit_api_instance(shipit_config)
56+
release_name = ""
57+
58+
log.info('creating a new release...')
59+
release_api.create_new_release(
60+
product, channel, release_name, version, revision, headers=headers
61+
)
62+
release_api.trigger_release_phase(
63+
product, channel, release_name, phase, headers=headers
64+
)
65+
66+
67+
def mark_as_shipped_v2(shipit_config, release_name):
68+
"""Function to make a simple call to Ship-it API v2 to change a release
69+
status to 'shipped'
70+
"""
71+
release_api, headers = get_shipit_api_instance(shipit_config)
2972

3073
log.info('Marking the release as shipped...')
31-
headers = get_request_headers(api_root)
3274
release_api.update_status(release_name, status='shipped', headers=headers)
3375
check_release_has_values_v2(release_api, release_name, headers, status='shipped')

shipitscript/shipitscript/shipitapi.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,31 @@ def update_status(self, name, status, rebuild_product_details=True, headers={}):
124124
headers=headers,
125125
)
126126
return res
127+
128+
def releases_are_disabled(self, product, channel, headers={}):
129+
pass
130+
131+
def get_next_release_version(self, product, channel, headers={}):
132+
pass
133+
134+
def get_most_recent_shipped_revision(self, product, channel, headers={}):
135+
pass
136+
137+
def create_new_release(
138+
self, product, repo, channel, release_name, version, revision, headers={}
139+
):
140+
if self.releases_are_disabled(product, channel):
141+
return
142+
pass
143+
144+
def trigger_release_phase(self, product, channel, release_name, phase, headers={}):
145+
"""Trigger a push phase for a specific release"""
146+
if self.releases_are_disabled(product, channel):
147+
return
148+
149+
self._request(
150+
api_endpoint='/releases/{}/{}'.format(release_name, phase),
151+
method='PUT',
152+
data=None,
153+
headers=headers,
154+
)

shipitscript/shipitscript/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ def check_release_has_values_v2(release_api, release_name, headers, **kwargs):
6666
raise ScriptWorkerTaskException(err_msg)
6767

6868
log.info("All release fields have been correctly updated in Ship-it!")
69+
70+
71+
def get_buildnum_from_version(next_version):
72+
pass

0 commit comments

Comments
 (0)