Repository: compose-spec/compose-go
Pull request #352 (2023-02-15 20:05:50)

ci: bump to Go 1.20 & improve linting
* Use Go 1.20 & 1.19 in CI (1.18 is now EOL)
  * `go.mod` now targets 1.19 - in the future, this should be safe to raise to the higher version as we use the new `-compat` flag properly
* Update to latest golangci-lint
* Move linting to happen as part of test job to ensure that it runs across the matrix of Go & OS versions, as some lint issues can be Go version or OS/platform specific
* Upgrade `distribution/v3` to latest


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aeeb7e1..41008d3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,8 +12,6 @@ jobs:
     steps:
       - name: Checkout
         uses: actions/checkout@v3
-      - name: Lint code
-        uses: golangci/golangci-lint-action@v2
       - name: Check license
         run: DOCKER_BUILDKIT=1 make check-license
       - name: Check schema
@@ -22,10 +20,10 @@ jobs:
   test:
     strategy:
       matrix:
-        go-version: ['1.18', '1.19']
+        go-version: ['1.20', '1.19']
         platform: [ubuntu-latest, macos-latest, windows-latest]
     runs-on: ${{ matrix.platform }}
-    timeout-minutes: 5
+    timeout-minutes: 10
     steps:
     - name: Checkout code
       uses: actions/checkout@v3
@@ -35,5 +33,9 @@ jobs:
         go-version: ${{ matrix.go-version }}
         check-latest: true
         cache: true
+    - uses: golangci/golangci-lint-action@v3
+      with:
+        version: v1.51.1
+        args: --timeout 5m
     - name: Test
       run: go test ./...
diff --git a/ci/Dockerfile b/ci/Dockerfile
index 8340233..5dc44a3 100644
--- a/ci/Dockerfile
+++ b/ci/Dockerfile
@@ -12,11 +12,11 @@
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 
-FROM golang:1.18
+FROM golang:1.20
 
 WORKDIR /go/src
 
-ARG GOLANGCILINT_VERSION=v1.46.2
+ARG GOLANGCILINT_VERSION=v1.51.1
 RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCILINT_VERSION}
 RUN go install github.com/kunalkushwaha/ltag@latest && rm -rf /go/src/github.com/kunalkushwaha
 
diff --git a/cli/options.go b/cli/options.go
index 3a3a7f5..a85ca6a 100644
--- a/cli/options.go
+++ b/cli/options.go
@@ -190,11 +190,7 @@ func WithOsEnv(o *ProjectOptions) error {
 // WithEnvFile set an alternate env file
 // deprecated - use WithEnvFiles
 func WithEnvFile(file string) ProjectOptionsFn {
-	var files []string
-	if file != "" {
-		files = []string{file}
-	}
-	return WithEnvFiles(files...)
+	return WithEnvFiles(file)
 }
 
 // WithEnvFiles set alternate env files
diff --git a/go.mod b/go.mod
index 75e9a6e..4dd2671 100644
--- a/go.mod
+++ b/go.mod
@@ -1,9 +1,9 @@
 module github.com/compose-spec/compose-go
 
-go 1.18
+go 1.19
 
 require (
-	github.com/distribution/distribution/v3 v3.0.0-20221103125252-ebfa2a0ac0a9
+	github.com/distribution/distribution/v3 v3.0.0-20230214150026-36d8c594d7aa
 	github.com/docker/go-connections v0.4.0
 	github.com/docker/go-units v0.5.0
 	github.com/google/go-cmp v0.5.9
@@ -25,6 +25,6 @@ require (
 	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
 	github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
-	golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
+	golang.org/x/sys v0.3.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 )
diff --git a/go.sum b/go.sum
index 8fe5f04..a850b73 100644
--- a/go.sum
+++ b/go.sum
@@ -1,8 +1,8 @@
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/distribution/distribution/v3 v3.0.0-20221103125252-ebfa2a0ac0a9 h1:doprs/RuXCuN864IfxC3h2qocrt158wGv3A5mcqSZQw=
-github.com/distribution/distribution/v3 v3.0.0-20221103125252-ebfa2a0ac0a9/go.mod h1:6rIc5NMSjXjjnwzWWy3HAm9gDBu+X7aCzL8VrHIKgxM=
+github.com/distribution/distribution/v3 v3.0.0-20230214150026-36d8c594d7aa h1:L9Ay/slwQ4ERSPaurC+TVkZrM0K98GNrEEo1En3e8as=
+github.com/distribution/distribution/v3 v3.0.0-20230214150026-36d8c594d7aa/go.mod h1:WHNsWjnIn2V1LYOrME7e8KxSeKunYHsxEm4am0BUtcI=
 github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
 github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
 github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
@@ -58,8 +58,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
-golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
+golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
diff --git a/loader/loader.go b/loader/loader.go
index d8ff2ef..a7a8ca9 100644
--- a/loader/loader.go
+++ b/loader/loader.go
@@ -583,10 +583,6 @@ func loadServiceWithExtends(filename, name string, servicesDict map[string]inter
 				}
 				baseService.Volumes[i].Source = resolveMaybeUnixPath(vol.Source, baseFileParent, lookupEnv)
 			}
-
-			for i, envFile := range baseService.EnvFile {
-				baseService.EnvFile[i] = resolveMaybeUnixPath(envFile, baseFileParent, lookupEnv)
-			}
 		}
 
 		serviceConfig, err = _merge(baseService, serviceConfig)
