Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jreij committed Feb 18, 2025
1 parent 94a76b9 commit 5b9d1fa
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 23 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/check_dependency_changes.yml
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
47 changes: 25 additions & 22 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ concurrency:
cancel-in-progress: true

jobs:
code_analysis:
name: Code analysis
uses: ./.github/workflows/code_analysis.yml
assemble:
name: Assemble
uses: ./.github/workflows/assemble.yml
needs: code_analysis
test:
name: Test
uses: ./.github/workflows/run_tests.yml
needs: assemble
sonar_cloud:
name: SonarCloud
uses: ./.github/workflows/sonar_cloud.yml
secrets: inherit
validate_public_api:
name: Validate public API
uses: ./.github/workflows/validate_public_api.yml
secrets: inherit
verify_dependencies:
name: Validate dependencies
uses: ./.github/workflows/validate_dependencies.yml
# code_analysis:
# name: Code analysis
# uses: ./.github/workflows/code_analysis.yml
# assemble:
# name: Assemble
# uses: ./.github/workflows/assemble.yml
# needs: code_analysis
# test:
# name: Test
# uses: ./.github/workflows/run_tests.yml
# needs: assemble
# sonar_cloud:
# name: SonarCloud
# uses: ./.github/workflows/sonar_cloud.yml
# secrets: inherit
# validate_public_api:
# name: Validate public API
# uses: ./.github/workflows/validate_public_api.yml
# secrets: inherit
# verify_dependencies:
# name: Validate dependencies
# uses: ./.github/workflows/validate_dependencies.yml
check_dependency_changes:
name: Check dependency changes
uses: ./.github/workflows/check_dependency_changes.yml
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ constraintlayout = "2.2.0"

# Compose dependencies
compose-activity = "1.10.0"
compose-bom = "2024.12.01"
compose-bom = "2025.02.00"
compose-hilt = "1.2.0"
compose-viewmodel = "2.8.7"

Expand Down
60 changes: 60 additions & 0 deletions scripts/check_dependency_changes.py
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()

0 comments on commit 5b9d1fa

Please sign in to comment.