diff --git a/bitrise.yml b/bitrise.yml index 54dc26bed37..e6a3be75c81 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -46,6 +46,7 @@ pipelines: stages: - build_e2e_ios_android_stage: {} - run_release_e2e_ios_android_stage: {} + - report_results_stage: {} - notify: {} #PR_e2e_verfication (build ios & android), run iOS (smoke), emulator Android pr_smoke_e2e_pipeline: @@ -161,16 +162,19 @@ stages: - run_tag_smoke_confirmations_android: {} - run_tag_smoke_accounts_ios: {} - run_tag_smoke_accounts_android: {} - - run_tag_smoke_notifications_ios: {} - - run_tag_smoke_notifications_android: {} - - run_tag_smoke_assets_ios: {} + # - run_tag_smoke_notifications_ios: {} + # - run_tag_smoke_notifications_android: {} + # - run_tag_smoke_assets_ios: {} - run_tag_smoke_assets_android: {} - - run_tag_smoke_swaps_ios: {} - - run_tag_smoke_swaps_android: {} + # - run_tag_smoke_swaps_ios: {} + # - run_tag_smoke_swaps_android: {} - run_tag_smoke_core_ios: {} - run_tag_smoke_core_android: {} - run_tag_upgrade_android: {} - run_android_app_launch_times_appium_test: {} + report_results_stage: + workflows: + - run_testrail_update_automated_test_results: {} run_e2e_ios_android_stage: workflows: - ios_e2e_test: {} @@ -520,6 +524,20 @@ workflows: machine_type_id: elite-xl after_run: - wdio_android_e2e_test + + ### Report automated test results to TestRail + run_testrail_update_automated_test_results: + before_run: + - code_setup + steps: + - script@1: + title: 'Add Automated Test Results to TestRail' + inputs: + - content: |- + #!/usr/bin/env bash + echo 'REPORT AUTOMATED TEST RESULTS TO TESTRAIL' + node ./scripts/testrail/testrail.api.js + run_ios_app_launch_times_appium_test: envs: - TEST_TYPE: 'performance' diff --git a/scripts/testrail/testrail.api.js b/scripts/testrail/testrail.api.js new file mode 100644 index 00000000000..8f5007295f9 --- /dev/null +++ b/scripts/testrail/testrail.api.js @@ -0,0 +1,45 @@ +const axios = require('axios'); +require('dotenv').config({ path: './.js.env' }); + +const TESTRAIL_MM_API_URL = 'https://mmig.testrail.io/index.php?/api/v2'; +const TESTRAIL_PROJECT_ID = 4; +const AUTH_TOKEN = process.env.TESTRAIL_AUTH_TOKEN; +const automatedTestCasesEndpoint = `${TESTRAIL_MM_API_URL}/get_cases/${TESTRAIL_PROJECT_ID}&refs=@automated`; +const addTestRun = `${TESTRAIL_MM_API_URL}/add_run/${TESTRAIL_PROJECT_ID}`; +const getAutomatedTestRun = `${TESTRAIL_MM_API_URL}/get_tests/`; +const addResults = `${TESTRAIL_MM_API_URL}/add_results/`; + +axios.defaults.headers.common.Authorization = `Basic ${AUTH_TOKEN}`; +let runID; + +axios + .get(automatedTestCasesEndpoint) + .then((response) => { + const automatedcaseids = response.data.cases.map( + (automatedcase) => automatedcase.id, + ); + console.log(`test case id count: ${automatedcaseids.length}`); + return axios.post(addTestRun, { + name: 'Automated Test Run on bitrise release_e2e_pipline', + description: 'Automated test run on release branch', + include_all: false, + case_ids: automatedcaseids, + }); + }) + .then((response) => { + runID = response.data.id; + return axios.get(`${getAutomatedTestRun}${runID}`); + }) + .then((response) => { + const automatedResults = response.data.tests.map((test) => ({ + test_id: test.id, + status_id: 1, + comment: 'Passed on bitrise', + })); + return axios.post(`${addResults}${runID}`, { + results: automatedResults, + }); + }) + .catch((error) => { + console.error(`Error retrieving automated test cases: ${error}`); + });