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

Github Action to check deprecations in PR #19666

Merged
merged 15 commits into from
Mar 28, 2023
Merged

Github Action to check deprecations in PR #19666

merged 15 commits into from
Mar 28, 2023

Conversation

akshya96
Copy link
Contributor

@akshya96 akshya96 commented Mar 21, 2023

https://hashicorp.atlassian.net/browse/VAULT-8439
Recommendation:

Add a GitHub action to scan for deprecated functions. It will need a way to allowlist certain functions or to ignore certain findings.

This PR uses the staticcheck cmdline tool to identify the use of deprecated functions.

This was initially attempted with golangci-lint tool with staticcheck. It produced inconsistent results, and there are many related issues on GitHub. Furthermore, the author of staticcheck is unaware of its inclusion in golangci-lint. Therefore, I used the staticcheck tool as it is more reliable.

The recommendation in the ticket was to create a GitHub action that includes an allowlist for certain findings, but this would prevent us from identifying if deprecated functions are utilized in new code.
To address this issue, the check runs on all files included in the PR. staticcheck runs at package level, so we need to grep the details for the changes that are included in the PR and display it. It uses revgrep to do this.

To check deprecations locally using the script, follow these steps:

  1. Run the command ./scipts/deprecations-checker.sh <optional branch name to compare with> on vault/vault-enterprise repository path or any package path
  2. Optionally specify a branch name to compare with. This will only show deprecations present in files that have changed when compared to the specified branch.

For example:
./scripts/deprecations-checker.sh main
./scripts/deprecations-checker.sh
(Running this from vault repo path)

If no branch name is specified, the command will show all the deprecations in the code.
GHA runs this wrt the PR's base ref branch.

This will be added to developer documentation after this PR is approved. Also, this is not a required check.

@akshya96 akshya96 marked this pull request as ready for review March 22, 2023 00:08
@akshya96 akshya96 requested a review from a team as a code owner March 22, 2023 00:08
@akshya96 akshya96 requested review from a team and peteski22 March 22, 2023 00:08
Copy link
Contributor

@miagilepner miagilepner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be really useful to have! Thanks for implementing it. I have a few small suggestions.

.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
@akshya96 akshya96 requested a review from miagilepner March 22, 2023 23:38
Copy link

@peteski22 peteski22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this @akshya96 it's good. I added a few comments and suggestions which hopefully help. 😄

.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/scripts/deprecations-checker.sh Outdated Show resolved Hide resolved
.github/scripts/deprecations-checker.sh Outdated Show resolved Hide resolved
.github/scripts/deprecations-checker.sh Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
Copy link

@peteski22 peteski22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work Akshya! I tagged in Kuba and Marc just for a sanity check.

Copy link
Contributor

@marcboudreau marcboudreau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issues I pointed out aren't serious, but would help streamline the workflow file.

I only skimmed the bash script quickly so that I could focus on the GitHub workflow file.

.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch-depth: 0 means getting the complete repository history. Is that necessary for this job? Alternatively, removing the fetch-depth parameter will result of a depth of 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need fetch-depth: 0 as we check the deprecations on changes when compared to origin/main branch. When I remove this, I get "fatal: Not a valid object name origin/main" and it shows all the deprecations in the code. Basically we need the origin/main branch to get the diff in the current branch.

Copy link
Contributor

@kubawi kubawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks Akshya!

scripts/deprecations-checker.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@miagilepner miagilepner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I added a couple of additional suggestions, but I don't think they're blockers to merging.

.github/workflows/drepecated-functions-checker.yml Outdated Show resolved Hide resolved
scripts/deprecations-checker.sh Show resolved Hide resolved
@akshya96 akshya96 merged commit 6a429bb into main Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants