From 629d1b559be152caa1ed5d3ec56738f7a3adc340 Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Sun, 29 Jan 2023 19:04:51 +1000 Subject: [PATCH] New CI workflow (#292) * New CI workflow * fix for incorrect version handling * add normal CI workflow * only trigger on pushes to master --- .github/workflows/ci.yml | 35 ++++++++----- .github/workflows/create_release.yml | 73 ---------------------------- .github/workflows/create_tag.yml | 59 ++++++++++++++++++++++ .github/workflows/publish.yml | 27 ++++++++++ .github/workflows/pull_request.yml | 23 +++++++++ scripts/buildinfo.py | 8 --- scripts/bump_version.py | 16 ------ scripts/readprops.py | 35 ------------- version | 1 + version.properties | 4 -- 10 files changed, 132 insertions(+), 149 deletions(-) delete mode 100644 .github/workflows/create_release.yml create mode 100644 .github/workflows/create_tag.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/pull_request.yml delete mode 100755 scripts/buildinfo.py delete mode 100755 scripts/bump_version.py delete mode 100644 scripts/readprops.py create mode 100644 version delete mode 100644 version.properties diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4919592..c93f78b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,27 @@ -name: pull-request -on: pull_request +name: Push commit to schema registry + +on: + push: + branches: + - master + jobs: - build: + push_to_registry: runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 - - uses: bufbuild/buf-setup-action@v1 + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Buf + uses: bufbuild/buf-setup-action@v1 with: github_token: ${{ github.token }} - - uses: bufbuild/buf-lint-action@v1 - - uses: bufbuild/buf-breaking-action@v1 - with: - against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=master" - - uses: bufbuild/buf-push-action@v1 - with: - buf_token: ${{ secrets.BUF_TOKEN }} - draft: ${{ github.ref_name != 'master'}} + + - name: Push to schema registry + # uses: bufbuild/buf-push-action@v1 + # with: + # buf_token: ${{ secrets.BUF_TOKEN }} + run: | + export BUF_TOKEN=${{ secrets.BUF_TOKEN }} + buf push --tag latest --tag ${{ github.sha }} diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml deleted file mode 100644 index fce2428..0000000 --- a/.github/workflows/create_release.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: "CI" -on: - push: - branches: - - master - pull_request: - branches: - - master - workflow_dispatch: - -jobs: - lint: - if: ${{ github.event_name != 'workflow_dispatch' }} - runs-on: ubuntu-latest - - steps: - - name: checkout source - uses: actions/checkout@v3 - - - uses: bufbuild/buf-setup-action@v1 - - uses: bufbuild/buf-lint-action@v1 - - uses: bufbuild/buf-breaking-action@v1 - with: - against: "https://github.com/${GITHUB_REPOSITORY}.git#branch=master" - - 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 diff --git a/.github/workflows/create_tag.yml b/.github/workflows/create_tag.yml new file mode 100644 index 0000000..494f0ed --- /dev/null +++ b/.github/workflows/create_tag.yml @@ -0,0 +1,59 @@ +name: Increment version and create tag + +on: + workflow_dispatch: + inputs: + increment_type: + type: choice + description: "Select the type of version increment" + required: true + options: + - patch + - minor + - major + +jobs: + increment_version: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Get current version + run: | + VERSION=$(cat version | grep version: | awk '{print $2}') + + - name: Increment version + run: | + # Split version into major, minor, and patch + MAJOR=$(echo $VERSION | awk -F '.' '{print $1}' | cut -c 2-) + MINOR=$(echo $VERSION | awk -F '.' '{print $2}') + PATCH=$(echo $VERSION | awk -F '.' '{print $3}') + + # Increment the appropriate part of the version + if [[ ${{ inputs.increment_type }} == "patch" ]]; then + PATCH=$((PATCH + 1)) + elif [[ ${{ inputs.increment_type }} == "minor" ]]; then + MINOR=$((MINOR + 1)) + PATCH=0 + elif [[ ${{ inputs.increment_type }} == "major" ]]; then + MAJOR=$((MAJOR + 1)) + MINOR=0 + PATCH=0 + fi + + # Update the version + NEW_VERSION="v$MAJOR.$MINOR.$PATCH" + sed -i "s/version: $VERSION/version: $NEW_VERSION/" version + + - name: Commit and push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Release $NEW_VERSION" + push: true + + - name: Create tag + run: | + git tag $NEW_VERSION + git push origin $NEW_VERSION diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6a7c2b9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,27 @@ +name: Push new version to schema registry + +on: + push: + tags: + - "v*" + +jobs: + push_to_registry: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ github.token }} + + - name: Push to schema registry + # uses: bufbuild/buf-push-action@v1 + # with: + # buf_token: ${{ secrets.BUF_TOKEN }} + run: | + export BUF_TOKEN=${{ secrets.BUF_TOKEN }} + buf push --tag ${{ github.ref_name }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..a7b6e68 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,23 @@ +name: pull-request +on: pull_request +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Buf + uses: bufbuild/buf-setup-action@v1 + with: + github_token: ${{ github.token }} + + - name: Lint + uses: bufbuild/buf-lint-action@v1 + + - name: Push to schema registry + uses: bufbuild/buf-push-action@v1 + with: + buf_token: ${{ secrets.BUF_TOKEN }} + draft: ${{ github.ref_name != 'master'}} diff --git a/scripts/buildinfo.py b/scripts/buildinfo.py deleted file mode 100755 index 4865f90..0000000 --- a/scripts/buildinfo.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/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 deleted file mode 100755 index 6128fad..0000000 --- a/scripts/bump_version.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/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 deleted file mode 100644 index 94199c4..0000000 --- a/scripts/readprops.py +++ /dev/null @@ -1,35 +0,0 @@ -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 b/version new file mode 100644 index 0000000..a025224 --- /dev/null +++ b/version @@ -0,0 +1 @@ +v2.0.15 \ No newline at end of file diff --git a/version.properties b/version.properties deleted file mode 100644 index 8ad7a80..0000000 --- a/version.properties +++ /dev/null @@ -1,4 +0,0 @@ -[VERSION] -major = 2 -minor = 0 -build = 16