Skip to content

Commit

Permalink
20240525.1
Browse files Browse the repository at this point in the history
        - Fix link to new issue
- Try to fix mDNS don't work #30
- Reworked build_fw.yml to use tag as version
- Updated version_update.py to save suffix, if version == today
  • Loading branch information
xyzroe committed May 25, 2024
1 parent 065c262 commit 6b259e6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 50 deletions.
51 changes: 27 additions & 24 deletions .github/workflows/build_fw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Build, release, push firmware

permissions:
contents: write

on:
workflow_dispatch:
push:
tags:
- '*' # Push events to matching *, any
- "*"

jobs:
build_release_push:
Expand All @@ -16,7 +16,24 @@ jobs:
- name: Clone repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"

- name: Get Release tag
id: get_tag
shell: bash
run: |
value=${GITHUB_REF#refs/tags/}
echo "tag=$value" >> $GITHUB_OUTPUT
- name: Display src/version.h before update
run: cat src/version.h

- name: Update version in source code
run: |
sed -i 's/#define VERSION.*/#define VERSION "${{ steps.get_tag.outputs.tag }}"/' src/version.h
- name: Display src/version.h after update
run: cat src/version.h

- name: Install Node JS
uses: actions/setup-node@v3
Expand All @@ -33,28 +50,14 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: "3.9"

- name: Install PlatformIO Core
run: pip install --upgrade platformio==6.1.11

- name: Build PlatformIO Project
run: pio run

- name: Get Release Version
id: get_version
shell: bash
run: |
value=$(grep '#define VERSION' src/version.h | awk -F '"' '{print $2}')
echo "version=$value" >> $GITHUB_OUTPUT
- name: Get Release tag
id: get_tag
shell: bash
run: |
value=${GITHUB_REF#refs/tags/}
echo "tag=$value" >> $GITHUB_OUTPUT
- name: Get last commit message
id: get_commit_message
run: |
Expand Down Expand Up @@ -84,7 +87,7 @@ jobs:
"improv": false,
"parts": [
{
"path": "https://raw.githubusercontent.com/${{ github.repository }}/releases/${{ steps.get_tag.outputs.tag }}/XZG_${{ steps.get_version.outputs.version }}.full.bin",
"path": "https://raw.githubusercontent.com/${{ github.repository }}/releases/${{ steps.get_tag.outputs.tag }}/XZG_${{ steps.get_tag.outputs.tag }}.full.bin",
"offset": 0
}
]
Expand All @@ -98,11 +101,11 @@ jobs:
uses: softprops/action-gh-release@v1
with:
generate_release_notes: false
name: "${{ steps.get_version.outputs.version }}"
name: "${{ steps.get_tag.outputs.tag }}"
body: ${{ env.releaseMessage }}
files: |
bin/XZG_${{ steps.get_version.outputs.version }}.ota.bin
bin/XZG_${{ steps.get_version.outputs.version }}.full.bin
bin/XZG_${{ steps.get_tag.outputs.tag }}.ota.bin
bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin
- name: Checkout releases branch
uses: actions/checkout@v3
Expand All @@ -113,7 +116,7 @@ jobs:
- name: Copy files to releases directory
run: |
mkdir -p releases/${{ steps.get_tag.outputs.tag }}
cp ./bin/XZG_${{ steps.get_version.outputs.version }}.full.bin releases/${{ steps.get_tag.outputs.tag }}/
cp ./bin/XZG_${{ steps.get_tag.outputs.tag }}.full.bin releases/${{ steps.get_tag.outputs.tag }}/
cp manifest.json releases/${{ steps.get_tag.outputs.tag }}/
echo "Files copied to releases directory."
Expand All @@ -135,4 +138,4 @@ jobs:
message: |
${{ env.commitMessage }}
[${{ steps.get_tag.outputs.tag }}](https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }})
[${{ steps.get_tag.outputs.tag }}](https://github.com/${{ github.repository }}/releases/tag/${{ steps.get_tag.outputs.tag }})
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void startServers(bool usb = false)
mqttConnectSetup();
}
}
mDNS_start();

initWebServer();

startAP(false);
Expand Down Expand Up @@ -162,6 +162,7 @@ void handleTmrNetworkOverseer()
if (WiFi.isConnected())
{
LOGD("WIFI CONNECTED");
mDNS_start();
tmrNetworkOverseer.stop();
}
else
Expand All @@ -181,6 +182,7 @@ void handleTmrNetworkOverseer()
if (vars.connectedEther)
{
LOGD("LAN CONNECTED");
mDNS_start();
tmrNetworkOverseer.stop();
}
else
Expand Down Expand Up @@ -279,7 +281,6 @@ void NetworkEvent(WiFiEvent_t event)
WiFi.localIP().toString().c_str(),
WiFi.subnetMask().toString().c_str(),
WiFi.gatewayIP().toString().c_str());

