From da22d2c0bc4ff130fa345b593ebaeac64d3a4ab2 Mon Sep 17 00:00:00 2001 From: salman2013 Date: Thu, 28 Mar 2024 11:48:02 +0500 Subject: [PATCH] chore: add workflow to find the python dependencies in repo --- .github/workflows/check_dependencies.yml | 48 +++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check_dependencies.yml b/.github/workflows/check_dependencies.yml index 56ec4db0cf92..429fdd9547a7 100644 --- a/.github/workflows/check_dependencies.yml +++ b/.github/workflows/check_dependencies.yml @@ -32,4 +32,50 @@ jobs: - name: List Installed Packages run: | source .venv/bin/activate # Activate the virtual environment - pip list --format=columns # List installed packages in columns format \ No newline at end of file + pip list --format=columns # List installed packages in columns format + + - name: Find Source Repos for Dependencies + id: find_source_repos + run: | + source .venv/bin/activate # Activate the virtual environment + python - << EOF +import subprocess +import re + +# Define the first-party and second-party organizations +FIRST_PARTY_ORGS = ["openedx"] +SECOND_PARTY_ORGS = [ + "edx", "edx-unsupported", "edx-solutions", + "mitodl", + "overhangio", + "open-craft", "eduNEXT", "raccoongang", +] + +# Get the output of 'pip list' command +pip_list_output = subprocess.run(['pip', 'list'], capture_output=True, text=True).stdout + +# Find source repositories for each installed package +first_party_repos = [] +second_party_repos = [] +for line in pip_list_output.split('\n'): + match = re.match(r'([\w-]+) \(([\d.]+)\)', line) + if match: + package_name = match.group(1) + # Assume the source repository URL can be extracted from the package name (modify this as per your project's conventions) + # Here, we just append 'https://github.com/{package_name}' for demonstration purposes + repo_url = f'https://github.com/{package_name}' + if any(org in repo_url for org in FIRST_PARTY_ORGS): + first_party_repos.append(repo_url) + elif any(org in repo_url for org in SECOND_PARTY_ORGS): + second_party_repos.append(repo_url) + +print("::set-output name=first_party_repos::{}".format(','.join(first_party_repos))) +print("::set-output name=second_party_repos::{}".format(','.join(second_party_repos))) +EOF + + - name: Display Source Repos + run: | + echo "First Party Repositories:" + echo "${{ steps.find_source_repos.outputs.first_party_repos }}" + echo "Second Party Repositories:" + echo "${{ steps.find_source_repos.outputs.second_party_repos }}" \ No newline at end of file