From 6c6b4bde5f5a626bafcccc8eb0a6280f78a06caf Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 25 Aug 2022 13:11:59 +0200 Subject: [PATCH 1/3] automate cleaning up deprecated io/ioutil --- .github/actions/copy-workflow-go/action.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index 4356430a..a5b7b459 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -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 + 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 }} From a4a319e3f7f1cf1f1d254b7a31b19f54589cd6c5 Mon Sep 17 00:00:00 2001 From: galargh Date: Thu, 25 Aug 2022 13:49:41 +0200 Subject: [PATCH 2/3] remove target version guard and add goimports install --- .github/actions/copy-workflow-go/action.yml | 31 ++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index a5b7b459..3287adcb 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -49,24 +49,23 @@ runs: # 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 - 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')" + 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 . + go install golang.org/x/tools/cmd/goimports@b3b5c13b291f9653da6f31b95db100a2e26bd186 # v0.1.12 + goimports -w . - git add . - git commit -m "stop using the deprecated io/ioutil package" - fi + 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 }} From d1ada68f529320c188674d7860ed8e3ae28c8312 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Thu, 25 Aug 2022 13:54:55 +0200 Subject: [PATCH 3/3] install goimports by providing the tag name --- .github/actions/copy-workflow-go/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/copy-workflow-go/action.yml b/.github/actions/copy-workflow-go/action.yml index 3287adcb..fbd3b918 100644 --- a/.github/actions/copy-workflow-go/action.yml +++ b/.github/actions/copy-workflow-go/action.yml @@ -61,7 +61,7 @@ runs: sed -i 's/ioutil.WriteFile/os.WriteFile/' "${file}"; done <<< "$(find . -type f -name '*.go')" - go install golang.org/x/tools/cmd/goimports@b3b5c13b291f9653da6f31b95db100a2e26bd186 # v0.1.12 + go install golang.org/x/tools/cmd/goimports@v0.1.12 goimports -w . git add .