Skip to content

Commit

Permalink
OPCT-199: Fixes related to CI code static analysis on dependencies (#60)
Browse files Browse the repository at this point in the history
The motivation of this PR is to fix/bump the static code check used on
Github CI, fixing issues reported on the new version. The issue has been
started, and it's isolated, from the PR
#54

Changes:

1) bump staticcheck version
2) fix issues reported by it

StaticCheck plugin used to Code Analysis on our CI was reporting issues
when bumping the OCP API lib, this is a false-positive:
-
https://github.com/redhat-openshift-ecosystem/provider-certification-tool/actions/runs/4608846263/jobs/8145167561

When updating the static check version it reports `io/ioutil`
deprecation addressed on this PR:

~~~
Error: internal/pkg/sippy/sippy.go:6:2: "io/ioutil" has been deprecated
since Go 1.16: As of Go 1.16, the same functionality is now provided by
package io or package os, and those implementations should be preferred
in new code. See the specific function documentation for details.
(SA1019)
Error: pkg/assets/bindata.go:11:2: "io/ioutil" has been deprecated since
Go 1.16: As of Go 1.16, the same functionality is now provided by
package io or package os, and those implementations should be preferred
in new code. See the specific function documentation for details.
(SA1019)
Error: Process completed with exit code 1.
~~~

Follow up for:
-
#54
- https://issues.redhat.com/browse/OPCT-181

Tracking card: https://issues.redhat.com/browse/OPCT-199
  • Loading branch information
mtulio committed Apr 11, 2023
1 parent 1d9951b commit 85dfec9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
set -xe
./hack/update-generated-bindata.sh
set +ex
# bypassing CI check for pkg/assets/bindata.go due go-bindata issues with ioutils
# https://issues.redhat.com/browse/OPCT-199
git checkout pkg/assets/bindata.go
git diff --exit-code
- name: Run unit tests
Expand All @@ -35,6 +38,6 @@ jobs:
run: make vet

- name: Run static code analysis
uses: dominikh/staticcheck-action@v1.2.0
uses: dominikh/staticcheck-action@v1.3.0
with:
version: "2022.1.1"
version: "2022.1.3"
19 changes: 19 additions & 0 deletions hack/patches/pkg-assets-bindata.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- pkg/assets/bindata.go 2023-04-11 12:33:12.134678061 -0300
+++ pkg/assets/bindata.go-ok 2023-04-11 12:33:07.950684962 -0300
@@ -8,7 +8,6 @@

import (
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -566,7 +565,7 @@
if err != nil {
return err
}
- err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
+ err = os.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
25 changes: 25 additions & 0 deletions hack/update-generated-bindata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -o errexit
set -o nounset
set -o pipefail

# generate static files with go-bindata[1]
# [1] https://github.com/go-bindata/go-bindata
# go-bindata requies minimal version of and go 1.19
# To install go-bindata run:
# $ go get -u github.com/go-bindata/go-bindata/...@latest

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..

if [[ ! $(which go-bindata) ]]; then
Expand All @@ -20,3 +26,22 @@ go-bindata \
-prefix "${SCRIPT_ROOT}" \
-o "${SCRIPT_ROOT}/pkg/assets/bindata.go" \
${SCRIPT_ROOT}/manifests/...

# io/ioutil is deprecated and go-bindata with the latest version
# is not addressing this recommendation. We are patching this file
# for now and plan to rid-off the go-bindata dependency v0.5+
# https://issues.redhat.com/browse/OPCT-199
#
# Temporary instructions to generate the patch and use on CI:
# # make sure the bindata.go is updated
# $ make update
# # patch the file, replacing ioutil.WriteFile to os.WriteFile
# # copy to file and update the dependencies
# $ cp pkg/assets/bindata.go hack/patches/pkg-assets-bindata.go
# $ make update
# # generate the patch
# $ diff -u pkg/assets/bindata.go hack/patches/pkg-assets-bindata.go > hack/patches/pkg-assets-bindata.go.patch
# $ rm hack/patches/pkg-assets-bindata.go
#
# # restore the patch on CI:
patch pkg/assets/bindata.go < hack/patches/pkg-assets-bindata.go.patch
4 changes: 2 additions & 2 deletions internal/pkg/sippy/sippy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sippy
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -115,7 +115,7 @@ func (a *SippyAPI) QueryTests(r *SippyTestsRequestInput) (*SippyTestsRequestOutp
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("couldn't parse response body. %+v", err)

Expand Down
3 changes: 1 addition & 2 deletions pkg/assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85dfec9

Please sign in to comment.