Skip to content

Commit 0d17540

Browse files
authored
feat: save trusted packages in the repo (#314)
1 parent c50ccbd commit 0d17540

7 files changed

Lines changed: 207 additions & 1 deletion

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Scheduled Pipeline
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * 1" # every Monday at 00:00 UTC
6+
workflow_dispatch:
7+
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b # v2.1.1
14+
id: app-token
15+
with:
16+
app-id: ${{ vars.ELEMENTSINTERACTIVE_BOT_APP_ID }}
17+
private-key: ${{ secrets.ELEMENTSINTERACTIVE_BOT_PRIVATE_KEY }}
18+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
19+
with:
20+
fetch-depth: 0
21+
token: ${{ steps.app-token.outputs.token }}
22+
ref: ${{ github.head_ref }}
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@557e51de59eb14aaaba2ed9621916900a91d50c6 # v6.6.1
25+
26+
- name: Install the project
27+
run: uv sync --locked --only-group download
28+
29+
- name: Download packages from trusted sources
30+
run: |
31+
uv run dependencies/scripts/download_packages.py run --ecosystem pypi
32+
uv run dependencies/scripts/download_packages.py run --ecosystem npm
33+
34+
- name: Push changes to repo
35+
run: |
36+
git add .
37+
git commit -m "chore: Weekly update of trusted packages"
38+
git push origin HEAD:main

dependencies/npm.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

dependencies/pypi.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import json
2+
from pathlib import Path
3+
from typing import Any
4+
5+
import click
6+
import httpx
7+
import stamina
8+
9+
10+
def parse_npm(data: list[dict[str, Any]]) -> list[str]:
11+
return [x["name"] for x in data]
12+
13+
14+
def parse_pypi(data: dict[str, Any]) -> list[str]:
15+
return [row["project"] for row in data["rows"]]
16+
17+
18+
ECOSYSTEMS = {
19+
"npm": {
20+
"url": "https://packages.ecosyste.ms/api/v1/registries/npmjs.org/packages?per_page=10000&page=1&sort=downloads",
21+
"parser": parse_npm,
22+
},
23+
"pypi": {
24+
"url": "https://hugovk.github.io/top-pypi-packages/top-pypi-packages.min.json",
25+
"parser": parse_pypi,
26+
},
27+
}
28+
29+
30+
@click.group()
31+
def entry_point() -> None:
32+
pass
33+
34+
35+
@entry_point.command()
36+
@click.option(
37+
"--ecosystem",
38+
type=str,
39+
required=True,
40+
help="Package ecosystem to download packages from.",
41+
)
42+
def run(ecosystem: str) -> None:
43+
for attempt in stamina.retry_context(
44+
on=(
45+
httpx.TransportError,
46+
httpx.TimeoutException,
47+
),
48+
attempts=3,
49+
timeout=60,
50+
):
51+
with attempt, httpx.Client() as client:
52+
response = client.get(ECOSYSTEMS[ecosystem]["url"]) # type: ignore[arg-type]
53+
response.raise_for_status()
54+
55+
fpath = Path("dependencies") / f"{ecosystem}.json"
56+
57+
data = ECOSYSTEMS[ecosystem]["parser"](response.json()) # type: ignore[operator]
58+
59+
with open(str(fpath), "w") as fp:
60+
json.dump(data, fp)
61+
62+
63+
if __name__ == "__main__":
64+
entry_point()

justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ run := "uv run"
55

66
venv-exists := path_exists(venv)
77

8-
target_dirs := "src tests"
8+
target_dirs := "src tests dependencies"
99

1010
# ALIASES
1111
alias t := test
@@ -53,3 +53,6 @@ build: venv
5353
# Install package in development mode
5454
install-dev: venv
5555
uv pip install -e .
56+
57+
download ecosystem: venv
58+
uv run dependencies/scripts/download_packages.py run --ecosystem {{ecosystem}}

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ dev = [
5050
"freezegun>=1.5.5",
5151
"types-pyyaml>=6.0.12.20250822",
5252
]
53+
download = [
54+
"click>=8.1.8",
55+
"httpx>=0.28.1",
56+
"stamina>=25.1.0",
57+
]
5358
local = ["ipdb<1.0.0,>=0.13.9", "commitizen<5.0,>=2.38", "pdbpp<1.0.0,>=0.11.6"]
5459

5560

uv.lock

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)