Skip to content

Commit

Permalink
[WORKFLOW] Ignore updates to documentation (md, png) files for stamp …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
calebofearth authored Jun 13, 2024
1 parent 2b67364 commit 77d2a15
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
1 change: 0 additions & 1 deletion .github/scripts/stamp_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflow_metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cb7f3fca2dec15bb4a7f79de6243ae45ccd694e4375cee1778ceaf28487ab3e4e99cf2d773b79ffe8737dceed4fff6f7
3e1ac9d915dbc1b961bea53177a00994a83506b8a048e76f9425fc5bdcbcee319af1d15feded88f64d73a7d08dffbdd1
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1717722005
1718252040
16 changes: 13 additions & 3 deletions .github/workflows/pre-run-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ jobs:
steps:
- name: Checkout RTL repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Gen File List
run: |
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 77d2a15

Please sign in to comment.