Skip to content

Commit

Permalink
Added more checks to package scans
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Jan 4, 2024
1 parent 8c9b9a9 commit 6635c4d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/package_scan_pr.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
on: pull_request

jobs:
default:
package_scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- run: python3 check_packages.py
- run: sh ./check_packages.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/package_scan_push.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
on: push

jobs:
default:
package_scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: python3 check_packages.py
- run: sh ./check_packages.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48 changes: 37 additions & 11 deletions check_packages.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

import os
import json
import tomllib

has_error = False

# Iterate all packages inside "pkgs" folder
for pkg in os.listdir("pkgs"):
print("\n=========================================\n")
# Get package name
pkg_name = pkg.split(".")[0]
# Open package file
Expand All @@ -15,20 +17,44 @@

download_url = pkg_data["download_url"]

print("CHECKING " + pkg_name + "...", end=' ')
print("CHECKING " + pkg_name + "...")
try:
print(" DOWNLOAD: ...", end=' ')
# clone the package into ".temp" folder
os.system("git clone " + download_url + " .temp --quiet --depth 1")
print("OK")

# clone the package into ".temp" folder
os.system("git clone " + download_url + " .temp --quiet --depth 1")
# See if the package has a "sn.toml" file
print(" PACKAGE CONFIG: ...", end=' ')
if os.path.isfile(".temp/sn.toml"):
# If it does, then it's a valid package
print("OK")

# See if the package has a "sn.toml" file
if os.path.isfile(".temp/sn.toml"):
# If it does, then it's a valid package
print("OK")
else:
# If it doesn't, then it's an invalid package
print("INVALID")
# Load the "sn.toml" file
with open(".temp/sn.toml", "r") as sn_toml_file:
# Load the "sn.toml" file
sn_toml_data = tomllib.loads(sn_toml_file.read())

print(" ENTRY EXISTENCE: ...", end=' ')
# See if the package has an entry
if "main" in sn_toml_data["package"]:
entry = sn_toml_data["package"]["main"]
with open(f".temp/{entry}", "r") as entry_file:
print("OK")
else:
# If it doesn't, then it's an invalid package
print("INVALID")
has_error = True
else:
# If it doesn't, then it's an invalid package
print("INVALID")
has_error = True

except Exception as e:
print("ERROR")
print(e)
has_error = True

# Delete the ".temp" folder
os.system("rm -rf .temp")

Expand Down
7 changes: 7 additions & 0 deletions check_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt-get update
sudo apt-get purge python3 -y --auto-remove
sudo apt-get install python3.11 -y

python3.11 -m pip install --upgrade pip
python3.11 check_packages.py

0 comments on commit 6635c4d

Please sign in to comment.