Bob Matcuk 3 лет назад
Родитель
Сommit
6a009dd1a7

+ 46 - 0
.github/workflows/check-for-new-firmware.yml

@@ -0,0 +1,46 @@
+name: Check for New Firmware
+
+on:
+  schedule:
+    - cron: '42 10 * * 0'
+  workflow_dispatch:
+
+jobs:
+  getversion:
+    name: Check for New Firmware
+    runs-on: ubuntu-latest
+    outputs:
+      version: ${{ steps.check.outputs.version }}
+    steps:
+      - name: Checkout Flipper Zero Firmware
+        uses: actions/checkout@v3
+        with:
+          repository: 'flipperdevices/flipperzero-firmware'
+          fetch-depth: 0
+          # we don't need submodules yet - fbt will get them if we build
+          # submodules: true
+      - name: Checkout
+        uses: actions/checkout@v3
+        with:
+          path: 'applications_user/qrcode_app'
+          token: ${{ secrets.CustomGithubToken }}
+          fetch-depth: 0
+      - name: Check Version
+        id: check
+        shell: bash
+        run: applications_user/qrcode_app/scripts/check-firmware.sh "$GITHUB_WORKSPACE"
+      - name: Build
+        if: ${{ steps.check.outputs.version }}
+        shell: bash
+        run: |
+          git checkout "${{ steps.check.outputs.version }}"
+          ./fbt fap_qrcode
+          [ -e build/f7-firmware-D/.extapps/qrcode.fap ]
+      - name: Update Firmware Version
+        if: ${{ steps.check.outputs.version }}
+        shell: bash
+        run: applications_user/qrcode_app/scripts/update-firmware.sh "${{ steps.check.outputs.version }}"
+        env:
+          GIT_USER_NAME: ${{ secrets.GitUserName }}
+          GIT_USER_EMAIL: ${{ secrets.GitUseEmail }}
+          GITHUB_TOKEN: ${{ secrets.CustomGithubToken }}

+ 4 - 1
.github/workflows/release.yml

@@ -5,6 +5,8 @@ on:
     tags:
     tags:
       - 'v[0-9]+.[0-9]+.[0-9]+'
       - 'v[0-9]+.[0-9]+.[0-9]+'
 
 
+env.firmware_version: '0.74.2'
+
 jobs:
 jobs:
   build:
   build:
     name: Build
     name: Build
@@ -14,7 +16,7 @@ jobs:
         uses: actions/checkout@v3
         uses: actions/checkout@v3
         with:
         with:
           repository: 'flipperdevices/flipperzero-firmware'
           repository: 'flipperdevices/flipperzero-firmware'
-          ref: '0.74.2'
+          ref: ${{ env.firmware_version }}
           submodules: true
           submodules: true
       - name: Checkout
       - name: Checkout
         uses: actions/checkout@v3
         uses: actions/checkout@v3
@@ -26,5 +28,6 @@ jobs:
         uses: softprops/action-gh-release@v1
         uses: softprops/action-gh-release@v1
         with:
         with:
           files: build/f7-firmware-D/.extapps/qrcode.fap
           files: build/f7-firmware-D/.extapps/qrcode.fap
+          body: Built against firmware v${{ env.firmware_version }}
           generate_release_notes: true
           generate_release_notes: true
           fail_on_unmatched_files: true
           fail_on_unmatched_files: true

+ 26 - 0
scripts/check-firmware.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+set -Exeuo pipefail
+
+print_status() {
+  local level="$1"
+  local body="${2//%/%25}"
+  body="${body//$'\r'/}"
+  body="${body//$'\n'/%0A}"
+
+  echo "::$level::$body"
+}
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
+FIRMWARE_DIR="$1"
+
+LASTVER="$(git -C "$SCRIPT_DIR" tag | grep firmware-v | sort -V | tail -n1 | sed -e 's/^firmware-v//')"
+print_status notice "last built against firmware version: $LASTVER"
+
+VER="$(git -C "$FIRMWARE_DIR" tag | sed -E -e '/^[0-9]+\.[0-9]+\.[0-9]+$/!d' | sort -V | sed -e "1,/$LASTVER/d" | tail -n1)"
+# VER="$(curl https://api.github.com/repos/flipperdevices/flipperzero-firmware/tags | jq -r --arg current "$LASTVER" 'def ver($v): $v | ltrimstr("v") | split(".") | map(tonumber); map(.name) | map(select(. | test("^\\d+\\.\\d+\\.\\d+$";"s"))) | map(ver(.)) | map(select(. > ver($current))) | sort | last | if . == null then "" else join(".") end')"
+if [ -z "$VER" ]; then
+  print_status notice "no new firmware version"
+  exit 0
+fi
+print_status notice "new firmware version: $VER"
+echo "::set-output name=version::$VER"

+ 43 - 0
scripts/update-firmware.sh

@@ -0,0 +1,43 @@
+#!/bin/bash
+set -Exeuo pipefail
+
+print_status() {
+  local level="$1"
+  local body="${2//%/%25}"
+  body="${body//$'\r'/}"
+  body="${body//$'\n'/%0A}"
+
+  echo "::$level::$body"
+}
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)"
+FIRMWARE_VER="$1"
+
+pushd "$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel)"
+print_status notice "updating to firmware $FIRMWARE_VER"
+
+# setup git
+git config --local user.name $GIT_USER_NAME
+git config --local user.email $GIT_USER_EMAIL
+
+# construct a new version number for the qrcode app
+VER="$(git tag | sed -E -e '/^v[0-9]+\.[0-9]+\.[0-9]+$/!d' | sort -V | tail -n1)"
+if [[ "$VER" =~ ^(v[0-9]+.[0-9]+).([0-9]+)$ ]]; then
+    VER="${BASH_REMATCH[1]}.$(( ${BASH_REMATCH[2]} + 1 ))"
+else
+    print_status warning "couldn't construct new version number from $VER"
+    exit 1
+fi
+print_status notice "new qrcode version: $VER"
+
+# update firmware version in automation
+sed -i -e "/^env.firmware_version:/s/'.*'/'$FIRMWARE_VER'/" .github/workflows/release.yml
+
+# commit and tag
+git add .github/workflows/release.yml
+git commit -m "update to firmware $FIRMWARE_VER"
+git tag -a -m "$VER" "$VER"
+git tag "firmware-v$FIRMWARE_VER"
+git push --all
+
+popd