Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snphost CI PR test #91

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/snp_function_declarations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

verify_snp_host() {
local AMDSEV_URL="https://github.com/LakshmiSaiHarika/AMDSEV.git"
local AMDSEV_DEFAULT_BRANCH="fedora-build-install-upstream-kernel"

if ! sudo dmesg | grep -i "SEV-SNP enabled" 2>&1 >/dev/null; then
echo -e "SEV-SNP not enabled on the host. Please follow these steps to enable:\n\
$(echo "${AMDSEV_URL}" | sed 's|\.git$||g')/tree/${AMDSEV_DEFAULT_BRANCH}#prepare-host"
return 1
fi
}

check_rust_on_host() {
# Install Rust on the host
source "${HOME}/.cargo/env" 2>/dev/null || true
if ! command -v rustc &> /dev/null; then
echo "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -sSf | sh -s -- -y
source "${HOME}/.cargo/env" 2>/dev/null
fi
}

83 changes: 83 additions & 0 deletions .github/workflows/snphost_ci_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: snphost CI PR test

on:
pull_request_target:
types:
- reopened
- opened
- edited
- synchronize
workflow_dispatch:
inputs:
pull_request_number:
description: 'Specify the pull request number'
pull_request_branch:
description: 'Specify pull request source branch'

jobs:
host_firmware_tests:
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Show the active SNP host kernel version on the host
run: uname -r

- name: Check if SNP is enabled on the host
run: |
set -e
source ./.github/workflows/snp_function_declarations.sh
verify_snp_host

- name: Set the PR number and PR branch environment based on GH Action event type
run: |
event_pr_number=''
event_pr_branch=''

if [ ${{ github.event_name }} == "pull_request_target" ]; then
event_pr_number=${{ github.event.pull_request.number }}
event_pr_branch=${{ github.event.pull_request.head.ref }}
elif [ ${{ github.event_name }} == "workflow_dispatch" ]; then
event_pr_number=${{ github.event.inputs.pull_request_number }}
event_pr_branch=${{ github.event.inputs.pull_request_branch }}
fi

echo "pr_number=${event_pr_number}" >> $GITHUB_ENV
echo "pr_branch=${event_pr_branch}" >> $GITHUB_ENV

- name: Show the GH environment variable current values
run: |
echo "GH Action PR number = ${{ env.pr_number }}"
echo "GH Action PR branch = ${{ env.pr_branch }}"

- name: Run snphost cargo test on the host
run: |
set -e

# Check and install dependencies on the host
source ./.github/workflows/snp_function_declarations.sh
check_rust_on_host

cd ${HOME}/
git clone https://github.com/LakshmiSaiHarika/snphost.git
cd ./snphost

# Checkout the PR branch
if [[ ${{ github.event_name }} == "pull_request_target" || ${{ github.event_name }} == "workflow_dispatch" ]]; then
git fetch origin pull/${{ env.pr_number }}/head:${{ env.pr_branch }}
git switch ${{ env.pr_branch }}
fi

# Perform cargo test on the host
cargo test

- name: snphost post cleanup tasks
if: always()
run: rm -rf ${HOME}/snphost

# Update this workflow title dynamically with PR details
run-name: |
${{ (startsWith(github.event_name, 'workflow_dispatch') && format('snphost PR CI test for PR #{0}/PR source branch({1})', github.event.inputs.pull_request_number, github.event.inputs.pull_request_branch)) ||
(startsWith(github.event_name, 'pull_request') && format('{0}', github.event.pull_request.title )) }}

Loading