diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5385246 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Create Release + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Get version from tag + id: get_version + run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/} + + - name: Read CHANGELOG.md + id: changelog + run: | + CHANGELOG=$(awk "/## \[${{ steps.get_version.outputs.VERSION }}\]/{p=1;print;next} /## \[/{p=0} p" CHANGELOG.md) + echo "::set-output name=CHANGES::$CHANGELOG" + + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ steps.get_version.outputs.VERSION }} + body: ${{ steps.changelog.outputs.CHANGES }} + draft: false + prerelease: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..286351e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +## [1.0.2] - 2025-02-16 +### Added +- Feature 1 +- Feature 2 + +### Changed +- Change 1 +- Change 2 + +### Fixed +- Fix 1 +- Fix 2 \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index d4d055e..825a2f3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,6 +8,9 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[common] +version = "1.0.2" + [env:esp32dev] platform = espressif32 board = esp32dev @@ -37,7 +40,12 @@ build_flags = -fdata-sections -DNDEBUG -mtext-section-literals + '-D VERSION="${common.version}"' extra_scripts = - pre:gzip_files.py - pre:extra_script.py + pre:scripts/combine_html.py + pre:scripts/pre_build.py + pre:scripts/pre_spiffs.py + pre:scripts/gzip_files.py + pre:scripts/extra_script.py + pre:scripts/update_changelog.py diff --git a/release.sh b/release.sh new file mode 100644 index 0000000..3c5011f --- /dev/null +++ b/release.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Get version from platformio.ini +VERSION=$(grep '^version = ' platformio.ini | sed 's/version = "\(.*\)"/\1/') + +if [ -z "$VERSION" ]; then + echo "Error: Could not find version in platformio.ini" + exit 1 +fi + +echo "Creating release for version $VERSION" + +# Check if working directory is clean +if [ -n "$(git status --porcelain)" ]; then + echo "Error: Working directory is not clean. Please commit all changes first." + exit 1 +fi + +# Create and push tag +git tag "v$VERSION" +if [ $? -ne 0 ]; then + echo "Error: Failed to create tag v$VERSION" + exit 1 +fi + +git push origin "v$VERSION" +if [ $? -ne 0 ]; then + echo "Error: Failed to push tag v$VERSION" + git tag -d "v$VERSION" + exit 1 +fi + +echo "Successfully created and pushed tag v$VERSION" +echo "GitHub Actions workflow will now create the release" \ No newline at end of file diff --git a/scripts/combine_html.py b/scripts/combine_html.py new file mode 100644 index 0000000..b13ccd6 --- /dev/null +++ b/scripts/combine_html.py @@ -0,0 +1,31 @@ +Import("env") +import os + +def combine_html_files(source, target, env): + html_dir = "./html" + header_file = os.path.join(html_dir, "header.html") + + # Read header content + with open(header_file, 'r') as f: + header_content = f.read() + + # Process all HTML files except header.html + for filename in os.listdir(html_dir): + if filename.endswith('.html') and filename != 'header.html': + file_path = os.path.join(html_dir, filename) + + # Read content + with open(file_path, 'r') as f: + content = f.read() + + # Replace placeholder with header content + if '{{header}}' in content: + new_content = content.replace('{{header}}', header_content) + + # Write back combined content + with open(file_path, 'w') as f: + f.write(new_content) + print(f"Combined header with {filename}") + +# Register the script to run before building SPIFFS +env.AddPreAction("buildfs", combine_html_files) \ No newline at end of file diff --git a/extra_script.py b/scripts/extra_script.py similarity index 100% rename from extra_script.py rename to scripts/extra_script.py diff --git a/gzip_files.py b/scripts/gzip_files.py similarity index 95% rename from gzip_files.py rename to scripts/gzip_files.py index 4bb48b2..9035dc5 100644 --- a/gzip_files.py +++ b/scripts/gzip_files.py @@ -14,7 +14,7 @@ def copy_file(input_file, output_file): def should_compress(file): # Komprimiere nur bestimmte Dateitypen - return file.endswith(('.js', '.png', '.css')) + return file.endswith(('.js', '.png', '.css', '.html')) def main(source_dir, target_dir): for root, dirs, files in os.walk(source_dir): diff --git a/scripts/pre_build.py b/scripts/pre_build.py new file mode 100644 index 0000000..a047d85 --- /dev/null +++ b/scripts/pre_build.py @@ -0,0 +1,25 @@ +Import("env") +import os + +def replace_version(source, target, env): + # Get version from common section + version = env.GetProjectConfig().get("common", "version").strip('"') + header_file = "./html/header.html" + + with open(header_file, 'r') as file: + content = file.read() + + # Replace version in header.html using string manipulation instead of regex + search = '