diff --git a/.github/workflows/update_protobufs.yml b/.github/workflows/update_protobufs.yml index b9c75583c..b3f1feeee 100644 --- a/.github/workflows/update_protobufs.yml +++ b/.github/workflows/update_protobufs.yml @@ -1,5 +1,15 @@ name: "Update protobufs" -on: workflow_dispatch + +on: + workflow_dispatch: + inputs: + version: + description: "Protobufs version tag to sync to (e.g., v2.7.26). Defaults to the latest protobufs release." + required: false + default: "" + type: string + repository_dispatch: + types: [protobufs-release] permissions: contents: write @@ -14,6 +24,7 @@ jobs: with: fetch-depth: 0 submodules: true + persist-credentials: false - name: Setup Python uses: actions/setup-python@v5 @@ -25,11 +36,44 @@ jobs: python -m pip install --upgrade pip python -m pip install poetry - - name: Update protobuf submodule + - name: Determine target protobufs version + id: version + env: + INPUT_VERSION: ${{ github.event.inputs.version }} + PAYLOAD_VERSION: ${{ github.event.client_payload.version }} + run: | + cd protobufs + git fetch --tags + + if [ -n "${INPUT_VERSION}" ]; then + target="${INPUT_VERSION}" + elif [ -n "${PAYLOAD_VERSION}" ]; then + target="${PAYLOAD_VERSION}" + else + target=$(git tag --list 'v*' --sort=-version:refname | head -n1) + if [ -z "${target}" ]; then + echo "Error: no release tags found in meshtastic/protobufs" + exit 1 + fi + fi + + if ! git show-ref --verify --quiet "refs/tags/${target}"; then + echo "Error: '${target}' is not a valid tag in meshtastic/protobufs" + exit 1 + fi + + printf 'version=%s\n' "${target}" >> "$GITHUB_OUTPUT" + echo "Target protobufs version: ${target}" + + - name: Update protobuf submodule to release + env: + TARGET_VERSION: ${{ steps.version.outputs.version }} run: | git submodule sync --recursive git submodule update --init --recursive - git submodule update --remote --recursive + cd protobufs + git checkout "${TARGET_VERSION}" + cd .. - name: Download nanopb run: | @@ -46,6 +90,8 @@ jobs: ./bin/regen-protobufs.sh - name: Commit update + env: + TARGET_VERSION: ${{ steps.version.outputs.version }} run: | git config --global user.name 'github-actions' git config --global user.email 'bot@noreply.github.com' @@ -53,7 +99,7 @@ jobs: git add protobufs git add meshtastic/protobuf if [[ -n "$(git status --porcelain)" ]]; then - git commit -m "Update protobufs" + git commit -m "protobufs: ${TARGET_VERSION}" git push else echo "No changes to commit"