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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/actions/copy-workflow-go/action.yml
Expand Up @@ -46,6 +46,27 @@ 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
if [[ $TARGET_VERSION == "1.18" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This if is always true, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's correct. I wanted to make it clear that we can remove it in time for the next upgrade but I guess a comment might be more fitting for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

We probably shouldn't remove it. If any of the updates is not merged (and the repo stays on an old uCI version), it would be nice if this was included in the next update, just in case. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we might also want to enrol a new repository that's not on latest Go yet and still uses ioutil - it'd come in handy then too.

Let me just remove the if-clause then.

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')"

goimports -w .

git add .
git commit -m "stop using the deprecated io/ioutil package"
fi
fi
- name: go mod tidy (on initial workflow deployment)
if: ${{ env.INITIAL_WORKFLOW_DEPLOYMENT == 1 }}
Expand Down