microsoft/openvmm
Publicmirrored fromhttps://github.com/microsoft/openvmmAvailable
.github/workflows/upload-petri-results.yml
115lines · modecode
| 1 | name: Upload Petri Test Results |
| 2 | |
| 3 | on: |
| 4 | workflow_run: |
| 5 | types: |
| 6 | - completed |
| 7 | workflows: |
| 8 | - 'OpenVMM CI' |
| 9 | - 'OpenVMM PR' |
| 10 | - '\[Optional\] OpenVMM Release PR' |
| 11 | |
| 12 | permissions: |
| 13 | id-token: write |
| 14 | contents: read |
| 15 | actions: read # Needed to download artifacts from other runs |
| 16 | pull-requests: write # Needed to create PR comments |
| 17 | |
| 18 | jobs: |
| 19 | upload-logs: |
| 20 | # Only attempt upload if the workflow run could have actually produced some artifacts |
| 21 | if: >- |
| 22 | ${{ |
| 23 | github.event.workflow_run.conclusion == 'success' || |
| 24 | github.event.workflow_run.conclusion == 'failure' || |
| 25 | github.event.workflow_run.conclusion == 'timed_out' |
| 26 | }} |
| 27 | runs-on: ubuntu-latest |
| 28 | env: |
| 29 | BASE_URL: https://openvmmghtestresults.blob.core.windows.net/results |
| 30 | |
| 31 | steps: |
| 32 | - name: Free Disk Space (Ubuntu) |
| 33 | uses: jlumbroso/free-disk-space@v1.3.1 |
| 34 | with: |
| 35 | # Azure CLI is considered a large package |
| 36 | large-packages: false |
| 37 | |
| 38 | - name: Authenticate to Azure |
| 39 | uses: azure/login@v1 |
| 40 | with: |
| 41 | client-id: ${{ secrets.OPENVMM_TEST_RESULT_CLIENT_ID }} |
| 42 | tenant-id: ${{ secrets.OPENVMM_TENANT_ID }} |
| 43 | subscription-id: ${{ secrets.OPENVMM_SUBSCRIPTION_ID }} |
| 44 | |
| 45 | - name: Download matching artifacts |
| 46 | run: | |
| 47 | if [ "$event" = "pull_request" ]; then |
| 48 | # Get the associated PR number. Work around GitHub Actions often not |
| 49 | # populating the `pull_requests` array. See |
| 50 | # <https://github.com/orgs/community/discussions/25220>. |
| 51 | pr=$(gh pr view --repo "${repo}" "${head_branch}" --json number --jq .number) |
| 52 | echo "SOURCE_PR=$pr" >> "$GITHUB_ENV" |
| 53 | else |
| 54 | echo "SOURCE_PR=" >> "$GITHUB_ENV" |
| 55 | fi |
| 56 | mkdir -p results |
| 57 | gh run \ |
| 58 | -R "$repo" \ |
| 59 | download "$run_id" \ |
| 60 | -p "*-vmm-tests-logs" \ |
| 61 | -D results |
| 62 | test_count=$(find results -name petri.jsonl | wc -l) |
| 63 | PASS_COUNT=$(find results -name petri.passed | wc -l) |
| 64 | FAIL_COUNT=$((test_count - PASS_COUNT)) |
| 65 | echo "FAIL_COUNT=$FAIL_COUNT" >> "$GITHUB_ENV" |
| 66 | echo "PASS_COUNT=$PASS_COUNT" >> "$GITHUB_ENV" |
| 67 | echo "SOURCE_BRANCH=$head_branch" >> "$GITHUB_ENV" |
| 68 | env: |
| 69 | event: ${{ github.event.workflow_run.event }} |
| 70 | repo: ${{ github.event.workflow_run.repository.full_name }} |
| 71 | run_id: ${{ github.event.workflow_run.id }} |
| 72 | # If the PR is from a fork, prefix it with `<owner-login>:`. |
| 73 | head_branch: |- |
| 74 | ${{ |
| 75 | (github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login) |
| 76 | && format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) |
| 77 | || github.event.workflow_run.head_branch |
| 78 | }} |
| 79 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | |
| 81 | - name: Upload to Azure Blob Storage |
| 82 | run: | |
| 83 | az storage blob upload-batch \ |
| 84 | --destination "$BASE_URL" \ |
| 85 | --destination-path "$run_id" \ |
| 86 | --source results \ |
| 87 | --auth-mode login |
| 88 | |
| 89 | # Store a metadata blob in a separate portion of the hierarchy so that |
| 90 | # it can be cheaply queried. |
| 91 | az storage blob upload \ |
| 92 | --blob-url "$BASE_URL/runs/$run_id" \ |
| 93 | --file /dev/null \ |
| 94 | --metadata \ |
| 95 | "petrifailed=$FAIL_COUNT" \ |
| 96 | "petripassed=$PASS_COUNT" \ |
| 97 | "ghbranch=$SOURCE_BRANCH" \ |
| 98 | "ghpr=$SOURCE_PR" \ |
| 99 | --auth-mode login |
| 100 | env: |
| 101 | run_id: ${{ github.event.workflow_run.id }} |
| 102 | |
| 103 | - name: Report failing tests |
| 104 | if: ${{ env.SOURCE_PR && env.FAIL_COUNT > 0 }} |
| 105 | run: | |
| 106 | gh pr comment \ |
| 107 | -R "$repo" \ |
| 108 | "$SOURCE_PR" \ |
| 109 | -F - <<EOF |
| 110 | [At least one Petri test failed.](https://openvmm.dev/test-results/#/runs/$run_id) |
| 111 | EOF |
| 112 | env: |
| 113 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 114 | repo: ${{ github.event.workflow_run.repository.full_name }} |
| 115 | run_id: ${{ github.event.workflow_run.id }} |
| 116 | |