Skip to content

Commit

Permalink
[TOOLS] Tweak pull_request compile.yml check to work with forked repo…
Browse files Browse the repository at this point in the history
…sitories (#507)

* Tweak to compile.yml check to work with forks

* Use merge ref instead of PR origin branch

* Disable verilator for quick workflow dbg iterations

* Fix dependencies too

* Debug info

* More dbg

* more debug

* Use repo owner

* Fork support

* Formatting

* Owner subfields

* Dbg

* DBG

* dbg

* Use login instead of name for owner

* show-ref on the diff command to get hashes

* fix show-ref calls

* Typo fix on gh context var

* cleanup of dbg lines

* manually stamp repo - no changes of any kind that are observed by internal pipeline

* Revert job disablement

* re-add MSFT users to list

* manually stamp repo - no changes of any kind that are observed by internal pipeline

* clarify print message and stamp repo
  • Loading branch information
calebofearth authored Apr 24, 2024
1 parent a50f6d2 commit e1d0156
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d80fa2173c00ce84dc0c744ca9d1ee6a99eb54891d7eb6c172e6a38905699c12fd517b389bcff0698dfb7d352f7cda6c
6d4ab4825024ab9ac6bdd9da7f697e8c46e778b62f31e18c38ef227f4a39095cea032f79f1686a79f5d49c1b5604f1c4
2 changes: 1 addition & 1 deletion .github/workflow_metadata/pr_timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1712949801
1713994941
26 changes: 20 additions & 6 deletions .github/workflows/pre-run-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
workflow_call:

env:
MSFT_ACTORS: ( "Nitsirks" "calebofearth" "mojtaba-bisheh" "anjpar" "upadhyayulakiran" )
MSFT_ACTORS: ( "Nitsirks" "calebofearth" "mojtaba-bisheh" "anjpar" "upadhyayulakiran" "nileshbpat" "ekarabu" )

jobs:
# Fail if any compile.yml has been modified
Expand All @@ -35,22 +35,36 @@ jobs:
fetch-depth: 0
- name: Compare against target
env:
SOURCE_BR: ${{ github.head_ref }}
TARGET_BR: ${{ github.base_ref }}
PR_OPENER: ${{ github.event.pull_request.user.login }}
SOURCE_BR: ${{ github.event.pull_request.head.ref }}
SOURCE_FORK: ${{ github.event.pull_request.head.repo.fork }}
SOURCE_OWN: ${{ github.event.pull_request.head.repo.owner.login }}
SOURCE_URL: ${{ github.event.pull_request.head.repo.clone_url }}
TARGET_BR: ${{ github.event.pull_request.base.ref }}
run: |
echo "Comparing $SOURCE_BR against merge target $TARGET_BR to look for compile.yml"
echo "Comparing $SOURCE_OWN/$SOURCE_BR against merge target origin/$TARGET_BR to look for compile.yml"
local_msft_actors=${{ env.MSFT_ACTORS }}
for msft_actor in "${local_msft_actors[@]}"; do
if [[ "${{ github.actor }}" == "${msft_actor}" ]]; then
if [[ "${PR_OPENER}" == "${msft_actor}" ]]; then
echo "Skipping check on compile.yml modifications for detected Microsoft contributor: ${msft_actor}"
exit 0
fi
done
compiles=$(git diff --name-only origin/$TARGET_BR...origin/$SOURCE_BR)
if [[ "${SOURCE_FORK}" == "true" ]]; then
echo "pull request is from a fork: ${SOURCE_FORK}"
echo "fork repository owner is ${SOURCE_OWN}"
echo "adding remote '${SOURCE_OWN}' at url '${SOURCE_URL}'"
git remote add -f ${SOURCE_OWN} ${SOURCE_URL}
fi
echo "target ref is $(git show-ref origin/${TARGET_BR} 2> /dev/null)"
echo "source ref is $(git show-ref ${SOURCE_OWN}/${SOURCE_BR} 2> /dev/null)"
compiles=$(git diff --name-only $(git show-ref --hash "origin/$TARGET_BR")...$(git show-ref --hash "${SOURCE_OWN}/${SOURCE_BR}"))
if [[ $(grep -c compile.yml <<< "$compiles") -gt 0 ]]; then
echo "compile.yml should not be modified for pull requests! Found:"
echo "$compiles"
exit 1
else
echo "Found no modifications to compile.yml"
fi
# Build the comparison hash file
Expand Down

0 comments on commit e1d0156

Please sign in to comment.