Skip to content

Commit c21ef70

Browse files
authored
fix(release): Replace all assets with chinese mirrors (#11323)
* fix(release): Replace all assets with chinese mirrors * feat(release): Add script to append "-cn" to versions * docs(install): Add instructions for users in China
1 parent cbdaee6 commit c21ef70

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

.github/scripts/on-release.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ jq_arg=".packages[0].platforms[0].version = \"$RELEASE_TAG\" | \
342342
echo "Generating $PACKAGE_JSON_DEV ..."
343343
cat "$PACKAGE_JSON_TEMPLATE" | jq "$jq_arg" > "$OUTPUT_DIR/$PACKAGE_JSON_DEV"
344344
# On MacOS the sed command won't skip the first match. Use gsed instead.
345-
sed '0,/github\.com\/espressif\//!s|github\.com/espressif/|dl.espressif.cn/github_assets/espressif/|g' "$OUTPUT_DIR/$PACKAGE_JSON_DEV" > "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN"
345+
sed '0,/github\.com\//!s|github\.com/|dl.espressif.cn/github_assets/|g' "$OUTPUT_DIR/$PACKAGE_JSON_DEV" > "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN"
346+
python "$SCRIPTS_DIR/release_append_cn.py" "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN"
346347
if [ "$RELEASE_PRE" == "false" ]; then
347348
echo "Generating $PACKAGE_JSON_REL ..."
348349
cat "$PACKAGE_JSON_TEMPLATE" | jq "$jq_arg" > "$OUTPUT_DIR/$PACKAGE_JSON_REL"
349350
# On MacOS the sed command won't skip the first match. Use gsed instead.
350-
sed '0,/github\.com\/espressif\//!s|github\.com/espressif/|dl.espressif.cn/github_assets/espressif/|g' "$OUTPUT_DIR/$PACKAGE_JSON_REL" > "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN"
351+
sed '0,/github\.com\//!s|github\.com/|dl.espressif.cn/github_assets/|g' "$OUTPUT_DIR/$PACKAGE_JSON_REL" > "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN"
352+
python "$SCRIPTS_DIR/release_append_cn.py" "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN"
351353
fi
352354

353355
# Figure out the last release or pre-release
@@ -456,14 +458,14 @@ echo "Uploading $PACKAGE_JSON_DEV ..."
456458
echo "Download URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV")"
457459
echo "Pages URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_DEV" "$OUTPUT_DIR/$PACKAGE_JSON_DEV")"
458460
echo "Download CN URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN")"
459-
echo "Pages CN URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_DEV" "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN")"
461+
echo "Pages CN URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_DEV_CN" "$OUTPUT_DIR/$PACKAGE_JSON_DEV_CN")"
460462
echo
461463
if [ "$RELEASE_PRE" == "false" ]; then
462464
echo "Uploading $PACKAGE_JSON_REL ..."
463465
echo "Download URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_REL")"
464466
echo "Pages URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL")"
465467
echo "Download CN URL: $(git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN")"
466-
echo "Pages CN URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN")"
468+
echo "Pages CN URL: $(git_safe_upload_to_pages "$PACKAGE_JSON_REL_CN" "$OUTPUT_DIR/$PACKAGE_JSON_REL_CN")"
467469
echo
468470
fi
469471

.github/scripts/release_append_cn.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
#!/usr/bin/env python3
3+
4+
# Arduino IDE provides by default a package file for the ESP32. This causes version conflicts
5+
# when the user tries to use the JSON file with the Chinese mirrors.
6+
#
7+
# The downside is that the Arduino IDE will always warn the user that updates are available as it
8+
# will consider the version from the Chinese mirrors as a pre-release version.
9+
#
10+
# This script is used to append "-cn" to all versions in the package_esp32_index_cn.json file so that
11+
# the user can select the Chinese mirrors without conflicts.
12+
#
13+
# If Arduino ever stops providing the package_esp32_index.json file by default,
14+
# this script can be removed and the tags reverted.
15+
16+
import json
17+
18+
def append_cn_to_versions(obj):
19+
if isinstance(obj, dict):
20+
# dfu-util comes from arduino.cc and not from the Chinese mirrors, so we skip it
21+
if obj.get("name") == "dfu-util":
22+
return
23+
24+
for key, value in obj.items():
25+
if key == "version" and isinstance(value, str):
26+
if not value.endswith("-cn"):
27+
obj[key] = value + "-cn"
28+
else:
29+
append_cn_to_versions(value)
30+
31+
elif isinstance(obj, list):
32+
for item in obj:
33+
append_cn_to_versions(item)
34+
35+
def process_json_file(input_path, output_path=None):
36+
with open(input_path, "r", encoding="utf-8") as f:
37+
data = json.load(f)
38+
39+
append_cn_to_versions(data)
40+
41+
if output_path is None:
42+
output_path = input_path
43+
44+
with open(output_path, "w", encoding="utf-8") as f:
45+
json.dump(data, f, indent=2)
46+
47+
print(f"Updated JSON written to {output_path}")
48+
49+
if __name__ == "__main__":
50+
import sys
51+
if len(sys.argv) < 2:
52+
print("Usage: python release_append_cn.py input.json [output.json]")
53+
else:
54+
input_file = sys.argv[1]
55+
output_file = sys.argv[2] if len(sys.argv) > 2 else None
56+
process_json_file(input_file, output_file)

docs/en/installing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ To start the installation process using the Boards Manager, follow these steps:
7070
:figclass: align-center
7171

7272
- Open Boards Manager from Tools > Board menu and install *esp32* platform (and do not forget to select your ESP32 board from Tools > Board menu after installation).
73+
Users in China must select the package version with the "-cn" suffix and perform updates manually.
74+
Automatic updates are not supported in this region, as they target the default package without the "-cn" suffix, resulting in download failures.
7375

7476
.. figure:: ../_static/install_guide_boards_manager_esp32.png
7577
:align: center

0 commit comments

Comments
 (0)