-
Notifications
You must be signed in to change notification settings - Fork 812
/
Copy pathrenovate-config.js
141 lines (133 loc) · 4.31 KB
/
renovate-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const child_process = require( 'child_process' );
const fs = require( 'fs' );
const path = require( 'path' );
const monorepoBase = '/tmp/monorepo/';
const composerLibraryFiles = [];
{
const libtypes = new Set( [ 'jetpack-library', 'phpcodesniffer-standard' ] );
const basedir = monorepoBase + 'projects/packages';
for ( const d of fs.readdirSync( basedir, { withFileTypes: true } ) ) {
const filepath = path.join( basedir, d.name, 'composer.json' );
if ( ! fs.existsSync( filepath ) ) {
continue;
}
const json = JSON.parse( fs.readFileSync( filepath, 'utf8' ) );
if ( libtypes.has( json.type ) ) {
composerLibraryFiles.push( filepath.substring( monorepoBase.length ) );
}
}
composerLibraryFiles.sort();
}
const versions = Object.fromEntries(
Array.from(
fs
.readFileSync( monorepoBase + '.github/versions.sh', 'utf8' )
.matchAll( /^\s*([a-zA-Z_][a-zA-Z0-9_]*)=(.*?)\s*$/gm ),
v => [ v[ 1 ], v[ 2 ] ]
)
);
module.exports = {
branchPrefix: 'renovate/',
allowPlugins: true,
allowScripts: true,
ignoreScripts: false,
gitAuthor: 'Renovate Bot (self-hosted) <[email protected]>',
platform: 'github',
repositories: [ 'Automattic/jetpack' ],
// Extra code to run before creating a commit.
allowedPostUpgradeCommands: [ monorepoBase + '.github/files/renovate-post-upgrade-run.sh' ],
postUpgradeTasks: {
commands: [ monorepoBase + '.github/files/renovate-post-upgrade-run.sh {{{branchName}}}' ],
executionMode: 'branch',
},
postUpdateOptions: [ 'pnpmDedupe' ],
// Most of the actual renovate configuration is in renovate.json5, except for a few things
// where we want to read part of it from somewhere else.
constraints: {
php: `~${ versions.PHP_VERSION }.0`,
},
packageRules: [
// Monorepo packages shouldn't be processed by renovate.
{
groupName: 'Monorepo packages',
matchPackageNames: ( () => {
const monorepoPackages = [];
const files = {
packages: 'composer.json',
'js-packages': 'package.json',
};
for ( const [ dir, file ] of Object.entries( files ) ) {
const basedir = path.resolve( monorepoBase, 'projects/', dir );
for ( const d of fs.readdirSync( basedir, { withFileTypes: true } ) ) {
if ( ! d.isDirectory() ) {
continue;
}
const filepath = path.join( basedir, d.name, file );
if ( ! fs.existsSync( filepath ) ) {
continue;
}
const json = JSON.parse( fs.readFileSync( filepath, 'utf8' ) );
if ( json.name ) {
monorepoPackages.push( json.name );
}
}
}
return monorepoPackages.sort();
} )(),
enabled: false,
},
// PHP non-dev deps need to work with the oldest PHP versions we support.
{
matchDatasources: [ 'packagist' ],
matchDepTypes: [ 'require' ],
constraintsFiltering: 'strict',
constraints: {
php: `~${ versions.MIN_PHP_VERSION }.0`,
},
// Need to have renovate tell composer to ignore `.require.php` since dev deps aren't constrained by this
// but renovate insists on using the above to choose the PHP version to run with. Sigh.
composerIgnorePlatformReqs: [ 'ext-*', 'lib-*', 'php' ],
},
...( () => {
const ret = {};
const { stdout } = child_process.spawnSync(
'git',
[ '-c', 'core.quotepath=off', 'ls-files', 'composer.json', '*/composer.json' ],
{
cwd: monorepoBase,
stdio: [ 'ignore', 'pipe', 'ignore' ],
encoding: 'utf-8',
}
);
for ( const filepath of stdout.split( /\n/ ) ) {
if ( filepath === '' ) {
continue;
}
const json = JSON.parse(
fs.readFileSync( path.resolve( monorepoBase, filepath ), 'utf8' )
);
if ( json.require?.php && json.require.php !== `>=${ versions.MIN_PHP_VERSION }` ) {
let req = json.require.php;
// Renovate is very cautious, ">=7.4" won't match "^7.0 || ^8.0" because 9.0 could exist.
// Rewrite it to "~7.4.0", since if it supports 7.4 it's probably ok with 8.0 (minus perhaps some deprecation warnings).
const m = json.require.php.match( /^>=(\d+\.\d+)$/ );
if ( m ) {
req = `~${ m[ 1 ] }.0`;
}
if ( ! ret[ req ] ) {
ret[ req ] = {
matchFileNames: [],
matchDatasources: [ 'packagist' ],
matchDepTypes: [ 'require' ],
constraints: {
php: req,
},
};
}
ret[ req ].matchFileNames.push( filepath );
}
}
return Object.values( ret );
} )(),
],
};