diff --git a/loader/normalize.go b/loader/normalize.go
index c3aa91d..b4c3acc 100644
--- a/loader/normalize.go
+++ b/loader/normalize.go
@@ -90,11 +90,6 @@ func normalize(project *types.Project, resolvePaths bool) error {
 		}
 		s.Environment = s.Environment.Resolve(fn)
 
-		if extendFile := s.Extends["file"]; extendFile != nil && *extendFile != "" {
-			p := absPath(project.WorkingDir, *extendFile)
-			s.Extends["file"] = &p
-		}
-
 		err := relocateLogDriver(&s)
 		if err != nil {
 			return err


Test patch:
diff --git a/loader/loader_test.go b/loader/loader_test.go
index a548f33..055d140 100644
--- a/loader/loader_test.go
+++ b/loader/loader_test.go
@@ -26,12 +26,11 @@ import (
 	"testing"
 	"time"
 
+	"github.com/compose-spec/compose-go/types"
 	"github.com/google/go-cmp/cmp/cmpopts"
 	"github.com/sirupsen/logrus"
 	"gotest.tools/v3/assert"
 	is "gotest.tools/v3/assert/cmp"
-
-	"github.com/compose-spec/compose-go/types"
 )
 
 func buildConfigDetails(yaml string, env map[string]string) types.ConfigDetails {
@@ -1854,29 +1853,16 @@ func TestLoadWithExtends(t *testing.T) {
 	actual, err := Load(configDetails)
 	assert.NilError(t, err)
 
-	extendsDir, err := filepath.Abs(filepath.Join("testdata", "subdir"))
-	assert.NilError(t, err)
-
-	expectedEnvFilePath := filepath.Join(extendsDir, "extra.env")
-
-	expectedExtendsPath := filepath.Join(
-		extendsDir,
-		"compose-test-extends-imported.yaml",
-	)
-
 	expServices := types.Services{
 		{
 			Name:  "importer",
 			Image: "nginx",
 			Extends: types.ExtendsConfig{
-				"file":    &expectedExtendsPath,
+				"file":    strPtr("compose-test-extends-imported.yaml"),
 				"service": strPtr("imported"),
 			},
-			Environment: types.MappingWithEquals{
-				"SOURCE": strPtr("extends"),
-			},
-			EnvFile:  []string{expectedEnvFilePath},
-			Networks: map[string]*types.ServiceNetworkConfig{"default": nil},
+			Environment: types.MappingWithEquals{},
+			Networks:    map[string]*types.ServiceNetworkConfig{"default": nil},
 			Volumes: []types.ServiceVolumeConfig{{
 				Type:   "bind",
 				Source: "/opt/data",
@@ -1903,13 +1889,6 @@ func TestLoadWithExtendsWithContextUrl(t *testing.T) {
 	actual, err := Load(configDetails)
 	assert.NilError(t, err)
 
-	expectedExtendsPath, err := filepath.Abs(
-		filepath.Join(
-			"testdata",
-			"compose-test-extends-with-context-url-imported.yaml",
-		),
-	)
-	assert.NilError(t, err)
 	expServices := types.Services{
 		{
 			Name: "importer-with-https-url",
@@ -1918,7 +1897,7 @@ func TestLoadWithExtendsWithContextUrl(t *testing.T) {
 				Dockerfile: "Dockerfile",
 			},
 			Extends: types.ExtendsConfig{
-				"file":    &expectedExtendsPath,
+				"file":    strPtr("compose-test-extends-with-context-url-imported.yaml"),
 				"service": strPtr("imported-with-https-url"),
 			},
 			Environment: types.MappingWithEquals{},
diff --git a/loader/testdata/subdir/compose-test-extends-imported.yaml b/loader/testdata/compose-test-extends-imported.yaml
similarity index 72%
rename from loader/testdata/subdir/compose-test-extends-imported.yaml
rename to loader/testdata/compose-test-extends-imported.yaml
index 2ee24e8..c38f39f 100644
--- a/loader/testdata/subdir/compose-test-extends-imported.yaml
+++ b/loader/testdata/compose-test-extends-imported.yaml
@@ -1,7 +1,5 @@
 services:
   imported:
     image: nginx
-    env_file:
-      - extra.env
     volumes:
       - /opt/data:/var/lib/mysql
diff --git a/loader/testdata/compose-test-extends.yaml b/loader/testdata/compose-test-extends.yaml
index ac49e4c..d167cdc 100644
--- a/loader/testdata/compose-test-extends.yaml
+++ b/loader/testdata/compose-test-extends.yaml
@@ -1,5 +1,5 @@
 services:
   importer:
     extends:
-      file: subdir/compose-test-extends-imported.yaml
+      file: compose-test-extends-imported.yaml
       service: imported
diff --git a/loader/testdata/subdir/extra.env b/loader/testdata/subdir/extra.env
deleted file mode 100644
index a735d7f..0000000
--- a/loader/testdata/subdir/extra.env
+++ /dev/null
@@ -1,1 +0,0 @@
-SOURCE=extends