Skip to content

Generator

Generator #1

Workflow file for this run

name: Generator
on:
workflow_dispatch:
inputs:
version:
description: "version"
required: true
default: "v15"
jobs:
build:
runs-on: ubuntu-latest
container:
image: alpine:latest
env:
VERSION: ${{ github.event.inputs.version }}
BRANCH_NAME: ${{ github.event.inputs.version }}
PUBLISH_PKG: github.com/Optable/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 https://$GITHUB_ACTOR_ID:${{ secrets.GITHUB_TOKEN }}@github.com/Optable/google-ads-pb.git $OUTPUT_PATH
git -C $OUTPUT_PATH checkout -b $BRANCH_NAME
git clone --depth=1 https://github.com/googleapis/googleapis.git $INPUT_PATH
if [ ! -d $INPUT_PATH/google/protobuf ]; then
git clone --depth=1 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/Optable/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 to commit"
exit 0
fi
echo "==> Committing changes"
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add .
git commit -m "Auto-generated client update for version $VERSION"
git push origin $BRANCH_NAME
echo "==> Changes have been pushed"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Auto-generated client update for version $VERSION"
title: "Auto-generated client update for version $VERSION"
body: "This PR updates the google ads proto & client to version $VERSION"
head: ${{ github.event.inputs.version }}
base: "main"