diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6adeb46..79ccaf8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,20 +15,20 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: - go-version: 1.16 + go-version: "1.22" - name: Docker Login - uses: docker/login-action@v1 + uses: docker/login-action@v3 with: username: txservices password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index cc70885..9615cee 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -38,11 +38,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -56,7 +56,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 # â„šī¸ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -69,4 +69,4 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7f68c8..5a4b832 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,20 +8,18 @@ on: name: Test jobs: test: - env: - GO111MODULE: "on" strategy: matrix: - go-version: [1.16.x] + go-version: [1.22.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Build run: make local-build - name: Test @@ -38,12 +36,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: - go-version: "1.17.x" + go-version: "1.22.x" - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@2022.1 + run: go install honnef.co/go/tools/cmd/staticcheck@2024.1.1 - name: Run staticcheck run: staticcheck ./... diff --git a/Makefile b/Makefile index d6df14f..a8572da 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ cli-build: DOCKER_BUILDKIT=1 docker build -f ./build/Dockerfile --platform ${PLATFORM} -t go-cli:devel . cli-tests: - docker-compose run --rm cli-test + docker compose run --rm cli-test docker-build: DOCKER_BUILDKIT=1 docker build -f ./build/Dockerfile-bin --output bin/ --platform ${PLATFORM} --target bin . diff --git a/go.mod b/go.mod index 8d079f4..157cbc8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/transifex/cli -go 1.16 +go 1.22 require ( github.com/blang/semver v3.5.1+incompatible @@ -11,10 +11,45 @@ require ( github.com/manifoldco/promptui v0.8.0 github.com/mattn/go-isatty v0.0.14 github.com/rhysd/go-github-selfupdate v1.2.3 - github.com/smartystreets/goconvey v1.6.4 // indirect - github.com/stretchr/testify v1.7.0 // indirect + github.com/stretchr/testify v1.7.0 github.com/urfave/cli/v2 v2.3.0 - golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect + golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d gopkg.in/ini.v1 v1.62.0 +) + +require ( + github.com/Microsoft/go-winio v0.4.16 // indirect + github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/emirpasic/gods v1.12.0 // indirect + github.com/go-git/gcfg v1.5.0 // indirect + github.com/go-git/go-billy/v5 v5.1.0 // indirect + github.com/golang/protobuf v1.3.2 // indirect + github.com/google/go-github/v30 v30.1.0 // indirect + github.com/google/go-querystring v1.0.0 // indirect + github.com/gosimple/unidecode v1.0.1 // indirect + github.com/imdario/mergo v0.3.12 // indirect + github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect + github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect + github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect + github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a // indirect + github.com/mattn/go-colorable v0.1.9 // indirect + github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/sergi/go-diff v1.1.0 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/smartystreets/goconvey v1.6.4 // indirect + github.com/tcnksm/go-gitconfig v0.1.2 // indirect + github.com/ulikunitz/xz v0.5.9 // indirect + github.com/xanzy/ssh-agent v0.3.0 // indirect + golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect + golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect + golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 // indirect + golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + google.golang.org/appengine v1.3.0 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/internal/txlib/add_remote_test.go b/internal/txlib/add_remote_test.go index 32a5061..2a1a19f 100644 --- a/internal/txlib/add_remote_test.go +++ b/internal/txlib/add_remote_test.go @@ -2,7 +2,7 @@ package txlib import ( "fmt" - "io/ioutil" + "io" "net/url" "os" "reflect" @@ -147,7 +147,7 @@ func TestAddRemoteInvalidFileFormat(t *testing.T) { // Restore stdout w.Close() os.Stdout = oldStdout - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) r.Close() testSimpleGet(t, mockData, projectUrl) diff --git a/internal/txlib/config/main.go b/internal/txlib/config/main.go index 49c8516..dc0d082 100644 --- a/internal/txlib/config/main.go +++ b/internal/txlib/config/main.go @@ -101,7 +101,7 @@ The local configuration has a 'host' field in its 'main' section. That host points to a section in the root configuration. We return the rest_hostname of that section. The fallback value is `https://rest.api.transifex.com` */ func (cfg *Config) GetActiveHost() *Host { - if cfg.Root.Hosts == nil || len(cfg.Root.Hosts) == 0 || + if len(cfg.Root.Hosts) == 0 || cfg.Local == nil { return nil } diff --git a/internal/txlib/delete.go b/internal/txlib/delete.go index 78a08c3..dd20a66 100644 --- a/internal/txlib/delete.go +++ b/internal/txlib/delete.go @@ -180,9 +180,8 @@ func deleteResource( return err } if remoteStatAttributes.TranslatedStrings > 0 { - msg := fmt.Sprintf("Aborting due to translations in %s", + return fmt.Errorf("aborting due to translations in %s", cfgResource.ResourceSlug) - return fmt.Errorf(msg) } } } diff --git a/internal/txlib/migrate.go b/internal/txlib/migrate.go index 0434802..982a773 100644 --- a/internal/txlib/migrate.go +++ b/internal/txlib/migrate.go @@ -2,7 +2,7 @@ package txlib import ( "fmt" - "io/ioutil" + "os" "path/filepath" "strings" "time" @@ -34,7 +34,7 @@ func MigrateLegacyConfigFile( // Backup previous file before doing anything //Read all the contents of the original config file - bytesRead, err := ioutil.ReadFile(cfg.Local.Path) + bytesRead, err := os.ReadFile(cfg.Local.Path) if err != nil { return "", fmt.Errorf("aborting, could not create backup file %w", err) } @@ -45,7 +45,7 @@ func MigrateLegacyConfigFile( backUpFilePath := filepath.Join(filepath.Dir(cfg.Local.Path), "config_"+currentTime.Format("20060102150405")+".bak") - err = ioutil.WriteFile(backUpFilePath, bytesRead, 0755) + err = os.WriteFile(backUpFilePath, bytesRead, 0755) if err != nil { return "", fmt.Errorf("aborting, could not create backup file %w", err) diff --git a/internal/txlib/migrate_test.go b/internal/txlib/migrate_test.go index 0a87ae0..8711da0 100644 --- a/internal/txlib/migrate_test.go +++ b/internal/txlib/migrate_test.go @@ -2,7 +2,7 @@ package txlib import ( "fmt" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -435,7 +435,7 @@ func TestNeedsTokenInRootConfig(t *testing.T) { _, _ = MigrateLegacyConfigFile(&cfg, api) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout assert.True(t, strings.Contains(string(out), "API token not found.")) @@ -507,7 +507,7 @@ func TestNoTransifexRcFile(t *testing.T) { _, _ = MigrateLegacyConfigFile(&cfg, api) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout assert.True(t, strings.Contains(string(out), "Please provide an API token to continue.")) @@ -668,12 +668,12 @@ func TestResourceMigrationFailed(t *testing.T) { } w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout assert.True(t, strings.Contains( string(out), "Could not migrate resource `ares`")) - content, err := ioutil.ReadFile(filepath.Join(tmpDir, "config")) + content, err := os.ReadFile(filepath.Join(tmpDir, "config")) if err != nil { t.Error(err) } @@ -798,11 +798,11 @@ func TestBackUpFileCreated(t *testing.T) { backupFilePath, _ := MigrateLegacyConfigFile(&cfg, api) - newContent, err := ioutil.ReadFile(filepath.Join(tmpDir, "config")) + newContent, err := os.ReadFile(filepath.Join(tmpDir, "config")) if err != nil { t.Error(err) } - buContent, err := ioutil.ReadFile(filepath.Join(backupFilePath)) + buContent, err := os.ReadFile(filepath.Join(backupFilePath)) if err != nil { t.Error(err) } diff --git a/internal/txlib/pull_test.go b/internal/txlib/pull_test.go index 6871ec6..b50a40f 100644 --- a/internal/txlib/pull_test.go +++ b/internal/txlib/pull_test.go @@ -2,7 +2,6 @@ package txlib import ( "fmt" - "io/ioutil" "os" "strings" "testing" @@ -684,7 +683,7 @@ func TestKeepNewFilesSourceOnlyWithDisableOverride(t *testing.T) { testSimpleGet(t, mockData, sourceDownloadUrl) assertFileContent(t, "aaa.json", "New source") - _, err = ioutil.ReadFile("aaa.json.new") + _, err = os.ReadFile("aaa.json.new") if err == nil { t.Error("File not exist because DisableOverwrite is not true") } diff --git a/internal/txlib/status_test.go b/internal/txlib/status_test.go index 449974e..ed7a774 100644 --- a/internal/txlib/status_test.go +++ b/internal/txlib/status_test.go @@ -2,7 +2,7 @@ package txlib import ( "fmt" - "io/ioutil" + "io" "log" "os" "strings" @@ -86,7 +86,7 @@ func TestStatusWithNoResourcesAsParameters(t *testing.T) { ) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -121,7 +121,7 @@ func TestStatusWithOverrides(t *testing.T) { ) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -157,7 +157,7 @@ func TestStatusWithResourceAsParameter(t *testing.T) { ) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) diff --git a/internal/txlib/update_test.go b/internal/txlib/update_test.go index 51adc0a..97dde47 100644 --- a/internal/txlib/update_test.go +++ b/internal/txlib/update_test.go @@ -1,7 +1,7 @@ package txlib import ( - "io/ioutil" + "io" "os" "strings" "testing" @@ -20,7 +20,7 @@ func TestUpdateCommandVersionLessThanProduction(t *testing.T) { os.Stdout = w _ = UpdateCommand(arguments) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -38,7 +38,7 @@ func TestUpdateCommandCheckGreaterThanProduction(t *testing.T) { os.Stdout = w _ = UpdateCommand(arguments) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -60,7 +60,7 @@ func TestUpdateCommandCheckEQtoProduction(t *testing.T) { os.Stdout = w _ = UpdateCommand(arguments) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -77,7 +77,7 @@ func TestUpdateCommandCheckLessThanProduction(t *testing.T) { os.Stdout = w _ = UpdateCommand(arguments) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -98,7 +98,7 @@ func TestUpdateCommandGreaterThanProduction(t *testing.T) { os.Stdout = w _ = UpdateCommand(arguments) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out) @@ -119,7 +119,7 @@ func TestUpdateCommandEQtoProduction(t *testing.T) { os.Stdout = w _ = UpdateCommand(arguments) w.Close() - out, _ := ioutil.ReadAll(r) + out, _ := io.ReadAll(r) os.Stdout = rescueStdout result := string(out)