2021-08-31 14:30:12 +00:00
|
|
|
# This workflow will build HIRS, run unit tests, and create HIRS artifacts
|
2023-08-15 21:10:34 +00:00
|
|
|
# Updated: 8/15/23
|
2021-08-31 14:30:12 +00:00
|
|
|
|
|
|
|
name: HIRS Build and Unit Test
|
|
|
|
|
2021-09-02 19:18:20 +00:00
|
|
|
on:
|
2023-08-15 21:10:34 +00:00
|
|
|
# Runs this workflow whenever there is a push to main from a branch annotated with "v3"
|
2021-08-31 14:30:12 +00:00
|
|
|
push:
|
2023-06-23 14:52:49 +00:00
|
|
|
branches:
|
2023-08-15 21:10:34 +00:00
|
|
|
- '*v3*'
|
|
|
|
- 'main'
|
|
|
|
# Allows you to run this workflow manually from the Actions tab
|
2021-08-31 14:30:12 +00:00
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
2023-08-15 21:10:34 +00:00
|
|
|
# Run the unit tests and package HIRS ACA, provisoner, and tools
|
|
|
|
ACA_Provisioner_Unit_Tests:
|
|
|
|
runs-on: ubuntu-latest # Configures the job to run on the latest version of an Ubuntu Linux runner
|
2021-08-31 14:30:12 +00:00
|
|
|
steps:
|
2023-08-15 21:10:34 +00:00
|
|
|
- uses: actions/checkout@v3 # run v3 of actions/checkout action, which checks out your repository onto the runner
|
|
|
|
# Build will archive build reports and will create a failedFile if build is not successful
|
|
|
|
- name: Directory setup
|
2021-08-31 14:30:12 +00:00
|
|
|
run: |
|
2023-08-15 21:10:34 +00:00
|
|
|
mkdir -p artifacts/githubActionsResults
|
2023-08-18 13:20:18 +00:00
|
|
|
mkdir -p artifacts/upload_reports/HIRS_AttestationCA
|
|
|
|
mkdir -p artifacts/upload_reports/HIRS_AttestationCAPortal
|
|
|
|
mkdir -p artifacts/upload_reports/HIRS_Provisioner
|
|
|
|
mkdir -p artifacts/upload_reports/HIRS_ProvisionerTPM2
|
|
|
|
mkdir -p artifacts/upload_reports/HIRS_Structs
|
|
|
|
mkdir -p artifacts/upload_reports/HIRS_Utils
|
|
|
|
mkdir -p artifacts/upload_reports/tcg_rim_tool
|
|
|
|
mkdir -p artifacts/upload_reports/tcg_eventlog_tool
|
2023-08-15 21:10:34 +00:00
|
|
|
# Run the provisioner and ACA unit tests via gradle build in a Rocky Docker container
|
|
|
|
- name: Build HIRS and run unit tests
|
2021-08-31 14:30:12 +00:00
|
|
|
run: |
|
2023-08-15 21:10:34 +00:00
|
|
|
|
|
|
|
# log into and run docker (note: must set up secrets in github for ghcr username and access_token)
|
|
|
|
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $ --password-stdin
|
|
|
|
|
|
|
|
# docker run options:
|
|
|
|
# create a mount between curr directory on the runner and the HIRS folder created by the cloning of HIRS repo
|
|
|
|
# -v $(pwd):/HIRS
|
|
|
|
# image used for the container, given by <repository>:<tag_name>
|
|
|
|
# rocky8: ghcr.io/nsacyber/hirs/hirs-rocky8-ci:latest [repo: https://github.com/orgs/nsacyber/packages]
|
|
|
|
# bash commands to clean/build/test each subproject
|
|
|
|
# /bin/bash -c '<commands>'
|
|
|
|
docker run --rm \
|
|
|
|
-v $(pwd):/HIRS \
|
|
|
|
ghcr.io/nsacyber/hirs/hirs-rocky8-ci:latest /bin/bash -c \
|
|
|
|
'pushd /HIRS
|
|
|
|
gradle_status=0
|
|
|
|
|
|
|
|
# git added a feature that gives error if user is not owner of the top-level directory; need to override this
|
|
|
|
git config --global --add safe.directory /HIRS
|
|
|
|
|
|
|
|
# clean, build and run unit tests on all sub-projects; copy build reports to an artifacts directory
|
|
|
|
./gradlew :HIRS_AttestationCA:clean :HIRS_AttestationCA:build :HIRS_AttestationCA:test
|
|
|
|
if (( $? != "0" )) ; then gradle_status=1; fi
|
2023-08-18 13:20:18 +00:00
|
|
|
#cp -r /HIRS/HIRS_AttestationCA/build/reports/ /HIRS/artifacts/upload_reports/HIRS_AttestationCA/.
|
2023-08-15 21:10:34 +00:00
|
|
|
./gradlew :HIRS_AttestationCAPortal:clean :HIRS_AttestationCAPortal:build :HIRS_AttestationCAPortal:test
|
|
|
|
if (( $? != "0" )) ; then gradle_status=1; fi
|
2023-08-18 13:20:18 +00:00
|
|
|
#cp -r /HIRS/HIRS_AttestationCAPortal/build/reports/ /HIRS/artifacts/upload_reports/HIRS_AttestationCAPortal/.
|
2023-08-15 21:10:34 +00:00
|
|
|
#./gradlew :HIRS_Provisioner:clean :HIRS_Provisioner:build :HIRS_Provisioner:test
|
|
|
|
#if (( $? != "0" )) ; then gradle_status=1; fi
|
2023-08-18 13:20:18 +00:00
|
|
|
#cp -r /HIRS/HIRS_Provisioner/build/reports/ /HIRS/artifacts/upload_reports/HIRS_Provisioner/.
|
2023-08-15 21:10:34 +00:00
|
|
|
#./gradlew :HIRS_ProvisionerTPM2:clean :HIRS_ProvisionerTPM2:build :HIRS_ProvisionerTPM2:test
|
|
|
|
#if (( $? != "0" )) ; then gradle_status=1; fi
|
2023-08-18 13:20:18 +00:00
|
|
|
#cp -r /HIRS/HIRS_ProvisionerTPM2/docs/ /HIRS/artifacts/upload_reports/HIRS_ProvisionerTPM2/.
|
2023-08-15 21:10:34 +00:00
|
|
|
#./gradlew :HIRS_Structs:clean :HIRS_Structs:build :HIRS_Structs:test
|
|
|
|
#if (( $? != "0" )) ; then gradle_status=1; fi
|
2023-08-18 13:20:18 +00:00
|
|
|
#cp -r /HIRS/HIRS_Structs/build/reports/ /HIRS/artifacts/upload_reports/HIRS_Structs/.
|
2023-08-15 21:10:34 +00:00
|
|
|
./gradlew :HIRS_Utils:clean :HIRS_Utils:build :HIRS_Utils:test
|
|
|
|
if (( $? != "0" )) ; then gradle_status=1; fi
|
2023-08-18 13:20:18 +00:00
|
|
|
cp -r /HIRS/HIRS_Utils/build/reports/ /HIRS/artifacts/upload_reports/HIRS_Utils/.
|
2023-08-15 21:10:34 +00:00
|
|
|
#./gradlew :TPM_Utils:clean :TPM_Utils:build :TPM_Utils:test
|
|
|
|
#if (( $? != "0" )) ; then gradle_status=1; fi
|
|
|
|
|
|
|
|
# Create "fail file" to fail the Build ACA tests if gradle exited with anything other than 0
|
|
|
|
if (( $gradle_status == "0" )) ; then
|
|
|
|
echo "In docker: Build Passed"
|
|
|
|
else
|
|
|
|
echo "In docker: Build Failed"
|
|
|
|
touch /HIRS/artifacts/githubActionsResults/buildFailed.txt
|
|
|
|
fi; popd;'
|
|
|
|
# Upload build report files
|
|
|
|
- name: Archive report files
|
|
|
|
uses: actions/upload-artifact@v3
|
2021-08-31 14:30:12 +00:00
|
|
|
with:
|
|
|
|
name: HIRS_Build_Reports
|
2023-08-18 13:20:18 +00:00
|
|
|
path: artifacts/upload_reports/*
|
2021-08-31 14:30:12 +00:00
|
|
|
if-no-files-found: ignore
|
2023-08-15 21:10:34 +00:00
|
|
|
# If buildFailed file exists, use that to fail the ACA unit tests
|
2023-08-18 13:26:14 +00:00
|
|
|
- name: Check if build/test passed or failed
|
2023-08-15 21:10:34 +00:00
|
|
|
if: ${{ hashFiles('artifacts/githubActionsResults/buildFailed.txt') != '' }}
|
|
|
|
uses: actions/github-script@v6
|
2021-08-31 14:30:12 +00:00
|
|
|
with:
|
2023-08-15 21:10:34 +00:00
|
|
|
script: |
|
|
|
|
core.setFailed('Build or Unit Test Failed')
|