Skip to content

Commit 30a4033

Browse files
committed
Automate extension publishing for multiple targets
1 parent e0b6ad0 commit 30a4033

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

scripts/publish.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import shutil
17+
import subprocess
18+
from dataclasses import dataclass
19+
from pathlib import Path
20+
21+
from platformio.package.manager.tool import ToolPackageManager
22+
from platformio.package.meta import PackageSpec
23+
24+
25+
@dataclass
26+
class PlatformItem:
27+
target: str
28+
system: str
29+
30+
def __init__(self, target, system=None):
31+
self.target = target
32+
self.system = system
33+
34+
35+
PLATFORM_LIST = [
36+
PlatformItem("win32-arm64"),
37+
PlatformItem("win32-ia32", "windows_x86"),
38+
PlatformItem("win32-x64", "windows_amd64"),
39+
PlatformItem("linux-arm64"),
40+
PlatformItem("linux-armhf"),
41+
PlatformItem("linux-x64"),
42+
PlatformItem("alpine-x64"),
43+
PlatformItem("alpine-arm64"),
44+
PlatformItem("darwin-arm64"),
45+
PlatformItem("darwin-x64", "darwin_x86_64"),
46+
PlatformItem("web"),
47+
]
48+
49+
ROOT_DIR = (Path(__file__).parent / "..").resolve()
50+
PREDOWNLOADED_DIR = ROOT_DIR / "assets" / "predownloaded"
51+
52+
53+
def cleanup_predownload_dir(path: Path):
54+
for child in path.iterdir():
55+
if child.name != ".keep":
56+
os.remove(str(child))
57+
58+
59+
def predownload_portable_python(dst_dir: Path, custom_system):
60+
tm = ToolPackageManager()
61+
package = tm.fetch_registry_package(PackageSpec("platformio/python-portable"))
62+
assert package
63+
version = tm.pick_best_registry_version(
64+
package["versions"], custom_system=custom_system
65+
)
66+
if not version:
67+
print(f"Could not find portable Python for {custom_system}")
68+
return
69+
pkgfile = tm.pick_compatible_pkg_file(version["files"], custom_system=custom_system)
70+
dlfile_path = tm.download(pkgfile["download_url"], pkgfile["checksum"]["sha256"])
71+
shutil.copy(dlfile_path, dst_dir / os.path.basename(pkgfile["download_url"]))
72+
73+
74+
if __name__ == "__main__":
75+
for item in PLATFORM_LIST:
76+
print(f"Publishing {item}")
77+
cleanup_predownload_dir(PREDOWNLOADED_DIR)
78+
if item.system:
79+
predownload_portable_python(PREDOWNLOADED_DIR, item.system)
80+
subprocess.run(
81+
[
82+
"npx",
83+
"vsce",
84+
"publish",
85+
"--allow-star-activation",
86+
"--target",
87+
item.target,
88+
],
89+
cwd=ROOT_DIR,
90+
)

0 commit comments

Comments
 (0)