Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): add new_client workflow #8446

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/new_client.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions internal/actions/cmd/changefinder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
13 changes: 12 additions & 1 deletion internal/actions/cmd/changefinder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down