Sync Proto #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Proto | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 1' | |
| workflow_dispatch: | |
| inputs: | |
| nacos_ref: | |
| description: 'Nacos ref (branch/tag/SHA, leave empty for develop HEAD)' | |
| required: false | |
| concurrency: | |
| group: sync-proto | |
| cancel-in-progress: true | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Generate app token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - name: Checkout nacos-sdk-proto | |
| uses: actions/checkout@v4 | |
| with: | |
| path: nacos-sdk-proto | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Resolve nacos ref | |
| id: resolve | |
| run: | | |
| if [ -n "${{ inputs.nacos_ref }}" ]; then | |
| REF="${{ inputs.nacos_ref }}" | |
| else | |
| REF="develop" | |
| fi | |
| echo "ref=$REF" >> "$GITHUB_OUTPUT" | |
| SHA=$(git ls-remote https://github.com/alibaba/nacos.git "$REF" | head -1 | cut -f1) | |
| echo "sha=$SHA" >> "$GITHUB_OUTPUT" | |
| - name: Check if sync needed | |
| id: check | |
| run: | | |
| LAST_SHA="" | |
| if [ -f nacos-sdk-proto/proto/VERSION ]; then | |
| LAST_SHA=$(jq -r .nacos_commit nacos-sdk-proto/proto/VERSION) | |
| fi | |
| # Double check: SHA must match AND generated files must exist | |
| HAS_GENERATED=true | |
| if [ -z "$(find nacos-sdk-proto/go -name '*.pb.go' 2>/dev/null | head -1)" ]; then | |
| HAS_GENERATED=false | |
| fi | |
| if [ "$LAST_SHA" = "${{ steps.resolve.outputs.sha }}" ] && [ "$HAS_GENERATED" = "true" ]; then | |
| echo "needed=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "needed=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| # --- Java toolchain (generate-proto + unit tests) --- | |
| - name: Checkout nacos | |
| if: steps.check.outputs.needed == 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: alibaba/nacos | |
| ref: ${{ steps.resolve.outputs.sha }} | |
| path: nacos | |
| fetch-depth: 1 | |
| - name: Setup Java | |
| if: steps.check.outputs.needed == 'true' | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| cache: maven | |
| - name: Build nacos-api | |
| if: steps.check.outputs.needed == 'true' | |
| run: cd nacos && mvn install -pl api -am -DskipTests -Drat.skip=true -q | |
| - name: Link nacos for Makefile | |
| if: steps.check.outputs.needed == 'true' | |
| run: ln -s "$GITHUB_WORKSPACE/nacos" nacos-sdk-proto/.nacos | |
| # --- protoc (shared by Go, Python, Node.js generation) --- | |
| - name: Install protoc | |
| if: steps.check.outputs.needed == 'true' | |
| run: | | |
| PROTOC_VERSION=28.3 | |
| curl -fsSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip -o protoc.zip | |
| sudo unzip -o protoc.zip -d /usr/local bin/protoc 'include/*' | |
| rm protoc.zip | |
| protoc --version | |
| # --- Go toolchain (generate-go + verify) --- | |
| - name: Setup Go | |
| if: steps.check.outputs.needed == 'true' | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: nacos-sdk-proto/go/go.mod | |
| cache-dependency-path: nacos-sdk-proto/go/go.sum | |
| - name: Install Go protoc plugins | |
| if: steps.check.outputs.needed == 'true' | |
| run: | | |
| go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | |
| go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | |
| # --- Python toolchain (generate-python) --- | |
| - name: Setup Python | |
| if: steps.check.outputs.needed == 'true' | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install grpcio-tools | |
| if: steps.check.outputs.needed == 'true' | |
| run: pip install grpcio-tools | |
| # --- Node.js toolchain (generate-nodejs + tsc verify) --- | |
| - name: Setup Node.js | |
| if: steps.check.outputs.needed == 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Install ts-proto | |
| if: steps.check.outputs.needed == 'true' | |
| run: cd nacos-sdk-proto && npm install | |
| # --- Generate and verify --- | |
| - name: Generate and verify | |
| if: steps.check.outputs.needed == 'true' | |
| run: | | |
| cd nacos-sdk-proto | |
| make clean | |
| make generate-proto | |
| make generate | |
| make verify-build | |
| - name: Update VERSION | |
| if: steps.check.outputs.needed == 'true' | |
| run: | | |
| cat > nacos-sdk-proto/proto/VERSION << VEOF | |
| { | |
| "source": "branch", | |
| "nacos_ref": "${{ steps.resolve.outputs.ref }}", | |
| "nacos_commit": "${{ steps.resolve.outputs.sha }}", | |
| "generated_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)" | |
| } | |
| VEOF | |
| - name: Check diff and create PR | |
| if: steps.check.outputs.needed == 'true' | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| cd nacos-sdk-proto | |
| if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then | |
| echo "No changes detected, skipping PR." | |
| exit 0 | |
| fi | |
| git config user.name "nacos-sdk-proto-bot[bot]" | |
| git config user.email "nacos-sdk-proto-bot[bot]@users.noreply.github.com" | |
| SHORT_SHA=$(echo "${{ steps.resolve.outputs.sha }}" | cut -c1-7) | |
| BRANCH="sync/nacos-${SHORT_SHA}" | |
| git checkout -b "$BRANCH" | |
| git add -A | |
| git commit -m "chore: sync proto from nacos@${SHORT_SHA} (${{ steps.resolve.outputs.ref }})" | |
| git push origin "$BRANCH" --force | |
| EXISTING=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number') | |
| if [ -z "$EXISTING" ]; then | |
| gh pr create \ | |
| --title "chore: sync proto from nacos@${SHORT_SHA}" \ | |
| --body "Auto-generated from alibaba/nacos@${{ steps.resolve.outputs.sha }} (ref: ${{ steps.resolve.outputs.ref }})" | |
| fi |