From 77d2a15a3244c97dc47a12c7a090075e12d389bd Mon Sep 17 00:00:00 2001 From: Caleb <11879229+calebofearth@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:18:19 -0700 Subject: [PATCH] [WORKFLOW] Ignore updates to documentation (md, png) files for stamp check (#537) * Ignore updates to documentation (md, png) files when running the hash/stamp check * Checkout merge branch non-shallow to see history * Use commit history from second parent of PR merge to find a valid timestamp from feature branch * MICROSOFT AUTOMATED PIPELINE: Stamp 'cwhitehead-msft-pr-wflow-ignore-docs' with updated timestamp and hash after successful run * Update README regarding PR run ignoring doc files --- .github/scripts/stamp_repo.sh | 1 - .github/workflow_metadata/README.md | 2 ++ .github/workflow_metadata/pr_hash | 2 +- .github/workflow_metadata/pr_timestamp | 2 +- .github/workflows/pre-run-check.yml | 16 +++++++++++++--- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.github/scripts/stamp_repo.sh b/.github/scripts/stamp_repo.sh index 85931f14a..9be13f55a 100755 --- a/.github/scripts/stamp_repo.sh +++ b/.github/scripts/stamp_repo.sh @@ -39,7 +39,6 @@ find "$CALIPTRA_ROOT" -type f -name "*.sv" \ -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 diff --git a/.github/workflow_metadata/README.md b/.github/workflow_metadata/README.md index 737c4f21a..a1adac7f9 100644 --- a/.github/workflow_metadata/README.md +++ b/.github/workflow_metadata/README.md @@ -18,3 +18,5 @@ pr\_\* objects are used to validate a Pull Request run. This is in support of an - 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 + +The Pull Request run ignores updates to documentation files. That is, commits containing only markdown (.md) or image (.png) files are not required to pass the timestamp/hash check. diff --git a/.github/workflow_metadata/pr_hash b/.github/workflow_metadata/pr_hash index 0a181b208..a3bad9b6a 100644 --- a/.github/workflow_metadata/pr_hash +++ b/.github/workflow_metadata/pr_hash @@ -1 +1 @@ -cb7f3fca2dec15bb4a7f79de6243ae45ccd694e4375cee1778ceaf28487ab3e4e99cf2d773b79ffe8737dceed4fff6f7 \ No newline at end of file +3e1ac9d915dbc1b961bea53177a00994a83506b8a048e76f9425fc5bdcbcee319af1d15feded88f64d73a7d08dffbdd1 \ No newline at end of file diff --git a/.github/workflow_metadata/pr_timestamp b/.github/workflow_metadata/pr_timestamp index f2da94b72..26856737d 100644 --- a/.github/workflow_metadata/pr_timestamp +++ b/.github/workflow_metadata/pr_timestamp @@ -1 +1 @@ -1717722005 \ No newline at end of file +1718252040 \ No newline at end of file diff --git a/.github/workflows/pre-run-check.yml b/.github/workflows/pre-run-check.yml index bc459bd6f..f3bee8a34 100644 --- a/.github/workflows/pre-run-check.yml +++ b/.github/workflows/pre-run-check.yml @@ -74,6 +74,8 @@ jobs: steps: - name: Checkout RTL repo uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Gen File List run: | @@ -94,7 +96,6 @@ jobs: -o -name "*.yml" \ -o -name "*.sh" \ -o -name "*.py" \ - -o -name "*.md" \ -o -name "pr_timestamp" \ ! -path "*.git/*" | LC_COLLATE=C sort -o $GITHUB_WORKSPACE/.github/workflow_metadata/file_list.txt sed -i "s,^$GITHUB_WORKSPACE/,," $GITHUB_WORKSPACE/.github/workflow_metadata/file_list.txt @@ -105,14 +106,23 @@ jobs: - name: Check Timestamp run: | - timestamp_exp=$(bc <<< "$(git log -n1 --pretty=tformat:'%ct')-3600") + # Find the last commit that modified any design file (not documentation) + # Start the search with the second parent of the PR merge commit + # in order to only traverse the feature branch commits + last_commit=$(git rev-parse HEAD^2) + until git diff --name-only "${last_commit}^..${last_commit}" | grep -v '\.md\|\.png' > /dev/null; do + last_commit="$(git rev-parse ${last_commit}^)" + done + echo "Latest non-doc hash is ${last_commit}" + # Compare the timestamp from the latest commit with the pr_timestamp file + timestamp_exp=$(bc <<< "$(git log -n1 --pretty=tformat:'%ct' ${last_commit})-3600") if [[ ! -f $GITHUB_WORKSPACE/.github/workflow_metadata/pr_timestamp ]]; then echo "Error, file not found: $GITHUB_WORKSPACE/.github/workflow_metadata/pr_timestamp" exit 1 fi timestamp=$(tail -1 $GITHUB_WORKSPACE/.github/workflow_metadata/pr_timestamp) if [[ ${timestamp} -lt ${timestamp_exp} ]]; then - echo "Error, submitted timestamp [${timestamp}] is outdated: it precedes the latest commit to branch by more than an hour [${timestamp_exp}]" + echo "Error, submitted timestamp [${timestamp}] is outdated: it precedes the latest non-documentation commit to branch by more than an hour [${timestamp_exp}]" echo "Please rerun any internal/company proprietary testcases, which should invoke .github/scripts/stamp_repo.sh to attest to successful completion" echo "DO NOT manually run stamp_repo.sh on your branch to bypass this step - the output timestamp/hash is used to verify internal testcase sign-off is successful" exit 1