diff --git a/shipitscript/src/shipitscript/data/mark_phase_as_completed_task_schema.json b/shipitscript/src/shipitscript/data/mark_phase_as_completed_task_schema.json new file mode 100644 index 000000000..862ff8933 --- /dev/null +++ b/shipitscript/src/shipitscript/data/mark_phase_as_completed_task_schema.json @@ -0,0 +1,43 @@ +{ + "title": "Taskcluster ShipIt mark-phase-as-completed task minimal schema", + "type": "object", + "properties": { + "dependencies": { + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "string" + } + }, + "scopes": { + "type": "array", + "minItems": 2, + "uniqueItems": true, + "items": { + "type": "string" + } + }, + "payload": { + "type": "object", + "properties": { + "release_name": { + "type": "string" + }, + "phase": { + "type": "string" + } + }, + "required": [ + "release_name", + "phase" + ], + "additionalProperties": false + } + }, + "required": [ + "dependencies", + "scopes", + "payload" + ] +} \ No newline at end of file diff --git a/shipitscript/src/shipitscript/script.py b/shipitscript/src/shipitscript/script.py index e56a2ce5b..1cf432366 100644 --- a/shipitscript/src/shipitscript/script.py +++ b/shipitscript/src/shipitscript/script.py @@ -24,6 +24,16 @@ async def async_main(context): log.info("Success!") +def mark_phase_as_completed_action(context): + """Action to perform is to tell Ship-it API that a phase can be marked + as completed""" + release_name = context.task["payload"]["release_name"] + phase = context.task["payload"]["phase"] + + log.info("Marking the release's phase as completed ...") + ship_actions.mark_phase_as_completed(context.ship_it_instance_config, release_name, phase) + + def mark_as_shipped_action(context): """Action to perform is to tell Ship-it API that a release can be marked as shipped""" @@ -63,7 +73,11 @@ def create_new_release_action(context): # ACTION_MAP {{{1 -ACTION_MAP = {"mark-as-shipped": mark_as_shipped_action, "create-new-release": create_new_release_action} +ACTION_MAP = { + "mark-as-shipped": mark_as_shipped_action, + "create-new-release": create_new_release_action, + "mark-phase-as-completed": mark_phase_as_completed_action, +} def get_default_config(): diff --git a/shipitscript/src/shipitscript/ship_actions.py b/shipitscript/src/shipitscript/ship_actions.py index c17dc67d5..3d93a0330 100644 --- a/shipitscript/src/shipitscript/ship_actions.py +++ b/shipitscript/src/shipitscript/ship_actions.py @@ -102,3 +102,10 @@ def mark_as_shipped_v2(shipit_config, release_name): log.info("Marking the release as shipped...") release_api.update_status(release_name, status="shipped", headers=headers) check_release_has_values_v2(release_api, release_name, headers, status="shipped") + + +def mark_phase_as_completed(shipit_config, release_name, phase): + release_api, headers = get_shipit_api_instance(shipit_config) + + log.info("Marking the release's phase as completed ...") + release_api.update_phase_status(release_name, phase, status="completed", headers=headers) diff --git a/shipitscript/src/shipitscript/shipitapi.py b/shipitscript/src/shipitscript/shipitapi.py index 62e083f3b..560090066 100644 --- a/shipitscript/src/shipitscript/shipitapi.py +++ b/shipitscript/src/shipitscript/shipitapi.py @@ -150,3 +150,15 @@ def trigger_release_phase(self, release_name, phase, headers={}): log.error(resp.content) log.error(f"Response code: {resp.status_code}") raise + + def update_phase_status(self, release_name, phase, status, headers={}): + data = json.dumps({"status": status}) + response = None + try: + response = self._request(api_endpoint=f"/releases/{release_name}/{phase}", method="PATCH", data=data, headers=headers) + except Exception: + log.error(f"Caught error while triggering {phase} for {release_name}", exc_info=True) + if response: + log.error(response.content) + log.error(f"Response code: {response.status_code}") + raise