|
| 1 | +name: snphost CI PR test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: |
| 6 | + - reopened |
| 7 | + - opened |
| 8 | + - edited |
| 9 | + - synchronize |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + pull_request_number: |
| 13 | + description: 'Specify the pull request number' |
| 14 | + pull_request_branch: |
| 15 | + description: 'Specify pull request source branch' |
| 16 | + |
| 17 | +jobs: |
| 18 | + host_firmware_tests: |
| 19 | + runs-on: self-hosted |
| 20 | + steps: |
| 21 | + - name: Checkout Repository |
| 22 | + uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - name: Verify if SNP is enabled on the host |
| 25 | + run: | |
| 26 | + source ./.github/workflows/snp_function_declarations.sh |
| 27 | + verify_snp_host |
| 28 | +
|
| 29 | + - name: Set the PR number and PR branch environment based on GH Action event type |
| 30 | + run: | |
| 31 | + event_pr_number='' |
| 32 | + event_pr_branch='' |
| 33 | +
|
| 34 | + if [ ${{ github.event_name }} == "pull_request_target" ]; then |
| 35 | + event_pr_number=${{ github.event.pull_request.number }} |
| 36 | + event_pr_branch=${{ github.event.pull_request.head.ref }} |
| 37 | + elif [ ${{ github.event_name }} == "workflow_dispatch" ]; then |
| 38 | + event_pr_number=${{ github.event.inputs.pull_request_number }} |
| 39 | + event_pr_branch=${{ github.event.inputs.pull_request_branch }} |
| 40 | + fi |
| 41 | +
|
| 42 | + echo "pr_number=${event_pr_number}" >> $GITHUB_ENV |
| 43 | + echo "pr_branch=${event_pr_branch}" >> $GITHUB_ENV |
| 44 | +
|
| 45 | + - name: Show the GH environment variable current values |
| 46 | + run: | |
| 47 | + echo "GH Action PR number = ${{ env.pr_number }}" |
| 48 | + echo "GH Action PR branch = ${{ env.pr_branch }}" |
| 49 | +
|
| 50 | + - name: Run snphost cargo test on the host |
| 51 | + run: | |
| 52 | + set -e |
| 53 | +
|
| 54 | + # Check and install dependencies on the host |
| 55 | + source ./.github/workflows/snp_function_declarations.sh |
| 56 | + check_rust_on_host |
| 57 | +
|
| 58 | + cd ${HOME}/ |
| 59 | + git clone https://github.com/LakshmiSaiHarika/snphost.git |
| 60 | + cd ./snphost |
| 61 | +
|
| 62 | + # Checkout the PR branch |
| 63 | + if [[ ${{ github.event_name }} == "pull_request_target" || ${{ github.event_name }} == "workflow_dispatch" ]]; then |
| 64 | + git fetch origin pull/${{ env.pr_number }}/head:${{ env.pr_branch }} |
| 65 | + git switch ${{ env.pr_branch }} |
| 66 | + fi |
| 67 | +
|
| 68 | + # Perform cargo test on the host |
| 69 | + cargo test |
| 70 | +
|
| 71 | + - name: snphost post cleanup tasks |
| 72 | + if: always() |
| 73 | + run: rm -rf ${HOME}/snphost |
| 74 | + |
0 commit comments