• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright 2019 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""A custom script example that utilizes the .JSON contents of the tryjob."""
8
9from __future__ import print_function
10
11import json
12import sys
13
14from update_tryjob_status import TryjobStatus
15
16
17def main():
18  """Determines the exit code based off of the contents of the .JSON file."""
19
20  # Index 1 in 'sys.argv' is the path to the .JSON file which contains
21  # the contents of the tryjob.
22  #
23  # Format of the tryjob contents:
24  #   {
25  #     "status" : [TRYJOB_STATUS],
26  #     "buildbucket_id" : [BUILDBUCKET_ID],
27  #     "extra_cls" : [A_LIST_OF_EXTRA_CLS_PASSED_TO_TRYJOB],
28  #     "url" : [GERRIT_URL],
29  #     "builder" : [TRYJOB_BUILDER_LIST],
30  #     "rev" : [REVISION],
31  #     "link" : [LINK_TO_TRYJOB],
32  #     "options" : [A_LIST_OF_OPTIONS_PASSED_TO_TRYJOB]
33  #   }
34  abs_path_json_file = sys.argv[1]
35
36  with open(abs_path_json_file) as f:
37    tryjob_contents = json.load(f)
38
39  CUTOFF_PENDING_REVISION = 369416
40
41  SKIP_REVISION_CUTOFF_START = 369420
42  SKIP_REVISION_CUTOFF_END = 369428
43
44  if tryjob_contents['status'] == TryjobStatus.PENDING.value:
45    if tryjob_contents['rev'] <= CUTOFF_PENDING_REVISION:
46      # Exit code 0 means to set the tryjob 'status' as 'good'.
47      sys.exit(0)
48
49    # Exit code 124 means to set the tryjob 'status' as 'bad'.
50    sys.exit(124)
51
52  if tryjob_contents['status'] == TryjobStatus.BAD.value:
53    # Need to take a closer look at the contents of the tryjob to then decide
54    # what that tryjob's 'status' value should be.
55    #
56    # Since the exit code is not in the mapping, an exception will occur which
57    # will save the file in the directory of this custom script example.
58    sys.exit(1)
59
60  if tryjob_contents['status'] == TryjobStatus.SKIP.value:
61    # Validate that the 'skip value is really set between the cutoffs.
62    if SKIP_REVISION_CUTOFF_START < tryjob_contents['rev'] < \
63        SKIP_REVISION_CUTOFF_END:
64      # Exit code 125 means to set the tryjob 'status' as 'skip'.
65      sys.exit(125)
66
67    if tryjob_contents['rev'] >= SKIP_REVISION_CUTOFF_END:
68      sys.exit(124)
69
70
71if __name__ == '__main__':
72  main()
73