-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Check dependency changes | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
check_dependency_changes: | ||
runs-on: ubuntu-latest | ||
name: Check dependency changes | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Gradle cache | ||
uses: gradle/actions/setup-gradle@v4 | ||
with: | ||
cache-read-only: true | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.13' | ||
|
||
- name: Compare dependencies between base and head | ||
id: compare_deps | ||
env: | ||
BASE_REF: ${{ github.base_ref }} | ||
HEAD_REF: ${{ github.head_ref }} | ||
run: | | ||
chmod +x scripts/check_dependency_changes.py | ||
python scripts/check_dependency_changes.py dependency_changes.md | ||
if [[ ! -s "dependency_changes.md" ]]; then | ||
echo "has_changes=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "has_changes=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Add comment on PR | ||
uses: thollander/actions-comment-pull-request@v3 | ||
if: steps.compare_deps.output.has_changes == true | ||
with: | ||
file-path: "${{ github.workspace }}/dependency_changes.md" | ||
comment-tag: dependency_changes | ||
mode: recreate | ||
|
||
- name: Delete comment from PR | ||
uses: thollander/actions-comment-pull-request@v3 | ||
if: steps.compare_deps.output.has_changes == false | ||
with: | ||
comment-tag: dependency_changes | ||
mode: delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
import difflib | ||
|
||
# You can test this script locally with this command: | ||
# BASE_REF="BASE_REFERENCE" HEAD_REF="HEAD_REFERENCE" python ./scripts/check_dependency_changes.py test_output.txt | ||
|
||
def compare_dependency_list(base_ref: str, head_ref: str): | ||
base_dependency_list = get_dependency_list(base_ref) | ||
head_dependency_list = get_dependency_list(head_ref) | ||
|
||
dependency_diff = diff_strings(base_dependency_list, head_dependency_list) | ||
output = generate_github_comment(dependency_diff) | ||
|
||
with open(sys.argv[1], 'w+') as f: | ||
f.write(output) | ||
if os.getenv('GITHUB_STEP_SUMMARY'): os.environ[os.getenv('GITHUB_STEP_SUMMARY')] = output | ||
|
||
def get_dependency_list(git_ref: str) -> str: | ||
subprocess.Popen(["git", "checkout", "-f", git_ref]) | ||
return subprocess.check_output(["./gradlew", "dependencyList", "-q", "--no-configuration-cache"] | ||
).decode(sys.stdout.encoding | ||
).strip() | ||
|
||
def diff_strings(first: str, second: str) -> str: | ||
diff = difflib.unified_diff(first.splitlines(keepends=True), second.splitlines(keepends=True)) | ||
return ''.join(diff) | ||
|
||
def generate_github_comment(dependency_diff: str) -> str: | ||
if not dependency_diff: | ||
return "" | ||
|
||
return '''\ | ||
The following dependencies have been modified in this PR: | ||
```diff | ||
{diff} | ||
``` | ||
To check the affected modules run the `dependencyList` gradle task with `includeModules=true`. | ||
'''.format(diff=dependency_diff) | ||
|
||
def main(): | ||
red = '\033[31m' | ||
|
||
base_ref = os.getenv('BASE_REF') | ||
if base_ref is None: | ||
print(red + 'BASE_REF is not provided. Please provide it in env list. Exiting...') | ||
sys.exit(1) | ||
|
||
head_ref = os.getenv('HEAD_REF') | ||
if head_ref is None: | ||
print(red + 'HEAD_REF is not provided. Please provide it in env list. Exiting...') | ||
sys.exit(1) | ||
|
||
compare_dependency_list(base_ref, head_ref) | ||
|
||
if __name__ == '__main__': | ||
main() |