break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED: // SYSTEM_EVENT_STA_DISCONNECTED:
LOGD("%s STA DISCONNECTED", wifiKey);
Expand Down Expand Up @@ -415,7 +416,6 @@ void connectWifi()

void mDNS_start()
{
String tag = "mDNS";
const char *host = "_xzg";
const char *http = "_http";
const char *tcp = "_tcp";
Expand All @@ -425,7 +425,7 @@ void mDNS_start()
}
else
{
LOGD("mDNS responder started");
LOGI("mDNS responder started on %s.local", String(systemCfg.hostname));
//----- WEB ------
mDNS.addService(http, tcp, 80);
//--zeroconf zha--
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AUTO GENERATED FILE
#ifndef VERSION
#define VERSION "20240525"
#define VERSION "20240525.1"
#endif
2 changes: 1 addition & 1 deletion src/websrc/html/PAGE_ABOUT.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h4 class="fw-bold mb-0" data-i18n="p.ab.cm.t"></h4>
<h4 class="fw-bold mb-0" data-i18n="p.ab.r.t"></h4>
<p data-i18n="p.ab.r.m"></p>
<p class="text-center">
<a class="about_link" href="https://github.com/xyzroe/xzg/issues/new" target="_blank" data-i18n="p.ab.r.l"></a>
<a class="about_link" href="https://github.com/xyzroe/XZG/issues/new/choose" target="_blank" data-i18n="p.ab.r.l"></a>
</p>
</div>
</div>
Expand Down
56 changes: 36 additions & 20 deletions tools/build/version_update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Create version header and tracker file if missing """

import datetime
import os
import sys
Expand All @@ -9,37 +8,54 @@
VERSION_HEADER = "version.h"

sys.path.append("./tools")
from func import print_logo
from func import print_colored
from func import print_logo, print_colored

print_logo()

def get_formatted_date(dateTimeBuild):
formatted_date = dateTimeBuild.strftime("%Y%m%d")
return formatted_date

dateTimeBuild = datetime.datetime.now()

HEADER_FILE = """// AUTO GENERATED FILE
return dateTimeBuild.strftime("%Y%m%d")

def read_version_from_file(file_path):
if os.path.exists(file_path):
with open(file_path, "r") as file:
for line in file:
if "#define VERSION" in line:
version = line.split('"')[1]
return version
return None

def write_version_to_file(file_path, version):
header_content = f"""// AUTO GENERATED FILE
#ifndef VERSION
#define VERSION "{}"
#define VERSION "{version}"
#endif
""".format(
get_formatted_date(dateTimeBuild)
)
"""
with open(file_path, "w") as file:
file.write(header_content)

dateTimeBuild = datetime.datetime.now()
current_date = get_formatted_date(dateTimeBuild)

if os.environ.get("PLATFORMIO_INCLUDE_DIR") is not None:
VERSION_HEADER = (
os.environ.get("PLATFORMIO_INCLUDE_DIR") + os.sep + VERSION_HEADER
)
VERSION_HEADER = os.environ.get("PLATFORMIO_INCLUDE_DIR") + os.sep + VERSION_HEADER
elif os.path.exists("src"):
VERSION_HEADER = "src" + os.sep + VERSION_HEADER
else:
PROJECT_DIR = env.subst("$PROJECT_DIR")
os.mkdir(PROJECT_DIR + os.sep + "include")
if not os.path.exists(PROJECT_DIR + os.sep + "include"):
os.mkdir(PROJECT_DIR + os.sep + "include")
VERSION_HEADER = "include" + os.sep + VERSION_HEADER

with open(VERSION_HEADER, "w+") as FILE:
FILE.write(HEADER_FILE)
current_version = read_version_from_file(VERSION_HEADER)

if current_version:
if current_version.startswith(current_date):
new_version = current_version
else:
new_version = current_date
else:
new_version = current_date

write_version_to_file(VERSION_HEADER, new_version)

print_colored("Build: {}".format(str(get_formatted_date(dateTimeBuild))), "magenta")
print_colored(f"Build: {new_version}", "magenta")

0 comments on commit 6b259e6

Please sign in to comment.