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

Automation, Lint'ing, etc Mega Refactor #208

Merged
merged 1 commit into from
May 13, 2024

Conversation

dvonthenen
Copy link
Contributor

@dvonthenen dvonthenen commented May 10, 2024

Proposed changes

This turned out to be a lot larger than I thought because it turns out that, although I had the golang toolchain downloaded for Visual Studio code, it was not actually enabled/hooked into my environment, which is a huge bummer.

The biggest impactful change code-wise is, in fact, the most annoying and the least impactful in value (just caused a TON of changes) and that was the Go variable/class/etc naming convention. By default, Go is supposed to automatically update this as you type, assuming your tools are set up correctly.

The other reason why this PR is so large... The problem is introducing these language static and lint checkers later on is that in order to introduce them, you also need to fix ALL associated issues that they call out.

To give perspective, I created a PR for everything but the Go static checks and lining, and this is what that looks like:
deepgram/deepgram-python-sdk#394

Prerequisites

Supported Environment:

  • Linux: Ubuntu and Redhat only
  • MacOS

NOTE: No windows support. Just submit the PR and use the PR to tell you what static checks and lints to fix.

In order to expedite implementation this feature, this does require the following to be installed:

Once you have docker installed, all other dependencies can be installed using:

make ensure-deps

NOTE: Just like this sounds, it will install things on your local laptop.

Significant Changes

  • Markdown linting - which is why you see all .md files changing
  • Yaml/GitHub Action static checking and lining - which is why you see all YAML and Actions changing
  • Shellscript static checking and lining - to support all these linters bash scripts ahead to be introduced to orchestrate invoking these tools
  • Go specific languages static checking and lining. Checkout https://github.com/golangci/golangci-lint for more details. This adds these checks
    • bodyclose
    • deadcode
    • dupl
    • errcheck
    • funlen
    • goconst
    • gocritic
    • gocyclo
    • gofmt
    • goheader
    • goimports
    • goprintffuncname
    • gosec
    • govet
    • ineffassign
    • misspell
    • nakedret
    • noctx
    • nolintlint
    • revive
    • staticcheck
    • structcheck
    • stylecheck
    • typecheck
    • unconvert
    • unparam
    • varcheck
    • whitespace
  • Framework for Daily Build - this will hit the DG endpoint daily just after midnight
  • Framework for Unit Tests - this will run on every PR
  • Makefile (and scripts) - these are cross-platform to help orchestrate these checks and for users to be able to run these checks locally BEFORE submitting a PR

To Run Locally:

You need to have cmake installed. Then just run:
make help

vonthd@vonthds-MacBook-Pro-2:deepgram-go-sdk$ make help

Syntax: make <target>

Targets:
  help            Display help
  version         display version of components
  ensure-deps     Ensure that all required dependency utilities are downloaded or installed
  lint            Performs Golang programming lint
  mdlint          Performs Markdown lint
  shellcheck      Performs bash/shell lint
  yamllint        Performs yaml lint
  actionlint      Performs GitHub Actions lint

Kinda Breaking Changes

So because certain response variables, class names, etc will change, this is technically a breaking change. After discovering my toolchain wasn't connected, I knew going into this that would be the case. There are no logic or flow breaking changes, they are strictly just variable, class, etc names that changed because of the lining.

In order to minimize the impact to code, I created some sed replace scripts which will automatically handle the update of these response, class, etc names. This should work for the majority of users and only specifically target updating names and adjusting pointers.

Just run these updates on your code (or you can make the changes yourself in your IDE... or if you want to really do it the hard way, do it all by hand).

# using response struct lint names
find ./ -type f -iname "*.go" -not -path "./.git" -exec sed -i.bak 's/Url/URL/g' "{}" +;
find ./ -type f -iname "*.go" -not -path "./.git" -exec sed -i.bak 's/Api/API/g' "{}" +;
find ./ -type f -iname "*.go" -not -path "./.git" -exec sed -i.bak -E 's/([^a-zA-Z])URI/\1uri/g' "{}" +;
find ./ -type f -iname "*.go" -not -path "./.git" -exec sed -i.bak 's/Http/HTTP/g' "{}" +;
find ./ -type f -iname "*.go" -not -path "./.git" -exec sed -i.bak 's/Uuid/UUID/g' "{}" +;
find ./ -type f -iname "*.go" -not -path "./.git" -exec sed -i.bak -E 's/Id([^e])/ID\1/g' "{}" +;
find ./ -type f -iname "*.bak" -not -path "./.git" -exec rm -rf "{}" +;

# changing class and options names
find ./ -type f -iname "*.go" -not -path ".git" -exec sed -i.bak 's/ReplyOptions/Options/g' "{}" +;
find ./ -type f -iname "*.go" -not -path ".git" -exec sed -i.bak 's/AnalyzeClient/Client/g' "{}" +;
find ./ -type f -iname "*.go" -not -path ".git" -exec sed -i.bak 's/ManageClient/Client/g' "{}" +;
find ./ -type f -iname "*.go" -not -path ".git" -exec sed -i.bak 's/PrerecordedClient/Client/g' "{}" +;
find ./ -type f -iname "*.go" -not -path ".git" -exec sed -i.bak 's/SpeakClient/Client/g' "{}" +;
find ./ -type f -iname "*.bak" -not -path "./.git" -exec rm -rf "{}" +;

# clients and options from `struct` to `*struct`
find ./examples -type f -iname "*.go" -not -path ".git" -exec sed -i.bak -E 's/([a-zA-Z0-9]+[[:blank:]]+:=.*)([[:blank:]]+)([^\&].+[a-zA-Z]+\.ClientOptions\{)(.*)/\1\2\&\3\4/g' "{}" +;
find ./examples -type f -iname "*.go" -not -path ".git" -exec sed -i.bak -E 's/([a-zA-Z0-9]+[[:blank:]]+:=.*)([[:blank:]]+)([^\&].+[a-zA-Z]+\.AnalyzeOptions\{)(.*)/\1\2\&\3\4/g' "{}" +;
find ./examples -type f -iname "*.go" -not -path ".git" -exec sed -i.bak -E 's/([a-zA-Z0-9]+[[:blank:]]+:=.*)([[:blank:]]+)([^\&].+[a-zA-Z]+\.LiveTranscriptionOptions\{)(.*)/\1\2\&\3\4/g' "{}" +;
find ./examples -type f -iname "*.go" -not -path ".git" -exec sed -i.bak -E 's/([a-zA-Z0-9]+[[:blank:]]+:=.*)([[:blank:]]+)([^\&].+[a-zA-Z]+\.PreRecordedTranscriptionOptions\{)(.*)/\1\2\&\3\4/g' "{}" +;
find ./examples -type f -iname "*.go" -not -path ".git" -exec sed -i.bak -E 's/([a-zA-Z0-9]+[[:blank:]]+:=.*)([[:blank:]]+)([^\&].+[a-zA-Z]+\.SpeakOptions\{)(.*)/\1\2\&\3\4/g' "{}" +;
find ./ -type f -iname "*.bak" -not -path "./.git" -exec rm -rf "{}" +;

Types of changes

What types of changes does your code introduce to the community Go SDK?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update or tests (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have lint'ed all of my code using repo standards
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

All examples were tested to make sure nothing is broken.

@dvonthenen dvonthenen force-pushed the github-actions-automation branch 7 times, most recently from 667d941 to f9cec6a Compare May 10, 2024 19:58
@dvonthenen dvonthenen merged commit b6e0c04 into deepgram:main May 13, 2024
6 checks passed
@dvonthenen dvonthenen deleted the github-actions-automation branch May 13, 2024 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants