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

automate cleaning up deprecated io/ioutil #377

Merged
merged 3 commits into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/actions/copy-workflow-go/action.yml
Original file line number Diff line number Diff line change
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