Skip to content

Commit ceb9d06

Browse files
feat: add automatic release generator
1 parent b653e3c commit ceb9d06

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

.github/workflows/build_addons.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build Addons
2+
on:
3+
push:
4+
branches: [main]
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v5
14+
15+
- name: Build Addons
16+
run: |
17+
python -m venv .venv
18+
source .venv/bin/activate
19+
python -m pip install -r _build/requirements.txt
20+
cd _build
21+
python -m build
22+
23+
- name: Create Release
24+
uses: softprops/action-gh-release@v2
25+
with:
26+
files: _out/addons.zip
27+
generate_release_notes: true
28+
make-latest: true

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
# IDE
2+
.vs/
3+
.idea/
4+
.vscode/
5+
6+
# Artifacts
7+
.venv/
8+
_out
9+
addons.zip
10+
11+
# Game
112
addonlist.kv3
2-
/.vs

_build/build.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import shutil
3+
import sys
4+
5+
from sourcepp import vpkpp
6+
7+
8+
def build_addon(addon_dir: str, output_dir_parent: str) -> None:
9+
output_dir = os.path.join(output_dir_parent, "p2ce_" + os.path.basename(addon_dir))
10+
os.makedirs(output_dir, exist_ok=True)
11+
print(f"Building addon {os.path.basename(addon_dir)} to {os.path.relpath(output_dir, os.getcwd())}")
12+
13+
to_pack: list[str] = []
14+
for content_entry_name in os.listdir(addon_dir):
15+
content_entry_path = os.path.join(addon_dir, content_entry_name)
16+
if content_entry_name.startswith('.') or content_entry_name == "addon.kv3" or content_entry_name == "media":
17+
# We can't pack media yet. Remove that check when this is no longer the case
18+
print(f"Copying {content_entry_name}")
19+
if os.path.isdir(content_entry_path):
20+
shutil.copytree(content_entry_path, os.path.join(output_dir, content_entry_name), dirs_exist_ok=True)
21+
else:
22+
shutil.copy(content_entry_path, output_dir)
23+
continue
24+
25+
print(f"Packing {content_entry_name}")
26+
to_pack.append(content_entry_path)
27+
28+
if len(to_pack) > 0:
29+
vpk = vpkpp.VPK.create(os.path.join(output_dir, "pak01_dir.vpk"))
30+
for entry in to_pack:
31+
if os.path.isdir(entry):
32+
vpk.add_directory(os.path.basename(entry), entry)
33+
elif os.path.isfile(entry):
34+
vpk.add_entry_from_file(os.path.basename(entry), entry)
35+
vpk.bake()
36+
37+
38+
def zip_addons(parent_dir: str, stem: str) -> None:
39+
print(f"Zipping contents of {parent_dir} into {stem}.zip")
40+
shutil.make_archive(os.path.join(parent_dir, stem), "zip", parent_dir)
41+
42+
43+
def build(addon_root_dir: str) -> None:
44+
output_dir_parent = os.path.join(addon_root_dir, "_out")
45+
46+
addon_count = 0
47+
for addon_dir_name in os.listdir(addon_root_dir):
48+
if addon_dir_name.startswith(('.', '_')):
49+
continue
50+
addon_dir = os.path.join(addon_root_dir, addon_dir_name)
51+
if not os.path.isdir(addon_dir):
52+
continue
53+
build_addon(addon_dir, output_dir_parent)
54+
addon_count += 1
55+
56+
zip_addons(output_dir_parent, "addons")
57+
print(f"Completed, built {addon_count} addons")
58+
59+
60+
if __name__ == "__main__":
61+
build(os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir)) if len(sys.argv) < 2 else sys.argv[1])

_build/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sourcepp==2025.9.12

0 commit comments

Comments
 (0)