Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / taskcluster / scripts / testrail_main.py
blob19bb2f41eae929f0aabffa2a91822093835db810
1 #!/usr/bin/env python3
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 """
7 This Python script automates creating milestones and test runs in TestRail and updating
8 test cases based on the results of automated smoke tests for different product releases.
10 Functionality includes:
11 - Reading TestRail credentials and environment variables.
12 - Building milestone names and descriptions.
13 - Interacting with the TestRail API to create milestones, test runs, and update test cases.
14 - Sending notifications to a specified Slack channel.
15 """
17 import os
18 import sys
20 from lib.testrail_api import TestRail
21 from lib.testrail_utils import (
22 build_milestone_description,
23 build_milestone_name,
24 get_release_type,
25 get_release_version,
26 load_testrail_credentials,
28 from slack_notifier import (
29 get_taskcluster_options,
30 send_error_notification,
31 send_success_notification,
34 # Constants
35 SUCCESS_CHANNEL_ID = "C02KDDS9QM9" # mobile-testeng
36 ERROR_CHANNEL_ID = "G016BC5FUHJ" # mobile-alerts-sandbox
39 def main():
40 # Load TestRail credentials
41 credentials = load_testrail_credentials(".testrail_credentials.json")
42 testrail = TestRail(
43 credentials["host"], credentials["username"], credentials["password"]
46 # Read task environment variables
47 try:
48 shipping_product = os.environ["SHIPPING_PRODUCT"]
49 testrail_product_type = os.environ["TESTRAIL_PRODUCT_TYPE"]
50 testrail_project_id = os.environ["TESTRAIL_PROJECT_ID"]
51 testrail_test_suite_id = os.environ["TESTRAIL_TEST_SUITE_ID"]
52 except KeyError as e:
53 raise ValueError(f"ERROR: Missing Environment Variable: {e}")
55 # Release information
56 release_version = get_release_version()
57 release_type = get_release_type(release_version)
59 # Build milestone information
60 milestone_name = build_milestone_name(
61 testrail_product_type, release_type, release_version
63 milestone_description = build_milestone_description(milestone_name)
65 # Configure Taskcluster API
66 options = get_taskcluster_options()
68 try:
69 # Check if milestone exists
70 if testrail.does_milestone_exist(testrail_project_id, milestone_name):
71 print(f"Milestone for {milestone_name} already exists. Exiting script...")
72 sys.exit()
74 # Create milestone and test runs
75 devices = ["Google Pixel 3(Android11)", "Google Pixel 2(Android11)"]
76 testrail.create_milestone_and_test_runs(
77 testrail_project_id,
78 milestone_name,
79 milestone_description,
80 devices,
81 testrail_test_suite_id,
84 # Send success notification
85 success_values = {
86 "RELEASE_TYPE": release_type,
87 "RELEASE_VERSION": release_version,
88 "SHIPPING_PRODUCT": shipping_product,
89 "TESTRAIL_PROJECT_ID": testrail_project_id,
90 "TESTRAIL_PRODUCT_TYPE": testrail_product_type,
92 send_success_notification(success_values, SUCCESS_CHANNEL_ID, options)
94 except Exception as error_message:
95 send_error_notification(str(error_message), ERROR_CHANNEL_ID, options)
98 if __name__ == "__main__":
99 main()