From 49e6554acdfea263b8a0ec25fcd7ddfef300abfb Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 20 Jul 2023 02:00:09 +0100 Subject: [PATCH] Rework workflows and add devbuilds --- .github/workflow_data/commit.sh | 4 ++ .github/workflow_data/devbuild.py | 65 +++++++++++++++++++++++++++++++ .github/workflow_data/version.sh | 9 ++++- .github/workflows/build.yml | 45 +++++++++------------ .github/workflows/hotfix.yml | 8 ++-- .github/workflows/release.yml | 10 ++--- fbt_options.py | 4 +- scripts/version.py | 7 +--- 8 files changed, 107 insertions(+), 45 deletions(-) create mode 100644 .github/workflow_data/commit.sh create mode 100644 .github/workflow_data/devbuild.py diff --git a/.github/workflow_data/commit.sh b/.github/workflow_data/commit.sh new file mode 100644 index 000000000..ddfe7040f --- /dev/null +++ b/.github/workflow_data/commit.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +export VERSION_TAG="$(python -c 'import fbt_options; print(fbt_options.DIST_SUFFIX, end="")')" +echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV diff --git a/.github/workflow_data/devbuild.py b/.github/workflow_data/devbuild.py new file mode 100644 index 000000000..efd988c89 --- /dev/null +++ b/.github/workflow_data/devbuild.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +import nextcloud_client +import datetime as dt +import requests +import json +import os + +dev_share = os.environ["NC_HOST"] + "s/sGHsQB94a9x5CRs/download?path=/&files={files}" + +if __name__ == "__main__": + with open(os.environ["GITHUB_EVENT_PATH"], "r") as f: + event = json.load(f) + + client = nextcloud_client.Client(os.environ["NC_HOST"]) + client.login(os.environ["NC_USER"], os.environ["NC_PASS"]) + + for file in ( + os.environ["ARTIFACT_TGZ"], + os.environ["ARTIFACT_SDK"], + ): + path = f"XFW-Dev/{file}" + # try: + # client.delete(path) + # except Exception: + # pass + client.put_file(path, file) + + requests.post( + os.environ["BUILD_WEBHOOK"], + headers={"Accept": "application/json", "Content-Type": "application/json"}, + json={ + "content": None, + "embeds": [ + { + "title": "Devbuild infos:", + "description": "", + "url": "", + "color": 16734443, + "fields": [ + { + "name": "Changes since last commit:", + "value": f"[Compare {event['before']} to {event['after']}]({event['compare']})" + }, + { + "name": "Changes since last release:", + "value": f"[Compare release to {event['after']}]({event['compare'].replace(event['before'], 'main')})" + }, + { + "name": "Firmware download:", + "value": f"- [Download SDK for development]({dev_share.format(files=os.environ['ARTIFACT_SDK'])})\n- [Download Firmware TGZ]({dev_share.format(files=os.environ['ARTIFACT_TGZ'])})" + } + ], + "author": { + "name": "Build Succeeded!", + "icon_url": "https://cdn.discordapp.com/emojis/1080005692485795930.png" + }, + "footer": { + "text": "Build go brrrr", + "icon_url": "https://cdn.discordapp.com/emojis/1059798228725403719.png" + }, + "timestamp": dt.datetime.utcnow().isoformat() + } + ], + }, + ) diff --git a/.github/workflow_data/version.sh b/.github/workflow_data/version.sh index b2ba35187..955a78167 100644 --- a/.github/workflow_data/version.sh +++ b/.github/workflow_data/version.sh @@ -1,4 +1,11 @@ #!/bin/bash -export VERSION_TAG="$(python -c 'import fbt_options; print(fbt_options.DIST_SUFFIX)')" +export VERSION_TAG="$(python -c ''' +import datetime as dt +with open(os.environ["GITHUB_EVENT_PATH"], "r") as f: + event = json.load(f) +version = int(event["pull_request"]["title"].removeprefix("V").removesuffix(" Release").removesuffix(" Hotfix")) +date = dt.datetime.now().strftime("%d%m%Y") +print(f"XFW-{version:04}_{date}", end="") +''')" echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac912a8c5..e7cbb7a4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,47 +24,38 @@ jobs: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} + - name: "Read version tag" + run: bash .github/workflow_data/commit.sh + - name: 'Build the firmware' run: | set -e for TARGET in ${TARGETS}; do TARGET_HW="$(echo "${TARGET}" | sed 's/f//')"; \ - ./fbt TARGET_HW=$TARGET_HW updater_package + ./fbt TARGET_HW=$TARGET_HW DIST_SUFFIX=$VERSION_TAG updater_package done - name: "Check for uncommitted changes" run: | git diff --exit-code - - name: 'Updater artifact' + - name: 'Dist artifact' uses: actions/upload-artifact@v3 with: - name: updater + name: dist path: | dist/${{ env.DEFAULT_TARGET }}-*/ - # - name: 'Find Previous Comment' - # if: ${{ github.event.pull_request }} - # uses: peter-evans/find-comment@v1 - # id: fc - # with: - # issue-number: ${{ github.event.pull_request.number }} - # comment-author: 'github-actions[bot]' - # body-includes: 'Compiled firmware:' + - name: "Make tgz, zip and sdk" + run: bash .github/workflow_data/package.sh - # - name: Artifact info - # id: artifact-info - # uses: dawidd6/action-download-artifact@v2 - # with: - # dry_run: true - - # - name: 'Create or update comment' - # if: ${{ github.event.pull_request}} - # uses: peter-evans/create-or-update-comment@v1 - # with: - # comment-id: ${{ steps.fc.outputs.comment-id }} - # issue-number: ${{ github.event.pull_request.number }} - # body: | - # **Compiled firmware:** - # - [📦 Update package](${{steps.artifact-info.outputs.artifacts[0].archive_download_url}}) - # edit-mode: replace + - name: Send devbuild webhook + if: "github.event_name == 'push' && endsWith(github.event.push.ref, '/dev')" + env: + NC_HOST: "https://cloud.cynthialabs.net/" + NC_USER: "${{ secrets.NC_USER }}" + NC_PASS: "${{ secrets.NC_PASS }}" + BUILD_WEBHOOK: ${{ secrets.BUILD_WEBHOOK }} + run: | + python -m pip install pyncclient + python .github/workflow_data/devbuild.py diff --git a/.github/workflows/hotfix.yml b/.github/workflows/hotfix.yml index e4a4982b5..38076ae18 100644 --- a/.github/workflows/hotfix.yml +++ b/.github/workflows/hotfix.yml @@ -31,21 +31,21 @@ jobs: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} + - name: "Read version tag" + run: bash .github/workflow_data/version.sh + - name: 'Build the firmware' run: | set -e for TARGET in ${TARGETS}; do TARGET_HW="$(echo "${TARGET}" | sed 's/f//')"; \ - ./fbt TARGET_HW=$TARGET_HW FORCE_NO_DIRTY=1 updater_package + ./fbt TARGET_HW=$TARGET_HW DIST_SUFFIX=$VERSION_TAG FORCE_NO_DIRTY=1 updater_package done - name: "Check for uncommitted changes" run: | git diff --exit-code - - name: "Read version tag" - run: bash .github/workflow_data/version.sh - - name: "Make tgz, zip and sdk" run: bash .github/workflow_data/package.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a73af726e..47c103807 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: release: if: | github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && - endsWith(github.event.pull_request.title, ' Release Candidate Changes') && + endsWith(github.event.pull_request.title, ' Release') && github.event.review.author_association == 'OWNER' && startsWith(github.event.pull_request.title, 'V') && github.event.pull_request.base.ref == 'main' && @@ -31,21 +31,21 @@ jobs: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} + - name: "Read version tag" + run: bash .github/workflow_data/version.sh + - name: 'Build the firmware' run: | set -e for TARGET in ${TARGETS}; do TARGET_HW="$(echo "${TARGET}" | sed 's/f//')"; \ - ./fbt TARGET_HW=$TARGET_HW FORCE_NO_DIRTY=1 updater_package + ./fbt TARGET_HW=$TARGET_HW DIST_SUFFIX=$VERSION_TAG FORCE_NO_DIRTY=1 updater_package done - name: "Check for uncommitted changes" run: | git diff --exit-code - - name: "Read version tag" - run: bash .github/workflow_data/version.sh - - name: "Make tgz, zip and sdk" run: bash .github/workflow_data/package.sh diff --git a/fbt_options.py b/fbt_options.py index efafce09d..f8e42f90d 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -1,6 +1,6 @@ from pathlib import Path +import subprocess import posixpath -import datetime # For more details on these options, run 'fbt -h' @@ -19,7 +19,7 @@ DEBUG = 0 # If OS environment has DIST_SUFFIX set, it will be used instead # How about we add the timestamp automatically. Solves some problems -DIST_SUFFIX = f"XFW-0049_{datetime.datetime.today().strftime('%d%m%Y')}" +DIST_SUFFIX = f"XFW-DEV_@{subprocess.check_output(['git', 'rev-parse', '--short=7', 'HEAD']).decode().strip().upper()}" # Coprocessor firmware COPRO_OB_DATA = "scripts/ob.data" diff --git a/scripts/version.py b/scripts/version.py index 987fd9b96..8ea4ff1a0 100755 --- a/scripts/version.py +++ b/scripts/version.py @@ -1,6 +1,4 @@ #!/usb/bin/env python3 -VERSION = "XFW-0049" - import json import os import subprocess @@ -32,14 +30,11 @@ class GitVersion: # (set by CI) branch = ( os.environ.get("WORKFLOW_BRANCH_OR_TAG", None) - or VERSION or self._exec_git("rev-parse --abbrev-ref HEAD") or "unknown" ) - branch_num = self._exec_git("rev-list --count HEAD") or "n/a" - - version = os.environ.get("DIST_SUFFIX", None) or VERSION or "unknown" + version = os.environ.get("DIST_SUFFIX", None).split("_")[0] or "unknown" force_no_dirty = os.environ.get("FORCE_NO_DIRTY", None) or "" if force_no_dirty != "":