Mu QEMU PR Validation #400
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Runs QEMU-based platform validation on pull requests. | |
| # | |
| # Triggered by the completion of the "CLANGPDB Package CI" workflow. | |
| # | |
| # Gathers PR metadata and calls the reusable MuPrValidation workflow in | |
| # mu_devops to build and boot mu_basecore changes on QEMU Q35 and SBSA. | |
| # | |
| # Copyright (c) Microsoft Corporation. | |
| # SPDX-License-Identifier: BSD-2-Clause-Patent | |
| ## | |
| name: Mu QEMU PR Validation | |
| on: | |
| workflow_run: | |
| workflows: ["CLANGPDB Package CI"] | |
| types: ["completed"] | |
| concurrency: | |
| group: mu-qemu-pr-${{ github.event.workflow_run.head_branch }} | |
| cancel-in-progress: true | |
| permissions: | |
| actions: read | |
| contents: read | |
| pull-requests: read | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| name: Gather PR Metadata | |
| if: | | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'pull_request' | |
| outputs: | |
| pr_number: ${{ steps.pr-info.outputs.pr_number }} | |
| skip: ${{ steps.pr-info.outputs.skip }} | |
| skip_reason: ${{ steps.pr-info.outputs.skip_reason }} | |
| steps: | |
| - name: Get PR Information | |
| id: pr-info | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| HEAD_REF: ${{ github.event.workflow_run.head_branch }} | |
| HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} | |
| run: | | |
| owner="${HEAD_REPO%%/*}" | |
| pr_number=$(gh api "repos/${GITHUB_REPOSITORY}/pulls" \ | |
| --method GET -f state=open -f head="${owner}:${HEAD_REF}" \ | |
| --jq '.[0].number') | |
| if [[ -z "$pr_number" || "$pr_number" == "null" ]]; then | |
| echo "::notice::No open PR found for head $owner:$HEAD_REF." | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| closed_pr_json=$(gh api "repos/${GITHUB_REPOSITORY}/pulls" \ | |
| --method GET -f state=closed -f head="${owner}:${HEAD_REF}" \ | |
| -f sort=updated -f direction=desc -f per_page=1 \ | |
| --jq '.[0] | select(. != null) | {number, merged: (.merged_at != null)}') | |
| if [[ -n "$closed_pr_json" ]]; then | |
| closed_pr_number=$(echo "$closed_pr_json" | jq -r '.number') | |
| closed_pr_merged=$(echo "$closed_pr_json" | jq -r '.merged') | |
| echo "pr_number=$closed_pr_number" >> "$GITHUB_OUTPUT" | |
| if [[ "$closed_pr_merged" == "true" ]]; then | |
| echo "::notice::PR #$closed_pr_number was merged before validation started." | |
| echo "skip_reason=merged" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "::notice::PR #$closed_pr_number was closed before validation started." | |
| echo "skip_reason=closed" >> "$GITHUB_OUTPUT" | |
| fi | |
| else | |
| echo "::notice::No PR (open or closed) found for head $owner:$HEAD_REF." | |
| echo "skip_reason=branch_unavailable" >> "$GITHUB_OUTPUT" | |
| fi | |
| exit 0 | |
| fi | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "::group::PR Information" | |
| echo " - PR Number: $pr_number" | |
| echo " - Head SHA: $HEAD_SHA" | |
| echo " - Head Ref: $HEAD_REF" | |
| echo " - Source: $HEAD_REPO" | |
| echo "::endgroup::" | |
| echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT" | |
| upload-skip-metadata: | |
| name: Upload Skip Metadata | |
| runs-on: ubuntu-latest | |
| needs: [prepare] | |
| if: needs.prepare.outputs.skip == 'true' && needs.prepare.outputs.pr_number != '' | |
| steps: | |
| - name: Create Skip Metadata | |
| shell: bash | |
| run: | | |
| mkdir -p metadata | |
| cat > metadata/pr-metadata.json <<EOF | |
| { | |
| "pr_number": ${{ needs.prepare.outputs.pr_number }}, | |
| "skipped": true, | |
| "skip_reason": "${{ needs.prepare.outputs.skip_reason }}" | |
| } | |
| EOF | |
| - name: Upload PR Metadata | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: mu-qemu-pr-metadata | |
| path: metadata/pr-metadata.json | |
| qemu-pr-validation: | |
| name: Run Mu QEMU Validation | |
| needs: [prepare] | |
| if: needs.prepare.result == 'success' && needs.prepare.outputs.skip != 'true' | |
| uses: microsoft/mu_devops/.github/workflows/MuPrValidation.yml@main | |
| with: | |
| app-id: ${{ vars.MU_ACCESS_APP_ID }} | |
| caller-ref: ${{ github.event.workflow_run.head_sha }} | |
| caller-repo: ${{ github.repository }} | |
| caller-repo-name: mu_basecore | |
| head-sha: ${{ github.event.workflow_run.head_sha }} | |
| pr-number: ${{ fromJSON(needs.prepare.outputs.pr_number) }} | |
| submodule-path: MU_BASECORE | |
| secrets: | |
| private-key: ${{ secrets.MU_ACCESS_APP_PRIVATE_KEY }} |