mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-14 08:36:26 +00:00
feat(manager/gomod): support updating go version in go.mod files (#16541)
This commit is contained in:
parent
1342cc15d9
commit
a6e5eefb64
6 changed files with 50 additions and 609 deletions
|
@ -1,607 +1,5 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`modules/manager/gomod/extract extractPackageFile() extracts constraints 1`] = `
|
||||
Object {
|
||||
"constraints": Object {
|
||||
"go": "^1.13",
|
||||
},
|
||||
"deps": Array [
|
||||
Object {
|
||||
"currentValue": "v0.45.1",
|
||||
"datasource": "go",
|
||||
"depName": "cloud.google.com/go",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 5,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.3.0",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/Parallels/docker-machine-parallels",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 7,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v3.5.0+incompatible",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/blang/semver",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 9,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v2.2.1+incompatible",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/cenkalti/backoff",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 11,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v3.0.1",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/cheggaaa/pb/v3",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 12,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "bcc4c8345a21",
|
||||
"currentValue": "v0.0.0-20151120183258-bcc4c8345a21",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/cloudfoundry-attic/jibber_jabber",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 13,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.13.1",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/docker/docker",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 17,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.4.0",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/docker/go-units",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 18,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.7.1-0.20190902101342-b170508bf44c",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/docker/machine",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 19,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "9d40249d3c2f",
|
||||
"currentValue": "v0.0.0-20190421051319-9d40249d3c2f",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/elazarl/goproxy",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 20,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "604e922904d3",
|
||||
"currentValue": "v0.0.0-20130729185459-604e922904d3",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/golang-collections/collections",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 25,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "23def4e6c14b",
|
||||
"currentValue": "v0.0.0-20160126235308-23def4e6c14b",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/golang/glog",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 26,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.3.2-0.20191028172631-481baca67f93",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/google/go-cmp",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 27,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "aec8da010de2",
|
||||
"currentValue": "v0.0.0-20200131185320-aec8da010de2",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/google/go-containerregistry",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 28,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v17.0.0+incompatible",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/google/go-github",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 29,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.4.0",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/hashicorp/go-getter",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 32,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.5.4",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/hashicorp/go-retryablehttp",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 33,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "1cf07e5970d8",
|
||||
"currentValue": "v0.0.0-20170318115843-1cf07e5970d8",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/hooklift/iso9660",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 35,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "c48c3734757f",
|
||||
"currentValue": "v0.0.0-20200318065542-c48c3734757f",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/johanneswuerbach/nfsexports",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 38,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "9c5c9712527c",
|
||||
"currentValue": "v0.0.0-20190205081909-9c5c9712527c",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/juju/clock",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 39,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "d21b13acf4bf",
|
||||
"currentValue": "v0.0.0-20180619145857-d21b13acf4bf",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/juju/mutex",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 42,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "95032a82bc51",
|
||||
"currentValue": "v0.0.0-20180428030007-95032a82bc51",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/kballard/go-shellquote",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 47,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v3.4.0+incompatible",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/libvirt/libvirt-go",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 49,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.1.1",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/machine-drivers/docker-machine-driver-vmware",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 50,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.0.11",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/mattn/go-isatty",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 51,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "4fdf99ab2936",
|
||||
"currentValue": "v0.0.0-20170309133038-4fdf99ab2936",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/mitchellh/go-ps",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 52,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "a12cd7250bcd",
|
||||
"currentValue": "v0.0.0-20171020124204-a12cd7250bcd",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/moby/hyperkit",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 53,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.0.4",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/olekukonko/tablewriter",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 54,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.0.0-rc1",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/opencontainers/go-digest",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 57,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.0.2",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/otiai10/copy",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 58,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.2.0",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/pborman/uuid",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 59,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "95f893ade6f2",
|
||||
"currentValue": "v0.0.0-20180830031419-95f893ade6f2",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/phayes/freeport",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 61,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "9302be274faa",
|
||||
"currentValue": "v0.0.0-20160118053552-9302be274faa",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/pkg/browser",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 62,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.9.1",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/pkg/errors",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 63,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "3a8809bd8a80",
|
||||
"currentValue": "v0.0.0-20161223203901-3a8809bd8a80",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/pkg/profile",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 64,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.0.0",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/pmezard/go-difflib",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 65,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v2.18.12+incompatible",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/shirou/gopsutil",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 70,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.0.0",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/spf13/cobra",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 72,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.0.5",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/spf13/pflag",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 73,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.6.1",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/spf13/viper",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 74,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "1d523034197f",
|
||||
"currentValue": "v0.0.0-20180618132009-1d523034197f",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/xeipuuv/gojsonschema",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 77,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "97ebf9174097",
|
||||
"currentValue": "v0.0.0-20161021174912-97ebf9174097",
|
||||
"datasource": "go",
|
||||
"depName": "github.com/zchee/go-vmnet",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 78,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "2835ba2e683f",
|
||||
"currentValue": "v0.0.0-20190927031335-2835ba2e683f",
|
||||
"datasource": "go",
|
||||
"depName": "golang.org/x/build",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 79,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "78000ba7a073",
|
||||
"currentValue": "v0.0.0-20200302210943-78000ba7a073",
|
||||
"datasource": "go",
|
||||
"depName": "golang.org/x/crypto",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 80,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "cd5d95a43a6e",
|
||||
"currentValue": "v0.0.0-20190911185100-cd5d95a43a6e",
|
||||
"datasource": "go",
|
||||
"depName": "golang.org/x/sync",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 82,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentDigest": "9fbb57f87de9",
|
||||
"currentValue": "v0.0.0-20200124204421-9fbb57f87de9",
|
||||
"datasource": "go",
|
||||
"depName": "golang.org/x/sys",
|
||||
"depType": "require",
|
||||
"digestOneAndOnly": true,
|
||||
"managerData": Object {
|
||||
"lineNumber": 83,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.3.2",
|
||||
"datasource": "go",
|
||||
"depName": "golang.org/x/text",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 84,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.9.0",
|
||||
"datasource": "go",
|
||||
"depName": "google.golang.org/api",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 85,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v2.2.8",
|
||||
"datasource": "go",
|
||||
"depName": "gopkg.in/yaml.v2",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 91,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.17.3",
|
||||
"datasource": "go",
|
||||
"depName": "k8s.io/api",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 93,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.17.3",
|
||||
"datasource": "go",
|
||||
"depName": "k8s.io/apimachinery",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 94,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.17.3",
|
||||
"datasource": "go",
|
||||
"depName": "k8s.io/client-go",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 95,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v0.0.0",
|
||||
"datasource": "go",
|
||||
"depName": "k8s.io/kubectl",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 96,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v1.17.3",
|
||||
"datasource": "go",
|
||||
"depName": "k8s.io/kubernetes",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 97,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"currentValue": "v4.0.0+incompatible",
|
||||
"datasource": "go",
|
||||
"depName": "sigs.k8s.io/sig-storage-lib-external-provisioner",
|
||||
"depType": "require",
|
||||
"managerData": Object {
|
||||
"lineNumber": 99,
|
||||
"multiLine": true,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`modules/manager/gomod/extract extractPackageFile() extracts multi-line requires 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
|
|
|
@ -19,9 +19,17 @@ describe('modules/manager/gomod/extract', () => {
|
|||
expect(res?.filter((e) => e.depType === 'replace')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('extracts constraints', () => {
|
||||
it('extracts constraints and golang', () => {
|
||||
const res = extractPackageFile(gomod3);
|
||||
expect(res).toMatchSnapshot();
|
||||
expect(res?.deps).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
depType: 'golang',
|
||||
depName: 'go',
|
||||
datasource: 'golang-version',
|
||||
}),
|
||||
])
|
||||
);
|
||||
expect(res?.constraints?.go).toBe('^1.13');
|
||||
});
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import semver from 'semver';
|
|||
import { logger } from '../../../logger';
|
||||
import { newlineRegex, regEx } from '../../../util/regex';
|
||||
import { GoDatasource } from '../../datasource/go';
|
||||
import { GolangVersionDatasource } from '../../datasource/golang-version';
|
||||
import { isVersion } from '../../versioning/semver';
|
||||
import type { PackageDependency, PackageFile } from '../types';
|
||||
|
||||
|
@ -34,6 +35,19 @@ function getDep(
|
|||
return dep;
|
||||
}
|
||||
|
||||
function getGoDep(lineNumber: number, goVer: string): PackageDependency {
|
||||
return {
|
||||
managerData: {
|
||||
lineNumber,
|
||||
},
|
||||
depName: 'go',
|
||||
depType: 'golang',
|
||||
currentValue: goVer,
|
||||
datasource: GolangVersionDatasource.id,
|
||||
versioning: 'npm',
|
||||
};
|
||||
}
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.trace({ content }, 'gomod.extractPackageFile()');
|
||||
const constraints: Record<string, any> = {};
|
||||
|
@ -42,10 +56,10 @@ export function extractPackageFile(content: string): PackageFile | null {
|
|||
const lines = content.split(newlineRegex);
|
||||
for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) {
|
||||
let line = lines[lineNumber];
|
||||
if (
|
||||
line.startsWith('go ') &&
|
||||
semver.validRange(line.replace('go ', ''))
|
||||
) {
|
||||
const goVer = line.startsWith('go ') ? line.replace('go ', '') : null;
|
||||
if (goVer && semver.validRange(goVer)) {
|
||||
const dep = getGoDep(lineNumber, goVer);
|
||||
deps.push(dep);
|
||||
constraints.go = line.replace('go ', '^');
|
||||
}
|
||||
const replaceMatch = regEx(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { ProgrammingLanguage } from '../../../constants';
|
||||
import { GoDatasource } from '../../datasource/go';
|
||||
import { GolangVersionDatasource } from '../../datasource/golang-version';
|
||||
import { updateArtifacts } from './artifacts';
|
||||
import { extractPackageFile } from './extract';
|
||||
import { updateDependency } from './update';
|
||||
|
@ -11,4 +12,7 @@ export const defaultConfig = {
|
|||
fileMatch: ['(^|/)go.mod$'],
|
||||
};
|
||||
|
||||
export const supportedDatasources = [GoDatasource.id];
|
||||
export const supportedDatasources = [
|
||||
GoDatasource.id,
|
||||
GolangVersionDatasource.id,
|
||||
];
|
||||
|
|
|
@ -4,6 +4,7 @@ import { updateDependency } from '.';
|
|||
|
||||
const gomod1 = Fixtures.get('1/go.mod');
|
||||
const gomod2 = Fixtures.get('2/go.mod');
|
||||
const gomod3 = Fixtures.get('3/go.mod');
|
||||
|
||||
describe('modules/manager/gomod/update', () => {
|
||||
describe('updateDependency', () => {
|
||||
|
@ -19,6 +20,18 @@ describe('modules/manager/gomod/update', () => {
|
|||
expect(res).toContain(upgrade.newValue);
|
||||
});
|
||||
|
||||
it('replaces golang version update', () => {
|
||||
const upgrade = {
|
||||
depName: 'go',
|
||||
managerData: { lineNumber: 2 },
|
||||
newValue: '1.18',
|
||||
depType: 'golang',
|
||||
};
|
||||
const res = updateDependency({ fileContent: gomod3, upgrade });
|
||||
expect(res).not.toEqual(gomod3);
|
||||
expect(res).toContain(upgrade.newValue);
|
||||
});
|
||||
|
||||
it('replaces two values in one file', () => {
|
||||
const upgrade1 = {
|
||||
depName: 'github.com/pkg/errors',
|
||||
|
|
|
@ -39,6 +39,10 @@ export function updateDependency({
|
|||
return null;
|
||||
}
|
||||
let updateLineExp: RegExp | undefined;
|
||||
|
||||
if (depType === 'golang') {
|
||||
updateLineExp = regEx(/(?<depPart>go)(?<divider>\s+)[^\s]+/);
|
||||
}
|
||||
if (depType === 'replace') {
|
||||
updateLineExp = regEx(
|
||||
/^(?<depPart>replace\s+[^\s]+[\s]+[=][>]+\s+)(?<divider>[^\s]+\s+)[^\s]+/
|
||||
|
|
Loading…
Reference in a new issue