Github Action to check deprecations in PR (#19666)
* deprecation check * adding script * add execute permission to script * revert changes * adding the script back * added working script for local and GHA * give execute permissions * updating revgrep * adding changes to script, tools * run go mod tidy * removing default ref * make bootstrap * adding to makefile
This commit is contained in:
parent
61b152c02c
commit
6a429bb0d6
31
.github/workflows/drepecated-functions-checker.yml
vendored
Normal file
31
.github/workflows/drepecated-functions-checker.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
name: "Check Deprecations"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
# Runs on PRs to main
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
deprecations-check:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0
|
||||
with:
|
||||
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 #v4
|
||||
with:
|
||||
go-version-file: ./.go-version
|
||||
cache: true
|
||||
- name: Install required tools
|
||||
run: |
|
||||
make bootstrap
|
||||
- name: Check deprecations for files in diff
|
||||
run: |
|
||||
# Need to run this from repository root and not from scripts/ as staticcheck works
|
||||
# only on packages
|
||||
./scripts/deprecations-checker.sh ${{ github.event.pull_request.base.ref }} ${{ github.event.repository.name }}
|
||||
|
14
Makefile
14
Makefile
@ -102,6 +102,20 @@ vet:
|
||||
echo "and fix them if necessary before submitting the code for reviewal."; \
|
||||
fi
|
||||
|
||||
# deprecations runs staticcheck tool to look for deprecations. Checks entire code to see if it
|
||||
# has deprecated function, variable, constant or field
|
||||
deprecations:
|
||||
make bootstrap
|
||||
repositoryName=$(basename `git rev-parse --show-toplevel`)
|
||||
./scripts/deprecations-checker.sh "" repositoryName
|
||||
|
||||
# ci-deprecations runs staticcheck tool to look for deprecations. All output gets piped to revgrep
|
||||
# which will only return an error if changes that is not on main has deprecated function, variable, constant or field
|
||||
ci-deprecations:
|
||||
make bootstrap
|
||||
repositoryName=$(basename `git rev-parse --show-toplevel`)
|
||||
./scripts/deprecations-checker.sh main repositoryName
|
||||
|
||||
# tools/godoctests/.bin/godoctests builds the custom analyzer to check for godocs for tests
|
||||
tools/godoctests/.bin/godoctests:
|
||||
@cd tools/godoctests && $(GO_CMD) build -o .bin/godoctests .
|
||||
|
8
go.mod
8
go.mod
@ -201,7 +201,7 @@ require (
|
||||
golang.org/x/sync v0.1.0
|
||||
golang.org/x/sys v0.5.0
|
||||
golang.org/x/term v0.5.0
|
||||
golang.org/x/tools v0.2.0
|
||||
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d
|
||||
google.golang.org/api v0.109.0
|
||||
google.golang.org/grpc v1.51.0
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
|
||||
@ -209,6 +209,7 @@ require (
|
||||
gopkg.in/ory-am/dockertest.v3 v3.3.4
|
||||
gopkg.in/square/go-jose.v2 v2.6.0
|
||||
gotest.tools/gotestsum v1.9.0
|
||||
honnef.co/go/tools v0.4.3
|
||||
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
|
||||
layeh.com/radius v0.0.0-20190322222518-890bc1058917
|
||||
mvdan.cc/gofumpt v0.3.1
|
||||
@ -241,7 +242,7 @@ require (
|
||||
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
|
||||
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
|
||||
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 // indirect
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/BurntSushi/toml v1.2.1 // indirect
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
|
||||
github.com/Jeffail/gabs v1.1.1 // indirect
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
@ -447,7 +448,8 @@ require (
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
go.uber.org/multierr v1.7.0 // indirect
|
||||
go.uber.org/zap v1.19.1 // indirect
|
||||
golang.org/x/mod v0.6.0 // indirect
|
||||
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
|
||||
golang.org/x/mod v0.7.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
|
16
go.sum
16
go.sum
@ -130,8 +130,8 @@ github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c/go.mod h1:chxPXzS
|
||||
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1 h1:oPdPEZFSbl7oSPEAIPMPBMUmiL+mqgzBJwM/9qYcwNg=
|
||||
github.com/AzureAD/microsoft-authentication-library-for-go v0.8.1/go.mod h1:4qFor3D/HDsvBME35Xy9rwW9DecL+M2sNw1ybjPtwA0=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
|
||||
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4=
|
||||
@ -1987,6 +1987,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
|
||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
||||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb h1:PaBZQdo+iSDyHT053FjUCgZQ/9uqVwPOcl7KSWhKn6w=
|
||||
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=
|
||||
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@ -2012,8 +2014,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I=
|
||||
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
|
||||
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
|
||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@ -2349,8 +2351,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.2.0 h1:G6AHpWxTMGY1KyEYoAQ5WTtIekUUvDNjan3ugu60JvE=
|
||||
golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
|
||||
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d h1:9ZNWAi4CYhNv60mXGgAncgq7SGc5qa7C8VZV8Tg7Ggs=
|
||||
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -2542,6 +2544,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.4.3 h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw=
|
||||
honnef.co/go/tools v0.4.3/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA=
|
||||
k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78=
|
||||
k8s.io/api v0.20.1/go.mod h1:KqwcCVogGxQY3nBlRpwt+wpAMF/KjaCc7RpywacvqUo=
|
||||
k8s.io/api v0.20.4/go.mod h1:++lNL1AJMkDymriNniQsWRkMDzRaX2Y/POTUi8yvqYQ=
|
||||
|
52
scripts/deprecations-checker.sh
Executable file
52
scripts/deprecations-checker.sh
Executable file
@ -0,0 +1,52 @@
|
||||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
# This script is sourced into the shell running in a Github Actions workflow.
|
||||
|
||||
# Usage:
|
||||
# To check deprecations locally using the script, follow these steps:
|
||||
# From the repository root or within a package folder, execute deprecations-checker.sh
|
||||
# Optionally: to only show deprecations in changed files between the current branch and
|
||||
# a specific branch, pass the other branch name as an argument to the script.
|
||||
#
|
||||
# For example:
|
||||
# ./scripts/deprecations-checker.sh (or) make deprecations
|
||||
# ./scripts/deprecations-checker.sh main (or) make ci-deprecations
|
||||
#
|
||||
# If no branch name is specified, the command will show all usage of deprecations in the code.
|
||||
#
|
||||
# GitHub Actions runs this against the PR's base ref branch.
|
||||
|
||||
# Staticcheck uses static analysis to finds bugs and performance issues, offers simplifications,
|
||||
# and enforces style rules.
|
||||
# Here, it is used to check if a deprecated function, variable, constant or field is used.
|
||||
|
||||
# Run staticcheck
|
||||
echo "Performing deprecations check: running staticcheck"
|
||||
|
||||
# Identify repository name
|
||||
if [ -z $2 ]; then
|
||||
# local repository name
|
||||
repositoryName=$(basename `git rev-parse --show-toplevel`)
|
||||
else
|
||||
# github repository name from deprecated-functions-checker.yml
|
||||
repositoryName=$2
|
||||
fi
|
||||
|
||||
# Modify the command with the correct build tag based on repository
|
||||
if [ $repositoryName == "vault-enterprise" ]; then
|
||||
staticcheckCommand=$(echo "staticcheck ./... -tags=enterprise")
|
||||
else
|
||||
staticcheckCommand=$(echo "staticcheck ./...")
|
||||
fi
|
||||
|
||||
# If no compare branch name is specified, output all deprecations
|
||||
# Else only output the deprecations from the changes added
|
||||
if [ -z $1 ]
|
||||
then
|
||||
$staticcheckCommand | grep deprecated
|
||||
else
|
||||
# GitHub Actions will use this to find only changes wrt PR's base ref branch
|
||||
# revgrep CLI tool will return an exit status of 1 if any issues match, else it will return 0
|
||||
$staticcheckCommand | grep deprecated 2>&1 | revgrep "$(git merge-base HEAD "origin/$1")"
|
||||
fi
|
@ -19,6 +19,7 @@ package tools
|
||||
//go:generate go install google.golang.org/protobuf/cmd/protoc-gen-go
|
||||
//go:generate go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
||||
//go:generate go install github.com/favadi/protoc-go-inject-tag
|
||||
//go:generate go install honnef.co/go/tools/cmd/staticcheck
|
||||
//go:generate go install github.com/golangci/revgrep/cmd/revgrep
|
||||
//go:generate go install gotest.tools/gotestsum
|
||||
import (
|
||||
@ -37,4 +38,6 @@ import (
|
||||
_ "github.com/golangci/revgrep/cmd/revgrep"
|
||||
|
||||
_ "gotest.tools/gotestsum"
|
||||
|
||||
_ "honnef.co/go/tools/cmd/staticcheck"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user