py code generate #5
This file contains 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: py code generate | |
on: | |
workflow_dispatch: | |
workflow_call: | |
outputs: | |
committed: | |
value: ${{ jobs.code-gen-py.outputs.committed }} | |
pushed: | |
value: ${{ jobs.code-gen-py.outputs.pushed }} | |
jobs: | |
code-gen-py: | |
runs-on: ubuntu-latest | |
outputs: | |
committed: ${{ steps.commit-changes.outputs.committed }} | |
pushed: ${{ steps.commit-changes.outputs.pushed }} | |
steps: | |
# set up toolchain | |
- name: Setup protoc | |
uses: arduino/setup-protoc@v2 | |
with: | |
version: "24.x" | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
# 分别check out master 分支和 py 分支 | |
- name: checkout master | |
uses: actions/checkout@v3 | |
with: | |
ref: master | |
path: ./master | |
- name: Checkout py branch | |
uses: actions/checkout@v3 | |
with: | |
ref: py-code-gen | |
path: ./py-code-gen | |
- name: read old codegen info | |
id: old-codegen-info | |
working-directory: ./py-code-gen | |
# 因为一开始没有这个文件,所以写入一段空内容 | |
run: | | |
echo "" >> ./codegen_info | |
cat ./codegen_info >> "$GITHUB_OUTPUT" | |
# 下载py proto依赖 | |
- run: | |
pip install protobuf && | |
pip install grpcio && | |
pip install googleapis-common-protos && | |
pip install grpcio-tools | |
working-directory: ./master | |
# 在master 中生成代码 | |
- name: generate proto code | |
run: | |
mkdir -v /Ceobe_Proto/pb && | |
python -m grpc_tools.protoc -I./Ceobe_Proto/pb=./protos --python_out=. --grpc_python_out=. ./protos/*.proto | |
working-directory: ./master | |
# 清理 py code gen 中的Py文件和workflow文件 | |
- name: remove old gen files | |
run: | | |
rm -rf ./py-code-gen/.github | |
rm -rf ./py-code-gen/pb | |
rm -rf ./py-code-gen/protos | |
- name: copy origin proto files | |
run: | |
mkdir -v ./py-code-gen/protos && | |
cp -vr ./master/protos/* ./py-code-gen/protos | |
- name: copy code gen | |
run: | |
mkdir -v ./py-code-gen/pb && | |
cp -vr ./master/Ceobe_Proto/pb/* ./py-code-gen/pb/ | |
- name: write codegen info | |
working-directory: ./master | |
run: | | |
echo "CURRENT_MASTER_SHA=$(git rev-parse --short HEAD)" > ../py-code-gen/codegen_info | |
echo "LAST_MASTER_SHA=${{ steps.old-codegen-info.outputs.CURRENT_MASTER_SHA }}" >> ../py-code-gen/codegen_info | |
- name: Add & Commit | |
id: commit-changes | |
uses: EndBug/add-and-commit@v9 | |
with: | |
default_author: github_actions | |
message: '[CI] update py-code-gen' | |
cwd: ./py-code-gen |