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 Pull Request Workflow #414

Merged
merged 80 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
f0fdb31
New workflows, new collateral, and updates to pull-request action
calebofearth Feb 8, 2024
6f1ca43
Syntax fix
calebofearth Feb 8, 2024
c13c180
Add runs-on for jobs
calebofearth Feb 8, 2024
30fc41a
Syntax fix
calebofearth Feb 8, 2024
3c6c281
Add repo checkout to PR workflow
calebofearth Feb 8, 2024
62c858c
Update to checkout@v4
calebofearth Feb 8, 2024
9bf18c5
Checkout in each job
calebofearth Feb 8, 2024
af272fa
Checkout in each job
calebofearth Feb 8, 2024
e3e1f6c
Remove checkout dependency
calebofearth Feb 8, 2024
b92c663
Use push trigger to make workflow visible
calebofearth Feb 8, 2024
f7ceafb
Use push trigger to make workflow visible
calebofearth Feb 8, 2024
438c773
Fix jobs::uses syntax
calebofearth Feb 9, 2024
e5888b6
Update env setting prerequisites for lic header check
calebofearth Feb 9, 2024
0d652a9
Add lic header, waive PR collateral from license header check
calebofearth Feb 9, 2024
4c2a2ac
Sed to strip leading path from file list entries
calebofearth Feb 9, 2024
296cca6
Add check -- for Pull Requests only -- on compile.yml modification
calebofearth Feb 9, 2024
0be79b3
Rename license header check script
calebofearth Feb 9, 2024
f4b0991
Use head_ref to refer to the source branch
calebofearth Feb 9, 2024
159ef87
Quote shell variables
calebofearth Feb 9, 2024
686acec
Single-quotes inside expressions
calebofearth Feb 9, 2024
38881c9
Checkout all history to compare base/head refs
calebofearth Feb 9, 2024
f60d051
Ref full remote branch name
calebofearth Feb 9, 2024
c7ef018
tmp: debug echo
calebofearth Feb 9, 2024
b5f4f3b
Remove aes_secworks references
calebofearth Feb 9, 2024
57a86ff
Use base of ref instead of full rev
calebofearth Feb 9, 2024
f4b7c2c
Make executable
calebofearth Feb 9, 2024
e330fb6
Remove tmp features from pipeline
calebofearth Feb 9, 2024
926fb66
Consolidate hashing code; add informative prints
calebofearth Feb 9, 2024
b11a445
Add script to stamp repo for Pull Requests and commit updated timesta…
calebofearth Feb 9, 2024
3e39f0f
Add lic header
calebofearth Feb 9, 2024
cfb808c
Add informative instructional message
calebofearth Feb 9, 2024
33d14f7
Install peakrdl for rdl check; add input param for dispatch run; pass…
calebofearth Feb 9, 2024
8f2c688
Syntax fix -- '' vs ""
calebofearth Feb 9, 2024
10500ba
Re-stamp repo
calebofearth Feb 9, 2024
894d064
Add orig file_list to compare and debug hash mismatch
calebofearth Feb 9, 2024
98c8abc
Rename rtl_hash script to be more accurate
calebofearth Feb 9, 2024
2ab0326
Typo fix
calebofearth Feb 9, 2024
8788723
README fix
calebofearth Feb 9, 2024
8ce2b79
README updates
calebofearth Feb 9, 2024
f85e17d
Use numeric sort on files to resolve sort discrepancy between local e…
calebofearth Feb 9, 2024
f5067c9
LC_COLLATE when sorting to resolve discrepancies
calebofearth Feb 9, 2024
9c27ae2
Update file_list used to stamp repo
calebofearth Feb 9, 2024
6f809d4
Re-stamp repo
calebofearth Feb 9, 2024
653bb7d
Remove local copy of file_list for PR stamp
calebofearth Feb 9, 2024
af785f9
Add more error checking in pull request scripts
calebofearth Feb 9, 2024
c6e62aa
Parameter expansion to protect against unbound var
calebofearth Feb 9, 2024
a6b0106
Restamp repo
calebofearth Feb 9, 2024
f08be38
Fetch-depth 0 to fetch all refs for comparison in RDL checker job
calebofearth Feb 9, 2024
4d52ebc
Fix to prevent grep with no matches from killing the script as error
calebofearth Feb 9, 2024
6d5a382
stamp repo
calebofearth Feb 9, 2024
f989075
More comprehensive file list for repo stamp check
calebofearth Feb 10, 2024
9d1a181
stamp repo
calebofearth Feb 10, 2024
a67c3bf
Add success message
calebofearth Feb 10, 2024
e683a13
Restamp repo
calebofearth Feb 10, 2024
3c94979
Omit .git directory from file list find command
calebofearth Feb 10, 2024
2ffbf30
Re-stamp repo
calebofearth Feb 10, 2024
d15ec9f
Permanently remove pull_request as trigger for reusable called workflows
calebofearth Feb 10, 2024
3586ff9
stamp repo
calebofearth Feb 10, 2024
a116196
Add instructional prints in case of hash check failure
calebofearth Mar 15, 2024
d0cfbff
Add env check at script start
calebofearth Mar 19, 2024
3bab4c2
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 20, 2024
68c2edc
Clobber file_list.txt at end of check
calebofearth Mar 20, 2024
909e40e
Print full file list
calebofearth Mar 20, 2024
b21c7c6
Manual stamp repo
calebofearth Mar 20, 2024
4d2fc02
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 20, 2024
ac10d3c
Updated info in README regarding how to commit the final stamp files,…
calebofearth Mar 21, 2024
0043708
Revert full file-list printout back to the first five files only
calebofearth Mar 21, 2024
468b08e
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 21, 2024
18b150c
Remove pre_run job as a dependency for Verilator/Doc gen workflows
calebofearth Mar 28, 2024
8e0d230
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 28, 2024
29752c0
Add exception for Microsoft Engineers on compile.yml check
calebofearth Mar 29, 2024
a97355a
Syntax fix on env var
calebofearth Mar 29, 2024
d2f9012
Use env vars in-line in bash script to validate contributor ID so arr…
calebofearth Mar 29, 2024
6612389
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 29, 2024
86435c6
Re-enable random UVM regression (limited) as part of promote validation
calebofearth Mar 29, 2024
63bb592
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 29, 2024
23bf7ce
Update peakrdl tool versions and improve RDL file check for PR workflow
calebofearth Mar 29, 2024
2a27979
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Mar 30, 2024
2561a50
Update timestamp in README
calebofearth Apr 1, 2024
c2cb345
MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pipeline-hash-ch…
calebofearth Apr 1, 2024
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
67 changes: 67 additions & 0 deletions .github/scripts/file_hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# DESCRIPTION:
# ====================================
# This tool is used to generate a hash over the Caliptra source code files
# This can be used to verify the hash of the code for which internal workflows were
# run prior to submission to the caliptra-rtl repo.
#
# Usage: file_hash.sh <path_to_rtl_src_dir> <file_list>
# path_to_rtl_src_dir Path to the root directory of the caliptra RTL repo.
# file_list This list of all the files that should be included in the hash
# is generated
#
# Exit and report failure if anything fails
set -euo pipefail

