|
| 1 | +name: report-to-testmo |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + runs_on: |
| 6 | + description: "runner label specifying instance running the job" |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + run_id: |
| 10 | + description: "run id provided by GHA" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + build_type: |
| 14 | + description: "build type: nightly or release" |
| 15 | + type: string |
| 16 | + required: true |
| 17 | + testmo_project_id: |
| 18 | + description: "testmo project id" |
| 19 | + type: string |
| 20 | + required: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + |
| 24 | + BUILD: |
| 25 | + runs-on: ${{ inputs.runs_on }} |
| 26 | + outputs: |
| 27 | + status: ${{ steps.build.outputs.status }} |
| 28 | + commitid: ${{ steps.build.outputs.commitid }} |
| 29 | + permissions: |
| 30 | + id-token: write |
| 31 | + contents: read |
| 32 | + steps: |
| 33 | + |
| 34 | + - name: repo checkout |
| 35 | + uses: actions/checkout@v3 |
| 36 | + |
| 37 | + - name: s3 |
| 38 | + uses: aws-actions/configure-aws-credentials@v2 |
| 39 | + with: |
| 40 | + role-to-assume: ${{ secrets.AWS_WEBIDENTITY_FOR_GITHUB_ACTIONS }} |
| 41 | + aws-region: us-east-1 |
| 42 | + |
| 43 | + - name: build |
| 44 | + id: build |
| 45 | + run: | |
| 46 | + pwd |
| 47 | + sudo apt-get -y install python3-pip |
| 48 | + pip3 --version |
| 49 | + sudo pip3 install virtualenv |
| 50 | + virtualenv venv |
| 51 | + source venv/bin/activate |
| 52 | + pip install -e . |
| 53 | + if [[ "${{ inputs.build_type }}" = release ]]; then |
| 54 | + sed -i 's/is_release = False/is_release = True/g' src/${{ github.event.repository.name }}/version.py |
| 55 | + fi |
| 56 | + status=$(make -B build || echo 'FAILED') |
| 57 | + deactivate |
| 58 | + echo "=========== Build log ===========" |
| 59 | + echo "${status}" |
| 60 | + echo "commitid=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT" |
| 61 | + echo "=========== Build status ===========" |
| 62 | + if [[ "${status}" = "FAILED" ]]; then |
| 63 | + echo "${{ github.event.repository.name }} build failed" |
| 64 | + echo "status=failed" >> "$GITHUB_OUTPUT" |
| 65 | + exit 1 |
| 66 | + else |
| 67 | + echo "${{ github.event.repository.name }} build success" |
| 68 | + fi |
| 69 | + echo "=========== Generated build ===========" |
| 70 | + ls dist/ |
| 71 | + echo "=========== Copy build to S3 ===========" |
| 72 | + aws s3 cp dist/*.whl s3://nm-github-actions/${{ github.event.repository.name }}/ |
| 73 | + if [ $? -eq 0 ]; then |
| 74 | + echo "ok: copied to s3://nm-github-actions/${{ github.event.repository.name }}/" |
| 75 | + echo "status=success" >> "$GITHUB_OUTPUT" |
| 76 | + else |
| 77 | + echo "failed: copied to s3://nm-github-actions/${{ github.event.repository.name }}/" |
| 78 | + echo "status=failed" >> "$GITHUB_OUTPUT" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + oldDate=`date --date='-2 month' +%Y%m%d` |
| 82 | + oldWhl=`(aws s3 ls s3://nm-github-actions/${{ github.event.repository.name }}/ | grep nightly | grep "${oldDate}") || echo "notfound"` |
| 83 | + if [[ "${oldWhl}" != 'notfound' ]]; then |
| 84 | + for oldwhl in $(echo "${oldWhl}" | awk '{print $4}') |
| 85 | + do |
| 86 | + echo "Remove old build ${oldwhl} in S3" |
| 87 | + aws s3 rm s3://nm-github-actions/${{ github.event.repository.name }}/${oldwhl} |
| 88 | + done |
| 89 | + fi |
| 90 | +
|
| 91 | + TESTMO: |
| 92 | + if: success() || failure() |
| 93 | + needs: BUILD |
| 94 | + runs-on: ${{ inputs.runs_on }} |
| 95 | + steps: |
| 96 | + |
| 97 | + - id: report |
| 98 | + run: | |
| 99 | + echo "node: $(node -v)" |
| 100 | + echo "npm: $(npm -v)" |
| 101 | + echo "Installing testmo cli..." |
| 102 | + sudo npm install -g @testmo/testmo-cli |
| 103 | + export TESTMO_TOKEN=${{ secrets.TESTMO_TEST_TOKEN }} |
| 104 | + TESTMO_URL="https://neuralmagic.testmo.net" |
| 105 | + todaytime=`date +%Y%m%d` |
| 106 | + name="${{ github.event.repository.name }} ${{ inputs.build_type }} ${todaytime} ${{ needs.BUILD.outputs.commitid }} RunID:${{ inputs.run_id }}" |
| 107 | + echo "========== Build info ===========" |
| 108 | + echo "name: ${name}" |
| 109 | + echo "build status: ${{ needs.BUILD.outputs.status }}" |
| 110 | + echo "<status>${{ needs.BUILD.outputs.status }}</status>" > result.xml |
| 111 | + exit_code=1 |
| 112 | + if [[ "${{ needs.BUILD.outputs.status }}" = "success" ]]; then |
| 113 | + exit_code=0 |
| 114 | + fi |
| 115 | + echo "echo \"GHA job ${{ needs.BUILD.outputs.status }}: https://github.com/neuralmagic/${{ github.event.repository.name }}/actions/runs/${{ inputs.run_id }}\"; exit ${exit_code}" > result.sh |
| 116 | + echo "========== Report to testmo ===========" |
| 117 | + echo "testmo automation:run:submit \\" |
| 118 | + echo " --instance ${TESTMO_URL} \\" |
| 119 | + echo " --project-id ${{ inputs.testmo_project_id }} \\" |
| 120 | + echo " --name ${name} \\" |
| 121 | + echo " --source ${{ github.event.repository.name }} \\" |
| 122 | + echo " --results result.xml" |
| 123 | + testmo automation:run:submit \ |
| 124 | + --instance "${TESTMO_URL}" \ |
| 125 | + --project-id ${{ inputs.testmo_project_id }} \ |
| 126 | + --name "${name}" \ |
| 127 | + --source "${{ github.event.repository.name }}" \ |
| 128 | + --results result.xml \ |
| 129 | + -- bash result.sh |
0 commit comments