diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e2f63b..6a6b706 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,12 @@ on: pull_request: branches: - master - + workflow_dispatch: + jobs: lint: + if: ${{ github.event_name != 'workflow_dispatch' }} runs-on: ubuntu-latest steps: @@ -20,3 +22,52 @@ jobs: uses: plexsystems/protolint-action@v0.2.0 with: configDirectory: . + + release: + if: ${{ github.event_name == 'workflow_dispatch' }} + runs-on: ubuntu-latest + + steps: + - name: checkout source + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: 3.x + + - name: Cache python libs + uses: actions/cache@v3 + id: cache-pip # needed in if test + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip + + - name: Upgrade python tools + shell: bash + run: | + python -m pip install --upgrade pip + + - name: Get release version string + run: echo "version=$(./scripts/buildinfo.py short)" >> $GITHUB_OUTPUT + id: version + + - name: Create release + uses: actions/create-release@v1 + id: create_release + with: + release_name: Meshtastic Protobufs ${{ steps.version.outputs.version }} + tag_name: v${{ steps.version.outputs.version }} + body: Protobufs for version ${{ steps.version.outputs.version }} release of Meshtastic firmware + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Bump version.properties + run: >- + scripts/bump_version.py + + - name: Create version.properties pull request + uses: peter-evans/create-pull-request@v3 + with: + add-paths: | + version.properties \ No newline at end of file diff --git a/scripts/buildinfo.py b/scripts/buildinfo.py new file mode 100755 index 0000000..4865f90 --- /dev/null +++ b/scripts/buildinfo.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 +import configparser +import sys +from readprops import readProps + +verObj = readProps('version.properties') +propName = sys.argv[1] +print(f"{verObj[propName]}") \ No newline at end of file diff --git a/scripts/bump_version.py b/scripts/bump_version.py new file mode 100755 index 0000000..6128fad --- /dev/null +++ b/scripts/bump_version.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +"""Bump the version number""" + +lines = None + +with open('version.properties', 'r', encoding='utf-8') as f: + lines = f.readlines() + +with open('version.properties', 'w', encoding='utf-8') as f: + for line in lines: + if line.lstrip().startswith("build = "): + words = line.split(" = ") + ver = f'build = {int(words[1]) + 1}' + f.write(f'{ver}\n') + else: + f.write(line) diff --git a/scripts/readprops.py b/scripts/readprops.py new file mode 100644 index 0000000..94199c4 --- /dev/null +++ b/scripts/readprops.py @@ -0,0 +1,35 @@ +import subprocess +import configparser +import traceback +import sys + + +def readProps(prefsLoc): + """Read the version of our project as a string""" + + config = configparser.RawConfigParser() + config.read(prefsLoc) + version = dict(config.items('VERSION')) + verObj = dict(short = "{}.{}.{}".format(version["major"], version["minor"], version["build"]), + long = "unset") + + # Try to find current build SHA if if the workspace is clean. This could fail if git is not installed + try: + sha = subprocess.check_output( + ['git', 'rev-parse', '--short', 'HEAD']).decode("utf-8").strip() + isDirty = subprocess.check_output( + ['git', 'diff', 'HEAD']).decode("utf-8").strip() + suffix = sha + if isDirty: + # short for 'dirty', we want to keep our verstrings source for protobuf reasons + suffix = sha + "-d" + verObj['long'] = "{}.{}.{}.{}".format( + version["major"], version["minor"], version["build"], suffix) + except: + # print("Unexpected error:", sys.exc_info()[0]) + # traceback.print_exc() + verObj['long'] = verObj['short'] + + # print("firmware version " + verStr) + return verObj +# print("path is" + ','.join(sys.path)) diff --git a/version.properties b/version.properties new file mode 100644 index 0000000..816f7c2 --- /dev/null +++ b/version.properties @@ -0,0 +1,4 @@ +[VERSION] +major = 2 +minor = 0 +build = 12