Generator #41
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: Generator | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "version" | |
| required: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: alpine:latest | |
| env: | |
| VERSION: ${{ github.event.inputs.version }} | |
| PUBLISH_PKG: github.com/shenzhencenter/google-ads-pb | |
| INPUT_PATH: /googleapis | |
| OUTPUT_PATH: /root/go/src/google-ads-pb | |
| ADSLIB_PATH: /googleapis/google/ads/googleads/${{ github.event.inputs.version }} | |
| API_CONFIG_PATH: /googleapis/google/ads/googleads/${{ github.event.inputs.version }}/googleads_${{ github.event.inputs.version }}.yaml | |
| GRPC_CONFIG_PATH: /googleapis/google/ads/googleads/${{ github.event.inputs.version }}/googleads_grpc_service_config.json | |
| steps: | |
| - name: Install dependencies | |
| run: | | |
| apk add --no-cache git curl tar unzip | |
| curl -LO https://go.dev/dl/go1.23.6.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.23.6.linux-amd64.tar.gz | |
| curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v24.4/protoc-24.4-linux-x86_64.zip && unzip protoc-24.4-linux-x86_64.zip -d /usr/local && rm -rf protoc-24.4-linux-x86_64.zip | |
| export PATH=$PATH:/usr/local/go/bin:/usr/local/bin:/github/home/go/bin | |
| echo "PATH=$PATH" >> $GITHUB_ENV | |
| go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.5 | |
| go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 | |
| go install github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic@v0.53.1 | |
| mkdir -p $OUTPUT_PATH | |
| - name: Clone repositories | |
| run: | | |
| git clone --branch=develop https://$GITHUB_ACTOR_ID:${{ secrets.GITHUB_TOKEN }}@github.com/shenzhencenter/google-ads-pb.git $OUTPUT_PATH | |
| git clone --depth=1 --branch=master https://github.com/googleapis/googleapis.git $INPUT_PATH | |
| if [ ! -d $INPUT_PATH/google/protobuf ]; then | |
| git clone --depth=1 --branch=main https://github.com/protocolbuffers/protobuf.git /protobuf | |
| ln -s /protobuf/src/google/protobuf $INPUT_PATH/google/protobuf | |
| fi | |
| - name: Remove old files | |
| run: | | |
| rm -rf $OUTPUT_PATH/clients $OUTPUT_PATH/common $OUTPUT_PATH/enums $OUTPUT_PATH/errors $OUTPUT_PATH/resources $OUTPUT_PATH/services | |
| rm -rf $OUTPUT_PATH/go.mod $OUTPUT_PATH/go.sum | |
| - name: Build | |
| run: | | |
| protoc -I=$INPUT_PATH \ | |
| --go_out=$OUTPUT_PATH \ | |
| --go-grpc_out=$OUTPUT_PATH \ | |
| --go_gapic_out=$OUTPUT_PATH \ | |
| --go_gapic_opt 'go-gapic-package=clients;clients' \ | |
| --go_gapic_opt "api-service-config=${API_CONFIG_PATH}" \ | |
| --go_gapic_opt "grpc-service-config=${GRPC_CONFIG_PATH}" \ | |
| `find $ADSLIB_PATH -name \*.proto` | |
| - name: Rename packages | |
| run: | | |
| BUILD_PATH=$OUTPUT_PATH/google.golang.org/genproto/googleapis/ads/googleads/${VERSION} | |
| BUILD_PKG=google.golang.org/genproto/googleapis/ads/googleads/$VERSION | |
| cp -r $BUILD_PATH/* $OUTPUT_PATH/ && rm -rf $OUTPUT_PATH/google.golang.org | |
| find $OUTPUT_PATH -name '*.go' -exec sed -i "s|${BUILD_PKG}|${PUBLISH_PKG}|g" '{}' \; | |
| find $OUTPUT_PATH/clients/internal/snippets -name '*.go' -exec sed -i "s|\"clients\"|\"${PUBLISH_PKG}/clients\"|g" '{}' \; | |
| rm -rf $OUTPUT_PATH/clients/*_test.go | |
| rm -rf $OUTPUT_PATH/clients/internal/snippets | |
| - name: Fix errors | |
| run: | | |
| if [ -f $OUTPUT_PATH/resources/experiment_arm.pb.go ]; then | |
| echo "==> Rename experiment_arm.pb.go to experimentarm.pb.go" | |
| mv $OUTPUT_PATH/resources/experiment_arm.pb.go $OUTPUT_PATH/resources/experimentarm.pb.go -f | |
| fi | |
| - name: Format | |
| run: | | |
| cd $OUTPUT_PATH | |
| if [ ! -f go.mod ]; then | |
| go mod init github.com/shenzhencenter/google-ads-pb | |
| fi | |
| go mod tidy | |
| go fmt ./... | |
| go build ./... | |
| - name: Commit and push | |
| run: | | |
| cd $OUTPUT_PATH | |
| if [ -z "$(git status --porcelain)" ]; then | |
| echo "==> No changes" | |
| exit 0 | |
| fi | |
| git add . | |
| git config user.email "16268065+xnkjj@users.noreply.github.com" | |
| git config user.name "GitHub Action" | |
| git commit -m "feat: updated by action, $(date)" | |
| git push origin develop |