Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Push cypress test results to kiwitcms not testrail (#10401)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkaye committed Mar 22, 2023
1 parent a5fcdd7 commit 853b3f8
Showing 1 changed file with 21 additions and 63 deletions.
84 changes: 21 additions & 63 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
commit_author: ${{ steps.commit.outputs.author }}
commit_email: ${{ steps.commit.outputs.email }}
percy_enable: ${{ steps.percy.outputs.value || '1' }}
testrail_enable: ${{ steps.testrail.outputs.value || '1' }}
kiwi_enable: ${{ steps.kiwi.outputs.value || '1' }}
steps:
# We create the status here and then update it to success/failure in the `report` stage
# This provides an easy link to this workflow_run from the PR before Cypress is done.
Expand Down Expand Up @@ -67,12 +67,12 @@ jobs:
!contains(fromJSON(steps.prdetails.outputs.data).labels.*.name, 'X-Needs-Percy')
run: echo "::set-output name=value::0"

# Only run Testrail when it is demanded or on develop
- name: Disable Testrail if not needed
id: testrail
# Only export to kiwi when it is demanded or on develop
- name: Disable Kiwi if not needed
id: kiwi
if: |
github.event.workflow_run.event == 'pull_request' &&
!contains(fromJSON(steps.prdetails.outputs.data).labels.*.name, 'X-Send-Testrail')
!contains(fromJSON(steps.prdetails.outputs.data).labels.*.name, 'X-Send-Kiwi')
run: echo "::set-output name=value::0"

- name: Generate unique ID 💎
Expand Down Expand Up @@ -222,69 +222,27 @@ jobs:
sha: ${{ github.event.workflow_run.head_sha }}
target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

testrail:
name: Report results to testrail
kiwi:
name: Report results to kiwi
needs:
- prepare
- tests
environment: Testrail
environment: Kiwi
runs-on: ubuntu-latest
if: ${{ needs.prepare.outputs.testrail_enable }}
if: ${{ needs.prepare.outputs.kiwi_enable }}
steps:
- uses: actions/download-artifact@v3
- name: Download all zip files
uses: actions/download-artifact@v3
with:
name: cypress-junit
- name: Prepare testrail upload config
id: testrailprep
env:
TESTRAIL_PROJECT_ID: ${{ secrets.TESTRAIL_PROJECT_ID }}
TESTRAIL_SUITE_ID: ${{ secrets.TESTRAIL_SUITE_ID }}
TEST_ID: ${{ github.run_id }}
TESTRAIL_URL: https://elementqa.testrail.io
TESTRAIL_USER: ${{ secrets.TESTRAIL_USER }}
TESTRAIL_API_KEY: ${{ secrets.TESTRAIL_API_KEY }}
run: |
echo '{"name": "element-web cypress '$TEST_ID'", "suite_id": '$TESTRAIL_SUITE_ID' }' > body.json # TODO add description with more context?
RUN_ID=`curl -X POST -d @body.json -u "$TESTRAIL_USER:$TESTRAIL_API_KEY" -H "Content-Type: application/json" "$TESTRAIL_URL/index.php?/api/v2/add_run/$TESTRAIL_PROJECT_ID" | jq '.id'`
PROJECT_NAME=`curl -X GET -u "$TESTRAIL_USER:$TESTRAIL_API_KEY" -H "Content-Type: application/json" "$TESTRAIL_URL/index.php?/api/v2/get_project/$TESTRAIL_PROJECT_ID" | jq '.name'`
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
echo "project_name=$PROJECT_NAME" >> $GITHUB_OUTPUT
- name: setup python
uses: actions/setup-python@v4
- name: Upload to kiwi
uses: vector-im/kiwitcms-upload-action@main
with:
python-version: "3.11"
- run: pip install trcli
- name: Upload junit files
env:
TESTRAIL_PROJECT_ID: ${{ secrets.TESTRAIL_PROJECT_ID }}
TESTRAIL_SUITE_ID: ${{ secrets.TESTRAIL_SUITE_ID }}
TESTRAIL_URL: https://elementqa.testrail.io
TESTRAIL_USER: ${{ secrets.TESTRAIL_USER }}
TESTRAIL_API_KEY: ${{ secrets.TESTRAIL_API_KEY }}
TESTRAIL_RUN_ID: ${{ steps.testrailprep.outputs.run_id }}
run: |
for file in results-*.xml; do
echo "Handling $file"
trcli -y -h $TESTRAIL_URL \
--project-id $TESTRAIL_PROJECT_ID \
--project ${{ steps.testrailprep.outputs.project_name }} \
--username $TESTRAIL_USER \
--password $TESTRAIL_API_KEY \
parse_junit \
--run-id $TESTRAIL_RUN_ID \
--suite-id $TESTRAIL_SUITE_ID \
--title "if you see this please check cypress build for run id not being provisioned" \
-f $file || true
# We want to keep uploading what we can; but don't want the failures/red marks when it fails, so we add || true above.
done
- name: Close test run
id: testrailpost
if: always()
env:
TESTRAIL_URL: https://elementqa.testrail.io
TESTRAIL_USER: ${{ secrets.TESTRAIL_USER }}
TESTRAIL_API_KEY: ${{ secrets.TESTRAIL_API_KEY }}
TESTRAIL_RUN_ID: ${{ steps.testrailprep.outputs.run_id }}
run: |
CLOSE_RESPONSE=`curl -X POST -d '{}' -u "$TESTRAIL_USER:$TESTRAIL_API_KEY" -H "Content-Type: application/json" "$TESTRAIL_URL/index.php?/api/v2/close_run/$TESTRAIL_RUN_ID"`
if [ ! "0" == "`echo $CLOSE_RESPONSE | jq .untested_count`" ] ; then echo "::warning title=Missing Tests::Testrail reported some cypress tests were not run. $CLOSE_RESPONSE"; fi
file-pattern: results-*.xml
kiwi-username: ${{ secrets.TCMS_USERNAME }}
kiwi-password: ${{ secrets.TCMS_PASSWORD }}
product: "Element Web"
product-version: ${{ github.event.workflow_run.head_branch }}
build-id: ${{ github.event.workflow_run.head_sha }}
suite-name: "Cypress E2E"
summary-template: "$name"

0 comments on commit 853b3f8

Please sign in to comment.