diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index 4356430a..fbd3b918 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -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 }}