-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
77 changed files
with
7,248 additions
and
3,822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import re | ||
|
||
def read_hw_file(hw_file_path): | ||
with open(hw_file_path, 'r') as file: | ||
return file.read() | ||
|
||
def parse_brd_configs(hw_content): | ||
pattern = re.compile(r'BrdConfigStruct brdConfigs\[\] = \{(.*?)\};', re.DOTALL) | ||
match = pattern.search(hw_content) | ||
if match: | ||
print("Found brdConfigs") | ||
return match.group(1) | ||
print("brdConfigs not found") | ||
return "" | ||
|
||
def extract_devices(brd_configs, mist_configs): | ||
devices = [] | ||
device_pattern = re.compile(r'\{\s*"([^"]+)",\s*\.ethConfigIndex = (-?\d+),\s*\.zbConfigIndex = -?\d+,\s*\.mistConfigIndex = (-?\d+)\s*\}', re.DOTALL) | ||
for device_match in device_pattern.finditer(brd_configs): | ||
device_name = device_match.group(1) | ||
eth_config_index = int(device_match.group(2)) | ||
mist_config_index = int(device_match.group(3)) | ||
|
||
eth_is = eth_config_index > -1 | ||
btn_is = mist_configs[mist_config_index]['btnPin'] > -1 | ||
led_is = mist_configs[mist_config_index]['ledModePin'] > -1 or mist_configs[mist_config_index]['ledPwrPin'] > -1 | ||
|
||
device = { | ||
'name': device_name, | ||
'eth': ':white_check_mark:' if eth_is else ':x:', | ||
'button': ':white_check_mark:' if btn_is else ':x:', | ||
'led': ':white_check_mark:' if led_is else ':x:', | ||
'network_usb': ':white_check_mark:' | ||
} | ||
devices.append(device) | ||
print(f"Extracted device: {device}") | ||
return devices | ||
|
||
def parse_mist_configs(hw_content): | ||
pattern = re.compile(r'MistConfig mistConfigs\[\] = \{(.*?)\};', re.DOTALL) | ||
match = pattern.search(hw_content) | ||
if match: | ||
print("Found mistConfigs") | ||
mist_configs = match.group(1) | ||
return extract_mist_configs(mist_configs) | ||
print("mistConfigs not found") | ||
return [] | ||
|
||
def extract_mist_configs(mist_configs): | ||
configs = [] | ||
config_pattern = re.compile(r'\{\s*\.btnPin = (-?\d+),\s*\.btnPlr = \d+,\s*\.uartSelPin = -?\d+,\s*\.uartSelPlr = \d+,\s*\.ledModePin = (-?\d+),\s*\.ledModePlr = \d+,\s*\.ledPwrPin = (-?\d+),\s*\.ledPwrPlr = \d+\s*\}', re.DOTALL) | ||
for config_match in config_pattern.finditer(mist_configs): | ||
config = { | ||
'btnPin': int(config_match.group(1)), | ||
'ledModePin': int(config_match.group(2)), | ||
'ledPwrPin': int(config_match.group(3)), | ||
} | ||
configs.append(config) | ||
print(f"Extracted mistConfig: {config}") | ||
return configs | ||
|
||
def read_features_file(features_file_path): | ||
with open(features_file_path, 'r') as file: | ||
return file.read() | ||
|
||
def extract_existing_links(features_content): | ||
device_links = {} | ||
table_pattern = re.compile(r'\| \[(.*?)\]\((.*?)\)', re.DOTALL) | ||
for match in table_pattern.finditer(features_content): | ||
device_name = match.group(1) | ||
link = match.group(2) | ||
device_links[device_name] = link | ||
print(f"Found link: {device_name} -> {link}") | ||
return device_links | ||
|
||
def update_features_content(features_content, devices, device_links): | ||
# Define the regular expression to match the whole Supported devices section | ||
table_pattern = re.compile(r'(.*## 🎮 Supported devices)(\s+\| .+\|.+?)(\* Some devices do not support all features.*)', re.DOTALL) | ||
match = table_pattern.search(features_content) | ||
if match: | ||
|
||
header = match.group(1) | ||
footer = match.group(3) | ||
|
||
updated_devices_table = "| Device Name | Button | ESP32 LEDs | Remote Network / USB mode selection | Ethernet |\n" | ||
updated_devices_table += "| :---------------------------------------------------------- | :----------------: | :----------------: | :---------------------------------: | :----------------: |\n" | ||
|
||
for device in devices: | ||
device_name = device['name'] | ||
link = device_links.get(device_name, "") | ||
if link: | ||
device_name = f"[{device_name}]({link})" | ||
device_row = f"| {device_name} | {device['button']} | {device['led']} | {device['network_usb']} | {device['eth']} |\n" | ||
updated_devices_table += device_row | ||
|
||
updated_features_content = header + "\n\n" + updated_devices_table + "\n" + footer | ||
print("Updated features content") | ||
return updated_features_content | ||
print("Supported devices section not found") | ||
return features_content | ||
|
||
def write_features_file(features_file_path, updated_content): | ||
with open(features_file_path, 'w') as file: | ||
file.write(updated_content) | ||
print(f"Updated features file: {features_file_path}") | ||
|
||
def main(): | ||
hw_file_path = 'main_branch/src//const/hw.cpp' | ||
features_file_path = 'mkdocs_branch/docs/features.md' | ||
|
||
hw_content = read_hw_file(hw_file_path) | ||
print(f"Read hw.cpp content: {len(hw_content)} characters") | ||
|
||
brd_configs = parse_brd_configs(hw_content) | ||
mist_configs = parse_mist_configs(hw_content) | ||
|
||
devices = extract_devices(brd_configs, mist_configs) | ||
|
||
features_content = read_features_file(features_file_path) | ||
print(f"Read features.md content: {len(features_content)} characters") | ||
|
||
device_links = extract_existing_links(features_content) | ||
|
||
updated_content = update_features_content(features_content, devices, device_links) | ||
|
||
write_features_file(features_file_path, updated_content) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ jobs: | |
uses: actions/checkout@v3 | ||
with: | ||
submodules: "recursive" | ||
fetch-depth: 0 | ||
|
||
- name: Get Release tag | ||
id: get_tag | ||
|
@@ -53,7 +54,7 @@ jobs: | |
python-version: "3.9" | ||
|
||
- name: Install PlatformIO Core | ||
run: pip install --upgrade platformio==6.1.11 | ||
run: pip install --upgrade platformio==6.1.15 | ||
|
||
- name: Build PlatformIO Project | ||
run: pio run | ||
|
@@ -97,6 +98,29 @@ jobs: | |
EOF | ||
echo "Manifest file created." | ||
- name: Get the latest commit SHA for the whole project | ||
id: get_fw_commit_sha | ||
run: echo "::set-output name=fw_commit_sha::$(git log -n 1 --pretty=format:%h)" | ||
|
||
- name: Get the latest commit SHA in src/websrc | ||
id: get_fs_commit_sha | ||
run: echo "::set-output name=fs_commit_sha::$(git log -n 1 --pretty=format:%h -- src/websrc)" | ||
|
||
- name: Create xzg.json for firmware update | ||
run: | | ||
cat << EOF > xzg.json | ||
{ | ||
"name": "XZG Firmware", | ||
"version": "${{ steps.get_tag.outputs.tag }}", | ||
"fw_sha": "${{ steps.get_fw_commit_sha.outputs.fw_commit_sha }}", | ||
"fs_sha": "${{ steps.get_fs_commit_sha.outputs.fs_commit_sha }}" | ||
} | ||
EOF | ||
echo "xzg.json file created." | ||
- name: Display xzg.json | ||
run: cat xzg.json | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
|
@@ -106,6 +130,7 @@ jobs: | |
files: | | ||
bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin | ||
bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin | ||
bin/XZG_${{ steps.get_tag.outputs.tag }}.fs.bin | ||
- name: Checkout releases branch | ||
uses: actions/checkout@v3 | ||
|
@@ -120,14 +145,32 @@ jobs: | |
cp manifest.json releases/${{ steps.get_tag.outputs.tag }}/ | ||
echo "Files copied to releases directory." | ||
- name: Prepare latest release directory | ||
run: | | ||
if [ -d releases/latest ]; then | ||
rm -rf releases/latest | ||
fi | ||
mkdir -p releases/latest | ||
- name: Copy file to latest release directory | ||
run: | | ||
cp xzg.json releases/latest/ | ||
# cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin releases/latest/XZG.ota.bin | ||
# cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.fs.bin releases/latest/XZG.fs.bin | ||
echo "File copied to latest release directory." | ||
- name: Commit and push files to releases branch | ||
run: | | ||
cd releases | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add . | ||
git commit -m "Add firmware and manifest for version ${{ steps.get_tag.outputs.tag }}" | ||
git push origin releases | ||
if [[ -n $(git status --porcelain) ]]; then | ||
git add . | ||
git commit -m "${{ steps.get_tag.outputs.tag }}" | ||
git push origin releases | ||
else | ||
echo "No changes to commit" | ||
fi | ||
- name: Send Telegram Notification about release | ||
uses: appleboy/telegram-action@master | ||
|
@@ -142,7 +185,7 @@ jobs: | |
- name: Send Discord Notification about release | ||
run: | | ||
json_payload=$(jq -n --arg content "https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }}" '{content: $content}') | ||
curl -H "Content-Type: application/json" \ | ||
-d "{\"content\": \"${{ env.commitMessage }}\n\nhttps://github.com/${{ github.repository }}/releases/tag/${{ env.tag }}\"}" \ | ||
${{ secrets.DISCORD_WEBHOOK }} | ||
-d "$json_payload" \ | ||
${{ secrets.DISCORD_WEBHOOK }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Build Wiki | ||
on: | ||
workflow_dispatch: | ||
workflow_run: | ||
workflows: ["Update devices in wiki"] | ||
types: | ||
- completed | ||
push: | ||
branches: | ||
- mkdocs | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: mkdocs | ||
- name: Configure Git Credentials | ||
run: | | ||
git config user.name github-actions[bot] | ||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.x | ||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV | ||
- uses: actions/cache@v4 | ||
with: | ||
key: mkdocs-material-${{ env.cache_id }} | ||
path: .cache | ||
restore-keys: | | ||
mkdocs-material- | ||
- run: pip install mkdocs-material | ||
- run: pip install -r requirements.txt | ||
- run: mkdocs gh-deploy --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Update devices in wiki | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- src/const/hw.cpp | ||
|
||
jobs: | ||
update-devices: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout main branch | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: main | ||
path: main_branch | ||
|
||
- name: Checkout mkdocs branch | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: mkdocs | ||
path: mkdocs_branch | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
- name: Run update_devices.py | ||
run: python main_branch/.github/scripts/update_devices.py | ||
|
||
- name: Commit and push changes | ||
run: | | ||
cd mkdocs_branch | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
if [[ -n $(git status --porcelain) ]]; then | ||
git add docs/features.md | ||
git commit -m 'Update features.md with new device data' | ||
git push origin mkdocs | ||
else | ||
echo "No changes to commit" | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cmake_minimum_required(VERSION 3.16.0) | ||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(XZG) | ||
|
Oops, something went wrong.