Skip to content

Commit

Permalink
vet: add dependency checks (#7766)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Oct 25, 2024
1 parent a82315c commit 94e1b29
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Dependency Changes

# Trigger on PRs.
on:
pull_request:

permissions:
contents: read

jobs:
# Compare dependencies before and after this PR.
dependencies:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: true

steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: stable
cache-dependency-path: "**/*go.sum"

# Run the commands to generate dependencies before and after and compare.
- name: Compare dependencies
run: |
BEFORE="$(mktemp -d)"
AFTER="$(mktemp -d)"
scripts/gen-deps.sh "${AFTER}"
git checkout origin/master
scripts/gen-deps.sh "${BEFORE}"
echo "Comparing dependencies..."
# Run grep in a sub-shell since bash does not support ! in the middle of a pipe
diff -u0 -r "${BEFORE}" "${AFTER}" | bash -c '! grep -v "@@"'
echo "No changes detected."
21 changes: 21 additions & 0 deletions scripts/gen-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e # Exit on error
set -o pipefail # Fail a pipe if any sub-command fails.

if [[ "$#" -ne 1 || ! -d "$1" ]]; then
echo "Specify a valid output directory as the first parameter."
exit 1
fi

SCRIPTS_DIR="$(dirname "$0")"
OUTPUT_DIR="$1"

cd "${SCRIPTS_DIR}/.."

git ls-files -- '*.go' | grep -v '\(^\|/\)\(internal\|examples\|benchmark\|interop\|test\|testdata\)\(/\|$\)' | xargs dirname | sort -u | while read d; do
pushd "$d" > /dev/null
pkg="$(echo "$d" | sed 's;\.;grpc;' | sed 's;/;_;g')"
go list -deps . | sort >| "${OUTPUT_DIR}/$pkg"
popd > /dev/null
done

0 comments on commit 94e1b29

Please sign in to comment.