Skip to content

Commit

Permalink
Fix: reduce workflow dependencies (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan-rajoria authored Nov 6, 2024
1 parent 2cdd0b3 commit f887ab5
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-meson-tst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
path: blint-db
- name: Install dependencies
run: |
[ -d venv ] || python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install setuptools wheel twine build
cd blint-db && python -m pip install .
Expand All @@ -32,8 +34,9 @@ jobs:
- name: Build and upload db
run: |
mkdir -p temp
source venv/bin/activate
cd blint-db/
python blint_db/cli.py -f -Z1
python blint_db/cli.py --clean-start -f -Z1
python ./.oras/orasclient.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/build-meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
path: blint-db
- name: Install dependencies
run: |
[ -d venv ] || python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install setuptools wheel twine build
cd blint-db && python -m pip install .
Expand All @@ -32,8 +34,9 @@ jobs:
- name: Build and upload db
run: |
mkdir -p temp
source venv/bin/activate
cd blint-db/
python blint_db/cli.py -Z1
python blint_db/cli.py --clean-start -Z1
python ./.oras/orasclient.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/build-vcpkg-tst.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build and Upload vcpkg blint-db 0.1.0

on:
schedule:
- cron: "0 */12 * * *"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: appthreat/blintdb

jobs:
builder-vcpkg-tst:
runs-on: ['self-hosted', 'ubuntu', 'arm64']
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
with:
repository: AppThreat/blint-db
path: blint-db
- name: Install dependencies
run: |
[ -d venv ] || python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install setuptools wheel twine build
cd blint-db && python -m pip install .
- name: Clean up previous
run: |
cd blint-db
rm -f info.log
rm -f blint.db
- name: Build and upload db
run: |
mkdir -p temp
source venv/bin/activate
cd blint-db/
python3 blint-db/blint_db/cli.py --clean-start -f -Z2
python3 ./.oras/orasclient.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: ${{ github.actor }}
7 changes: 5 additions & 2 deletions .github/workflows/build-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
path: blint-db
- name: Install dependencies
run: |
[ -d venv ] || python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install setuptools wheel twine build
cd blint-db && python -m pip install .
Expand All @@ -32,9 +34,10 @@ jobs:
- name: Build and upload db
run: |
mkdir -p temp
source venv/bin/activate
cd blint-db/
python blint-db/blint_db/cli.py -Z2
python ./.oras/orasclient.py
python3 blint-db/blint_db/cli.py --clean-start -Z2
python3 ./.oras/orasclient.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USERNAME: ${{ github.actor }}
2 changes: 1 addition & 1 deletion .oras/orasclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

client = oras.client.OrasClient()

token = os.getenv("GITHUB_USERNAME", "")
token = os.getenv("GITHUB_TOKEN", "")
username = os.getenv("GITHUB_USERNAME", "")


Expand Down
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"request": "launch",
"program": "${workspaceFolder}/blint_db/cli.py",
"console": "integratedTerminal",
"args": "-Z1"
// "preLaunchTask": "Run Cleanup Script",
"args": ["-f", "-Z1"]
},
{
"name": "test nodejs sbom deep",
Expand All @@ -38,7 +39,7 @@
"request": "launch",
"program": "${workspaceFolder}/blint_db/cli.py",
"console": "integratedTerminal",
"preLaunchTask": "Run Cleanup Script",
// "preLaunchTask": "Run Cleanup Script",
"args": "-Z2"
}
]
Expand Down
25 changes: 15 additions & 10 deletions blint_db/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import argparse
import sqlite3
from concurrent import futures

from blint_db import BLINTDB_LOCATION, COMMON_CONNECTION
Expand Down Expand Up @@ -60,7 +61,6 @@ def arguments_parser():
parser.add_argument(
"--clean-start",
dest="clean",
default=False,
action="store_true",
help="Resets the database before starting a new build",
)
Expand All @@ -69,9 +69,17 @@ def arguments_parser():
"--few-packages",
dest="test_mode",
action="store_true",
help="Set meson to build fewer projects, helpful for debugging",
help="Set pkg managers to build fewer projects, helpful for debugging",
)

# parser.add_argument(
# "-R",
# "--reuse-old-db",
# dest="reuse",
# action="store_true",
# help="when set does not create a new database"
# )

return parser.parse_args()

def reset_and_backup():
Expand All @@ -96,8 +104,10 @@ def meson_add_blint_bom_process(test_mode=False):
print(f"Ran complete for {project_name} and we found {len(executables)}")


def vcpkg_add_blint_bom_process():
def vcpkg_add_blint_bom_process(test_mode=False):
projects_list = get_vcpkg_projects()
if test_mode:
projects_list = projects_list[:10]
count = 0
for project_name in projects_list:
executables = mt_vcpkg_blint_db_build(project_name)
Expand All @@ -108,12 +118,6 @@ def vcpkg_add_blint_bom_process():
reset_and_backup()
count = 0

# with futures.ProcessPoolExecutor(max_workers=1) as executor:
# for project_name, executables in zip(
# projects_list, executor.map(mt_vcpkg_blint_db_build, projects_list)
# ):
# print(f"Ran complete for {project_name} and we found {len(executables)}")


def main():

Expand All @@ -127,10 +131,11 @@ def main():
meson_add_blint_bom_process(args["test_mode"])

if args["vcpkg"]:
vcpkg_add_blint_bom_process()
vcpkg_add_blint_bom_process(args["test_mode"])

if COMMON_CONNECTION:
reset_and_backup()
print("Build Completed Saved Database")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions blint_db/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

DELIMETER_BOM = "~~"
# variables
DEBUG_MODE = True
DEBUG_MODE = False
# constants
TEMP_PATH = Path.cwd() / "temp"
WRAPDB_LOCATION = TEMP_PATH / "wrapdb"
Expand All @@ -28,5 +28,5 @@

SQLITE_TIMEOUT = 20.0

# COMMON_CONNECTION = None
COMMON_CONNECTION = sqlite3.connect(":memory:")
COMMON_CONNECTION = None
# COMMON_CONNECTION = sqlite3.connect(":memory:")
11 changes: 5 additions & 6 deletions blint_db/handlers/sqlite_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SQLITE_TIMEOUT)



def use_existing_connection(connection=None): # Decorator now accepts connection
"""
Decorator to use an existing connection when BLINTDB_LOCATION is ':memory:'.
Expand All @@ -18,7 +19,7 @@ def decorator(func):
def wrapper(*args, **kwargs):
if connection:
with closing(connection.cursor()) as c:
if len(args) > 1: # Statement and arguments provided
if len(args) > 1:
c.execute(args[0], args[1])
else:
c.execute(args[0])
Expand Down Expand Up @@ -117,7 +118,9 @@ def create_database():


def clear_sqlite_database():
os.remove(BLINTDB_LOCATION)
if os.path.exists(BLINTDB_LOCATION):
if os.path.isfile(BLINTDB_LOCATION):
os.remove(BLINTDB_LOCATION)


def store_sbom_in_sqlite(purl, sbom):
Expand Down Expand Up @@ -196,7 +199,3 @@ def _fetch_infunc_row(infunc):
execute_statement(
"INSERT INTO BinariesExports (bid, eid) VALUES (?, ?)", (bid, eid)
)


if not os.path.exists(BLINTDB_LOCATION):
create_database()

0 comments on commit f887ab5

Please sign in to comment.