Skip to content

Commit

Permalink
chore(apidiff): ignore added files (#8338)
Browse files Browse the repository at this point in the history
Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com>
  • Loading branch information
noahdietz and gcf-merge-on-green[bot] committed Jul 27, 2023
1 parent da2ad53 commit 59574e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/apidiff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
- name: Get changed directories
id: changed_dirs
# Ignore changes to the internal and root directories.
# Ignore added files with --diff-filter=a.
run: |
dirs=$(go run ./internal/actions/cmd/changefinder -q)
dirs=$(go run ./internal/actions/cmd/changefinder -q --diff-filter=a)
if [ -z "$dirs" ]
then
echo "skip=1" >> $GITHUB_OUTPUT
Expand Down
10 changes: 9 additions & 1 deletion internal/actions/cmd/changefinder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
format = flag.String("format", "plain", "output format, one of [plain|github], defaults to 'plain'")
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")
)

func main() {
Expand Down Expand Up @@ -128,7 +130,13 @@ func modDirs(dir string) (submodulesDirs []string, err error) {
}

func gitFilesChanges(dir string) ([]string, error) {
c := exec.Command("git", "diff", "--name-only", *base)
args := []string{"diff", "--name-only"}
if *filter != "" {
args = append(args, "--diff-filter", *filter)
}
args = append(args, *base)

c := exec.Command("git", args...)
c.Dir = dir
b, err := c.Output()
if err != nil {
Expand Down

0 comments on commit 59574e9

Please sign in to comment.