Skip to content

Extract Protos

Extract Protos #44

name: Extract Protos
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0' # Runs at 00:00 on Sunday
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
submodules: 'recursive'
- name: Setup Rust
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6
with:
dotnet-version: 'latest'
- name: Setup Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: 'stable'
cache-dependency-path: src/EcoFlow.Proto.Decoder/go.sum
- name: Install apkeep
run: cargo install apkeep
- name: Download APK (direct URL, fallback to apkeep)
shell: bash
run: |
set -euo pipefail
mkdir -p downloads
if curl -L --fail --retry 5 --retry-delay 2 --connect-timeout 20 --max-time 600 -o downloads/app-release.apk "https://ecoflow-service-us-cdn.ecoflow.com/apk/app-release.apk"; then
echo "Downloaded from EcoFlow CDN"
ls -lh downloads/app-release.apk
exit 0
fi
echo "Direct download failed; falling back to apkeep"
apkeep -a com.ecoflow downloads
ls -lh downloads
- name: Export file descriptor set from APK
run: |
fileName="$(ls -1 downloads | head -n 1)"
if [ -z "$fileName" ]; then
echo "No file downloaded into ./downloads"
exit 1
fi
if [ "$(ls -1 downloads | wc -l)" -ne 1 ]; then
echo "Expected exactly 1 file in ./downloads, got:"
ls -la downloads
exit 1
fi
dotnet run --project src/EcoFlow.Exporter.Protos -i "downloads/$fileName" -o file_descriptor_set.pb
- name: Generate protos from descriptor set
run: |
rm -rf protos
cd src/EcoFlow.Proto.Decoder
go mod tidy
go run . ../../file_descriptor_set.pb ../../protos
- name: Commit protos back to current branch
run: |
if [ -z "${GITHUB_REF_NAME}" ]; then
echo "GITHUB_REF_NAME is empty"
exit 1
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add protos
if git diff --cached --quiet; then
echo "No changes in protos to commit"
exit 0
fi
git commit -m "Update protos"
git push origin "HEAD:${GITHUB_REF_NAME}"