Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
automate cleaning up deprecated io/ioutil (#377)
Browse files Browse the repository at this point in the history
* automate cleaning up deprecated io/ioutil

* remove target version guard and add goimports install

* install goimports by providing the tag name
  • Loading branch information
galargh authored and masih committed Nov 8, 2022
1 parent 961348a commit 3ab93c9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/actions/copy-workflow-go/action.yml
Expand Up @@ -46,6 +46,26 @@ runs:
# We don't tidy, because the next step does that.
# Separate commits also help with reviews.
git commit -m "bump go.mod to Go $TARGET_VERSION and run go fix"
# As of Go 1.19 io/ioutil is deprecated
# We automate its upgrade here because it is quite a widely used package
while read file; do
sed -i 's/ioutil.NopCloser/io.NopCloser/' "${file}";
sed -i 's/ioutil.ReadAll/io.ReadAll/' "${file}";
# Skipping ReadDir replacement because it's a bit more complicated
# See https://pkg.go.dev/io/ioutil#ReadDir
# sed -i 's/ioutil.ReadDir/os.ReadDir/' "${file}";
sed -i 's/ioutil.ReadFile/os.ReadFile/' "${file}";
sed -i 's/ioutil.TempDir/os.MkdirTemp/' "${file}";
sed -i 's/ioutil.TempFile/os.CreateTemp/' "${file}";
sed -i 's/ioutil.WriteFile/os.WriteFile/' "${file}";
done <<< "$(find . -type f -name '*.go')"
go install golang.org/x/tools/cmd/goimports@v0.1.12
goimports -w .
git add .
git commit -m "stop using the deprecated io/ioutil package"
fi
- name: go mod tidy (on initial workflow deployment)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }}
Expand Down

0 comments on commit 3ab93c9

Please sign in to comment.