# Check arg count
if [ $# -ne 2 ]
then
echo "Usage: $(basename $0) <path_to_caliptra_root> <file_list>"
exit -1
fi

# Get args
rtl_path=$1

# Read expected file list, prepend rtl path, and store in array
IFS=$'\n' expected_file_list=($(cat "$2" | sed "s@^@""$rtl_path""/@"))

# Make sure all files exist
missing_files=0
for file in "${expected_file_list[@]}"
do
# Check if the file is missing
if ! test -f "$file"; then
# Report any missing files (and keep count)
if [ "$missing_files" -eq 0 ]; then
echo "Missing expected files: "
fi
missing_files=$(($missing_files + 1))
echo " $file"
fi
done

# Calculate the hash (only if no files were missing)
if [ "$missing_files" -eq 0 ]; then
hash=$(cat "${expected_file_list[@]}" | sha384sum | tr -d "\n *-")
echo "$hash"
else
echo "Failed to generate code hash"
exit -1
fi

99 changes: 99 additions & 0 deletions .github/scripts/license_header_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

function show_usage() {
printf "Usage: $0 [optional [parameters]]\n"
printf "\n"
printf "Options:\n"
printf " -i|--insertHeader\tInsert license header in files missing it (Currently unavailable) \n"
printf " -h|--help\tShow usage information\n"

return 0
}

set -euo pipefail

apacheLicenseHeader="# SPDX-License-Identifier: Apache-2.0
#
#
# Licensed under the Apache License, Version 2.0 (the \"License\");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an \"AS IS\" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License."

apacheLicenseHeader_v_c="//********************************************************************************
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 Western Digital Corporation or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the \"License\");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an \"AS IS\" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//********************************************************************************"

while [[ ! -z "${1:+empty}" ]]; do
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
show_usage
#elif [[ "$1" == "-i" ]] || [[ "$1" == "--insertHeader"]]; then
# insHeader=1
# shift
fi
shift
done

if [[ -z ${CALIPTRA_ROOT:+"empty"} ]]; then
echo "Must set CALIPTRA_ROOT prior to running script"
exit 1
fi

exclude_dir='{uvmf*,.git,cmark,caliptra_reg_html,caliptra_top_reg_html,sha256,sha512,sha512_masked,doe,fw_test_*,__pycache__,templates,docs}'
exclude_suffix='*.{tcl,txt,js,htm,html,json,vf,yml,woff,rsp,rdl,bashrc,waiver,cfg,hex,rc,exe,pdf,png,hvp,svg,log}'
exclude_regs='*_reg*.{sv,rdl}'
exclude_csr='*_csr*.*'
exclude_file='{sglint_waivers,pr_hash,pr_timestamp,.git-comodules,.gitignore,spyglass_lint.policy,ascent.ctl,clp_mapfile,readme.md,README.md,SECURITY.md,c_sample.c}'
apache_patn='Licensed under the Apache License'

# Recursive find through repository with some major exclusions
# 'eval' is used to expand exclude vars into a usable glob pattern
files_missing_header=$(eval grep -r -L -i --exclude-dir=${exclude_dir} --exclude=${exclude_suffix} --exclude=${exclude_regs} --exclude=${exclude_csr} --exclude=${exclude_file} \"${apache_patn}\" "${CALIPTRA_ROOT}")

# After excluding some crypto directories, re-scan specific directories therein
# (can't specificy exclude-dir using '<patn>/<patn>' to catch nested directories)
files_missing_header="${files_missing_header:+$files_missing_header }$(eval grep -r -L -i --exclude-dir={rtl,uvmf_*} --exclude={aes_tb.v,doe_tb.v,sha256_tb.v} --exclude=${exclude_suffix} --exclude=${exclude_regs} --exclude=${exclude_csr} --exclude=${exclude_file} \"${apache_patn}\" \"${CALIPTRA_ROOT}/src/sha256\" \"${CALIPTRA_ROOT}/src/sha512\" \"${CALIPTRA_ROOT}/src/sha512_masked\" \"${CALIPTRA_ROOT}/src/doe\")"

if [[ $files_missing_header != "" ]]; then
echo -e "\n\n\tPlease add Apache license header to the following files and try again. \n"
for file in $files_missing_header; do
echo -e "\t\e[1;31m $file \e[0m\n"
done
exit 1
fi
echo "Apache license header check completed successfully"
59 changes: 59 additions & 0 deletions .github/scripts/pr_rdl_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SPDX-License-Identifier: Apache-2.0
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -euo pipefail

if [[ $# -ne 1 ]]; then
echo "Error, requires branch name argument"
exit 1
else
merge_dest=$1
fi

if ! git show-ref --quiet "${merge_dest}"; then
echo "Could not find ref named [${merge_dest}]"
exit 1
fi

if [[ -z "${CALIPTRA_ROOT:+"empty"}" ]]; then
echo "Error, must set CALIPTRA_ROOT"
exit 1
fi
cd "${CALIPTRA_ROOT}"

rdl_mod_count=$(git diff --merge-base "${merge_dest}" --name-only | grep -c '\.rdl$\|tools\/templates\/rdl\|reg_gen.sh\|reg_gen.py\|reg_doc_gen.sh\|reg_doc_gen.py' || exit 0)
if [[ "${rdl_mod_count}" -gt 0 ]]; then
# Run the HTML Doc generator script (to update the REG macro header files)
# and the individual reg generator script but then remove the docs directories
bash "${CALIPTRA_ROOT}/tools/scripts/reg_gen.sh"
bash "${CALIPTRA_ROOT}/tools/scripts/reg_doc_gen.sh"
rm -rf "${CALIPTRA_ROOT}/src/integration/docs"
rm -rf "${CALIPTRA_ROOT}/src/soc_ifc/docs"

# Check for any file changes
if [[ $(git status -s --untracked-files=all --ignored=traditional -- "${CALIPTRA_ROOT}/src/" | wc -l) -gt 0 ]]; then
echo "Regenerating reg RDL outputs produced some file changes:";
git status -s --untracked-files=all --ignored=traditional;
git diff;
echo "*****************************************";
echo "Review above changes locally and resubmit pipeline";
echo "(Hint: Check ${CALIPTRA_ROOT} for the above changes)";
echo "*****************************************";
exit 1;
fi
else
echo "skipping RDL check since no RDL files were modified"
fi
76 changes: 76 additions & 0 deletions .github/scripts/stamp_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/bash
# SPDX-License-Identifier: Apache-2.0
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# ENV Check
if [[ -z "${CALIPTRA_ROOT:+"empty"}" ]]; then
echo "Error, must set CALIPTRA_ROOT"
exit 1
fi

# Create file list
find "$CALIPTRA_ROOT" -type f -name "*.sv" \
-o -name "*.svh" \
-o -name "*.rdl" \
-o -name "*.json" \
-o -name "*.v" \
-o -name "*.vh" \
-o -name "*.rsp" \
-o -name "*.s" \
-o -name "*.c" \
-o -name "*.cpp" \
-o -name "*.h" \
-o -name "*.hex" \
-o -name "*.ld" \
-o -name "*.gdb" \
-o -name "*.yml" \
-o -name "*.sh" \
-o -name "*.py" \
-o -name "*.md" \
-o -name "pr_timestamp" \
! -path "*.git/*" | LC_COLLATE=C sort -o $CALIPTRA_ROOT/.github/workflow_metadata/file_list.txt
sed -i "s,^$CALIPTRA_ROOT/,," $CALIPTRA_ROOT/.github/workflow_metadata/file_list.txt
echo "Found $(wc -l $CALIPTRA_ROOT/.github/workflow_metadata/file_list.txt) source code files to hash"
echo -e "First five files:\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
head -5 $CALIPTRA_ROOT/.github/workflow_metadata/file_list.txt
echo -e ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

# Create timestamp
if [[ ! -f $CALIPTRA_ROOT/.github/workflow_metadata/pr_timestamp ]]; then
echo "Error, file not found: $CALIPTRA_ROOT/.github/workflow_metadata/pr_timestamp"
exit 1
fi
timestamp=$(date +%s)
echo "Submitting timestamp [${timestamp}]"
echo -n ${timestamp} > $CALIPTRA_ROOT/.github/workflow_metadata/pr_timestamp

# Create hash
hash=$($CALIPTRA_ROOT/.github/scripts/file_hash.sh $CALIPTRA_ROOT $CALIPTRA_ROOT/.github/workflow_metadata/file_list.txt)
if [[ -z ${hash:+"empty"} ]]; then
echo "Failed to run hash script"
echo $hash
exit 1;
fi
echo "RTL hash is $hash"
if [[ ! -f $CALIPTRA_ROOT/.github/workflow_metadata/pr_hash ]]; then
echo "Error, file not found: $CALIPTRA_ROOT/.github/workflow_metadata/pr_hash"
exit 1
fi
echo "Submitting hash [${hash}]"
echo -n ${hash} > $CALIPTRA_ROOT/.github/workflow_metadata/pr_hash

# Clean up
rm $CALIPTRA_ROOT/.github/workflow_metadata/file_list.txt
20 changes: 20 additions & 0 deletions .github/workflow_metadata/README.md
anjpar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Files in this directory are used to support workflow checks that run on the caliptra-rtl repository using GitHub actions.

pr\_\* objects are used to validate a Pull Request run. This is in support of an honor based system that allows contributors to create internal pipelines (for example, to run tests with proprietary toolchains). The suggested procedure here is:
1. Contributor develops a new feature and pushes a branch to the caliptra-rtl GitHub repository
1. Contributor runs an internal workflow on a branch that contains the merge of the feature branch into main. This workflow includes the complete test-suite and (possibly) some additional checks required by the company policy of that contributor
- All contributors MUST perform the following checks in their development pipeline:
- VCS test of the complete L0 regression suite (smoke tests)
- Lint check run against caliptra_top
1. Upon successfully completing, the internal workflow runs the script [stamp_repo.sh](../scripts/stamp_repo.sh). This script:
- Updates the pr\_timestamp file to the current date
- Runs the hash script [file_hash.sh](../scripts/file_hash.sh) to measure the code that the workflow ran on (including the pr\_timestamp file)
- Writes the hash to the pr\_hash file
1. The internal workflow should commit the updates to pr\_timestamp and pr\_hash as the final commit to the feature branch
- Note that the workflow should be run upon a branch containing the MERGE of the feature branch into main, but the updated stamp files should be committed directly to the feature branch
1. Contributor creates a Pull Request to submit the feature branch to the GitHub `main` branch
1. Pull Request triggers GitHub Actions to run
- Verilator, etc
- Check on the timestamp. If the timestamp is sufficiently outdated (predates the final commit to the branch by more than 1 hour) the feature branch is considered to have failed the internal workflow
- Pull Request runs a hash on the branch fileset (including the timestamp), compares with the contents of pr\_hash. If the hash mismatches, the feature branch is considered to have failed the internal workflow
1. Pull Request is allowed to be merged only once all Actions complete successfully
1 change: 1 addition & 0 deletions .github/workflow_metadata/pr_hash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d6596bcdec69a9be207facc9ecde3e69e25643d66551c56f014b953a0027eb04392aa5996e66e0baeeb1550954e8fe9d
1 change: 1 addition & 0 deletions .github/workflow_metadata/pr_timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1711677713
3 changes: 1 addition & 2 deletions .github/workflows/build-test-verilator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ name: Verilator
on:
push:
branches: ["main", "dev-goog", "dev-msft"]
pull_request:

workflow_call:
workflow_dispatch:

env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/doc-gen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Register Documentation

on:
workflow_dispatch:
pull_request:
workflow_call:
push:
branches: ["main"]

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/interactive-debugging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ name: Interactive debugging
on:
push:
branches: ["main", "dev-goog", "dev-msft", "dev-public"]
pull_request:

workflow_call:
workflow_dispatch:

jobs:
Expand Down
Loading
Loading