Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to automated builds #441

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
Version: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
run: |
sed -i "s/unknownbuildnr/$Version/g" src/Config.h
python3 resources/config_version.py beta
- name: Build ${{ matrix.build }} PlatformIO Project ${{ matrix.board }}
run: |
if [ "$BUILD" = "debug" ]; then
Expand Down Expand Up @@ -97,7 +98,21 @@ jobs:
- name: Git Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
ref: binary
- name: Git Checkout master
uses: actions/checkout@v4
with:
ref: master
path: master
sparse-checkout: |
resources/ota_manifest.py
src/Config.h
- name: Git Commands
run: |
git checkout --orphan newBinary
git branch -D binary
git branch -M binary
git rm --cached --ignore-unmatch -r *
- name: Download release assets
uses: actions/download-artifact@v4
with:
Expand All @@ -108,17 +123,23 @@ jobs:
Version: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
run: |
mkdir -p ota/beta/
mkdir -p resources/
mkdir -p src/
cp -vf release/*/nuki_hub_*.bin ota/beta/
rm -rf release
cp -vf master/resources/ota_manifest.py resources/ota_manifest.py
cp -vf master/src/Config.h src/Config.h
python3 resources/ota_manifest.py beta $Version
- name: Commit binaries to master
find * -not -path "ota*" -not -path "webflash*" -delete
rm -rf .github .gitignore .gitmodules
- name: Commit binaries to binary
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update beta binaries"
file_pattern: 'ota/beta/*.bin ota/manifest.json'
branch: master
commit_message: "Update binaries"
file_pattern: 'ota/* ota/master/* ota/beta/* webflash/*'
branch: binary
skip_dirty_check: true
skip_fetch: true
skip_checkout: true
disable_globbing: true
add_options: '-f'
push_options: '-f'
39 changes: 29 additions & 10 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ jobs:
submodules: recursive
- name: Get new commits
run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV
- name: Check if commits larger than 1
if: ${{ env.NEW_COMMIT_COUNT < 2 }}
- name: Check if commits larger than 0
if: ${{ env.NEW_COMMIT_COUNT < 1 }}
run: exit 1
build:
name: Build ${{ matrix.board }} (${{ matrix.build }})
if: github.repository == 'technyon/nuki_hub'
needs: check-commits
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -67,6 +66,7 @@ jobs:
Version: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
run: |
sed -i "s/unknownbuildnr/$Version/g" src/Config.h
python3 resources/config_version.py master
- name: Build ${{ matrix.build }} PlatformIO Project ${{ matrix.board }}
run: |
if [ "$BUILD" = "debug" ]; then
Expand Down Expand Up @@ -109,14 +109,27 @@ jobs:
path: ${{ matrix.build }}/${{ env.VARIANT }}
ota-nightly:
name: Create nightly from latest master
if: github.repository == 'technyon/nuki_hub'
needs: build
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
ref: binary
- name: Git Checkout master
uses: actions/checkout@v4
with:
ref: master
path: master
sparse-checkout: |
resources/ota_manifest.py
src/Config.h
- name: Git Commands
run: |
git checkout --orphan newBinary
git branch -D binary
git branch -M binary
git rm --cached --ignore-unmatch -r *
- name: Download release assets
uses: actions/download-artifact@v4
with:
Expand All @@ -127,17 +140,23 @@ jobs:
Version: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
run: |
mkdir -p ota/master/
mkdir -p resources/
mkdir -p src/
cp -vf release/*/nuki_hub_*.bin ota/master/
rm -rf release
cp -vf master/resources/ota_manifest.py resources/ota_manifest.py
cp -vf master/src/Config.h src/Config.h
python3 resources/ota_manifest.py master $Version
- name: Commit binaries to master
find * -not -path "ota*" -not -path "webflash*" -delete
rm -rf .github .gitignore .gitmodules
- name: Commit binaries to binary
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update master binaries"
file_pattern: 'ota/master/*.bin ota/manifest.json'
branch: master
commit_message: "Update binaries"
file_pattern: 'ota/* ota/master/* ota/beta/* webflash/*'
branch: binary
skip_dirty_check: true
skip_fetch: true
skip_checkout: true
disable_globbing: true
add_options: '-f'
push_options: '-f'
41 changes: 30 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,24 @@ jobs:
- name: Git Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
ref: binary
- name: Git Checkout master
uses: actions/checkout@v4
with:
ref: master
path: master
sparse-checkout: |
resources/ota_manifest.py
src/Config.h
- name: Git Commands
run: |
git checkout --orphan newBinary
git branch -D binary
git branch -M binary
git rm --cached --ignore-unmatch -r *
- name: Get the version
id: get_version
run: echo "VERSION=$(cat src/Config.h | grep -oP '(?<=#define NUKI_HUB_VERSION \")(.*)(?=\")')" >> $GITHUB_OUTPUT
run: echo "VERSION=$(cat master/src/Config.h | grep -oP '(?<=#define NUKI_HUB_VERSION \")(.*)(?=\")')" >> $GITHUB_OUTPUT
- name: Download release assets
uses: actions/download-artifact@v4
with:
Expand Down Expand Up @@ -167,22 +181,27 @@ jobs:
env:
Version: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }}
run: |
mkdir -p ota/
mkdir -p resources/
mkdir -p src/
cp -vf release/*/nuki_hub_*.bin ota/
cp -vf release/*/webflash_nuki_hub_*.bin webflash/
rm -rf release
rm -rf debug
rm -rf NukiHub-*.zip
git rm -r --cached ota/beta/*.bin
cp -vf master/resources/ota_manifest.py resources/ota_manifest.py
cp -vf master/src/Config.h src/Config.h
python3 resources/ota_manifest.py release $Version
python3 resources/ota_manifest.py beta none
- name: Commit binaries to master
find * -not -path "ota*" -not -path "webflash*" -delete
rm -rf ota/beta/*.bin
rm -rf .github .gitignore .gitmodules
- name: Commit binaries to binary
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update binaries for version ${{ steps.get_version.outputs.VERSION }}"
file_pattern: 'ota/*.bin ota/manifest.json ota/beta/*.bin webflash/*.bin'
branch: master
commit_message: "Update binaries"
file_pattern: 'ota/* ota/master/* webflash/*'
branch: binary
skip_dirty_check: true
skip_fetch: true
skip_checkout: true
disable_globbing: true
add_options: '-f'
add_options: '-f'
push_options: '-f'
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1>Nuki Hub</h1>
type="module"
src="https://unpkg.com/esp-web-tools@8.0.1/dist/web/install-button.js?module">
</script>
<esp-web-install-button id="installButton" manifest="webflash/manifest.json"></esp-web-install-button>
<esp-web-install-button id="installButton" manifest="https://raw.githubusercontent.com/technyon/nuki_hub/binary/webflash/manifest.json"></esp-web-install-button>
<br><br><br><br>
Note: If flashing doesn't work, press and hold the "BOOT" switch, then click "Install".
</div>
Expand Down
12 changes: 12 additions & 0 deletions pio_package_pre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re, shutil, os
from datetime import datetime, timezone

regex = r"\#define NUKI_HUB_DATE \"(.*)\""
content_new = ""

with open ('src/Config.h', 'r' ) as readfile:
file_content = readfile.read()
content_new = re.sub(regex, "#define NUKI_HUB_DATE \"" + datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S") + "\"", file_content, flags = re.M)

with open('src/Config.h', 'w') as writefile:
writefile.write(content_new)
8 changes: 6 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ monitor_filters =

[env:esp32dev]
board = esp32dev
extra_scripts = post:pio_package.py
extra_scripts =
pre:pio_package_pre.py
post:pio_package.py
build_flags =
${env.build_flags}
-DBLESCANNER_USE_LATEST_NIMBLE
Expand Down Expand Up @@ -87,7 +89,9 @@ board = esp32-c6-devkitm-1
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip
framework = arduino
board = esp32-solo1
extra_scripts = post:pio_package.py
extra_scripts =
pre:pio_package_pre.py
post:pio_package.py
build_flags =
${env.build_flags}
-DFRAMEWORK_ARDUINO_SOLO1
Expand Down
40 changes: 40 additions & 0 deletions resources/config_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import re, json, argparse
from urllib.request import urlopen

parser = argparse.ArgumentParser()

parser.add_argument('ota_type', type=str)
args = parser.parse_args()

regex = r"\#define NUKI_HUB_VERSION \"(.*)\""
version = "unknown"

with open('src/Config.h', 'r') as file:
file_content = file.read()
matches = re.finditer(regex, file_content, re.MULTILINE)

for matchNum, match in enumerate(matches, start=1):
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
version = match.group(groupNum)

data = ""
number = 1

response = urlopen("https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json")
data = json.loads(response.read().decode("utf-8"))
if ("number" not in data[args.ota_type]):
number = 1
elif (data[args.ota_type]['version'] == version):
number = data[args.ota_type]['number'] + 1
else:
number = 1

content_new = ""

with open ('src/Config.h', 'r' ) as readfile:
file_content = readfile.read()
content_new = re.sub(regex, "#define NUKI_HUB_VERSION \"" + str(version) + "-" + args.ota_type + str(number) + "\"", file_content, flags = re.M)

with open('src/Config.h', 'w') as writefile:
writefile.write(content_new)
8 changes: 8 additions & 0 deletions resources/ota_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
data[args.ota_type]['time'] = "0000-00-00 00:00:00"
data[args.ota_type]['version'] = "No beta available"
data[args.ota_type]['build'] = ""
del(data[args.ota_type]['number'])
else:
if ("number" not in data[args.ota_type]):
data[args.ota_type]['number'] = 1
elif (data[args.ota_type]['version'] == version):
data[args.ota_type]['number'] = data[args.ota_type]['number'] + 1
else:
data[args.ota_type]['number'] = 1

data[args.ota_type]['time'] = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
data[args.ota_type]['version'] = version
data[args.ota_type]['build'] = args.build
Expand Down
Loading