Generator #10
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: Generator | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "version" | |
required: true | |
default: "v14" | |
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: ~/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 protoc go | |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | |
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | |
go install github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic@latest | |
echo $(go env GOPATH)/bin >> $GITHUB_PATH | |
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/*_example_test.go | |
- 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 "[email protected]" | |
git config user.name "GitHub Action" | |
git commit -m "feat: updated by action, $(date)" | |
git push origin develop |