From 255bdf21a1f781ad79ce746cf0c320a6b90cd61f Mon Sep 17 00:00:00 2001 From: Noah Dietz Date: Fri, 18 Aug 2023 14:09:59 -0700 Subject: [PATCH] chore(ci): add new_client workflow (#8446) --- .github/workflows/new_client.yml | 66 +++++++++++++++++++++ internal/actions/cmd/changefinder/README.md | 2 + internal/actions/cmd/changefinder/main.go | 13 +++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/new_client.yml diff --git a/.github/workflows/new_client.yml b/.github/workflows/new_client.yml new file mode 100644 index 000000000000..aaef46a0436a --- /dev/null +++ b/.github/workflows/new_client.yml @@ -0,0 +1,66 @@ +--- +name: new_client +on: + push: + # Per GitHub Action docs, specifying both branch and paths joins them with AND. + branches: + - main + paths: + - '**/version.go' + +permissions: + contents: read + pull-requests: write + +jobs: + new_versions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: 1.20.x + - name: Find new version files + id: versions + # Ignore changes to the internal and root directories. + # Focus on newly added version.go files generated by GAPIC. + # Multiple new version files in a single module file will be deduped. + run: | + dirs=$(go run ./internal/actions/cmd/changefinder -q --diff-filter=A --path-filter='*version.go' --content-regex='internal\.Version') + if [ -z "$dirs" ] + then + echo "skip=1" >> $GITHUB_OUTPUT + echo "No new version files!" + else + for d in $dirs; do list=${list},\"${d}\"; done + echo "new={\"new\":[${list#,}]}" >> $GITHUB_OUTPUT + echo "skip=" >> $GITHUB_OUTPUT + fi + outputs: + versions: ${{ steps.versions.outputs.new }} + skip: ${{ steps.versions.outputs.skip }} + bump_module: + needs: new_versions + runs-on: ubuntu-latest + if: "!needs.new_versions.outputs.skip" + continue-on-error: true + strategy: + matrix: ${{ fromJson(needs.new_versions.outputs.versions) }} + steps: + - uses: actions/checkout@v3 + - run: echo >> ${{ matrix.new }}/CHANGES.md + - uses: googleapis/code-suggester@v4 + id: code_suggester + env: + ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }} + with: + command: pr + upstream_owner: googleapis + upstream_repo: google-cloud-go + description: 'New client(s) generated in ${{ github.commits[0][url] }}, triggering release.' + title: 'feat(${{ matrix.new }}): new client(s)' + message: 'feat(${{ matrix.new }}): new clients' + primary: 'main' + branch: release-${{ matrix.new }}-client + git_dir: '.' + force: true diff --git a/internal/actions/cmd/changefinder/README.md b/internal/actions/cmd/changefinder/README.md index b17efdd14815..6cd43655d585 100644 --- a/internal/actions/cmd/changefinder/README.md +++ b/internal/actions/cmd/changefinder/README.md @@ -16,6 +16,8 @@ The available flags are as follows: format mode. Defaults to `submodules`. * `-base=[ref name]`: The base ref to compare `HEAD` to. Default is `origin/main`. + * `-path-filter=[path filter]`: The path filter to diff for. + * `-content-pattern=[regex]`: A regex to match on diff contents. Example usages from this repo root: diff --git a/internal/actions/cmd/changefinder/main.go b/internal/actions/cmd/changefinder/main.go index 50b8d48484e0..30d095f35cb8 100644 --- a/internal/actions/cmd/changefinder/main.go +++ b/internal/actions/cmd/changefinder/main.go @@ -32,7 +32,9 @@ var ( ghVarName = flag.String("gh-var", "submodules", "github format's variable name to set output for, defaults to 'submodules'.") base = flag.String("base", "origin/main", "the base ref to compare to, defaults to 'origin/main'") // See https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203 - filter = flag.String("diff-filter", "", "the git diff filter to apply [A|C|D|M|R|T|U|X|B] - lowercase to exclude") + filter = flag.String("diff-filter", "", "the git diff filter to apply [A|C|D|M|R|T|U|X|B] - lowercase to exclude") + pathFilter = flag.String("path-filter", "", "filter commits by changes to target path(s)") + contentPattern = flag.String("content-regex", "", "regular expression to execute against contents of diff") ) func main() { @@ -134,9 +136,18 @@ func gitFilesChanges(dir string) ([]string, error) { if *filter != "" { args = append(args, "--diff-filter", *filter) } + if *contentPattern != "" { + args = append(args, "-G", *contentPattern) + } args = append(args, *base) + if *pathFilter != "" { + args = append(args, "--", *pathFilter) + } + c := exec.Command("git", args...) + logg.Printf(c.String()) + c.Dir = dir b, err := c.Output() if err != nil {