forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github Action to check deprecations in PR (hashicorp#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
- Loading branch information
Showing
6 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters