-
Notifications
You must be signed in to change notification settings - Fork 0
/
renovate-config.js
183 lines (176 loc) · 5.22 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* Return the NPM configuration if the NPM environment variables for NPM are set
* Configure renovate to authenticate against the specified NPM registry and create a .npmrc file
* that authenticates against the same registry for the specified scope.
*/
function configureNpm() {
if (process.env.RENOVATE_NPM_USERNAME && process.env.RENOVATE_NPM_PASSWORD) {
return {
hostRules: [
{
hostType: "npm",
matchHost: process.env.RENOVATE_NPM_REGISTRY,
username: process.env.RENOVATE_NPM_USERNAME,
password: process.env.RENOVATE_NPM_PASSWORD,
},
],
config: {},
name: "npm",
};
}
if (
process.env.RENOVATE_NPM_AUTH_TOKEN &&
process.env.RENOVATE_NPM_REGISTRY &&
process.env.RENOVATE_NPM_SCOPE
) {
return {
hostRules: [],
name: "npmrc",
config: {
npmrc: [
`${process.env.RENOVATE_NPM_SCOPE}:registry=${process.env.RENOVATE_NPM_REGISTRY}`,
`${process.env.RENOVATE_NPM_REGISTRY}:_auth=${process.env.RENOVATE_NPM_AUTH_TOKEN}`,
`${process.env.RENOVATE_NPM_REGISTRY}:always-auth=true`,
].join("\n"),
},
};
}
}
/**
* Configure renovate to authenticate against the specified Artifactory registry
* if the environment variables are set
*/
function configureArtifactory() {
if (
process.env.RENOVATE_ARTIFACTORY_MATCH_HOST &&
process.env.RENOVATE_ARTIFACTORY_PACKAGE_PREFIXES &&
process.env.RENOVATE_ARTIFACTORY_PASSWORD &&
process.env.RENOVATE_ARTIFACTORY_PASSWORD_PROPERTY_NAME &&
process.env.RENOVATE_ARTIFACTORY_REGISTRY_URLS &&
process.env.RENOVATE_ARTIFACTORY_USERNAME &&
process.env.RENOVATE_ARTIFACTORY_USERNAME_PROPERTY_NAME
) {
return {
hostRules: [
{
hostType: "maven",
matchHost: process.env.RENOVATE_ARTIFACTORY_MATCH_HOST,
username: process.env.RENOVATE_ARTIFACTORY_USERNAME,
password: process.env.RENOVATE_ARTIFACTORY_PASSWORD,
},
],
name: "artifactory",
config: {
secrets: {
ARTIFACTORY_PASSWORD: process.env.RENOVATE_ARTIFACTORY_PASSWORD,
ARTIFACTORY_USERNAME: process.env.RENOVATE_ARTIFACTORY_USERNAME,
},
customEnvVariables: {
[`ORG_GRADLE_PROJECT_${process.env.RENOVATE_ARTIFACTORY_USERNAME_PROPERTY_NAME}`]:
"{{ secrets.ARTIFACTORY_USERNAME }}",
[`ORG_GRADLE_PROJECT_${process.env.RENOVATE_ARTIFACTORY_PASSWORD_PROPERTY_NAME}`]:
"{{ secrets.ARTIFACTORY_PASSWORD }}",
},
packageRules: [
{
matchDatasources: ["maven"],
matchPackagePrefixes:
process.env.RENOVATE_ARTIFACTORY_PACKAGE_PREFIXES.split(","),
registryUrls:
process.env.RENOVATE_ARTIFACTORY_REGISTRY_URLS.split(","),
},
],
},
};
}
}
/**
* Configure renovate to authenticate against the default terraform registry
* if the environment variables are set
*/
function configureTerraform() {
if (process.env.RENOVATE_TERRAFORM_TOKEN) {
return {
hostRules: [
{
hostType: "terraform-module",
token: process.env.RENOVATE_TERRAFORM_TOKEN,
},
{
matchHost: "app.terraform.io",
token: process.env.RENOVATE_TERRAFORM_TOKEN,
},
],
name: "terraform",
config: {},
};
}
}
/**
* Configure renovate to authenticate against docker hub if the environment variables are set
*/
function configureDocker() {
if (
process.env.RENOVATE_DOCKERHUB_USERNAME &&
process.env.RENOVATE_DOCKERHUB_PASSWORD
) {
return {
hostRules: [
{
hostType: "docker",
username: process.env.RENOVATE_DOCKERHUB_USERNAME,
password: process.env.RENOVATE_DOCKERHUB_PASSWORD,
},
],
name: "docker",
config: {},
};
}
}
/**
* Parse the extra configuration from the environment variable. If the environment variable
* is not set or it can't be parsed, return an empty object.
* @returns {{}|any}
*/
function getExtraConfig() {
if (process.env.RENOVATE_EXTRA_CONFIG) {
try {
return JSON.parse(process.env.RENOVATE_EXTRA_CONFIG);
} catch (e) {
console.error(
`Failed to parse RENOVATE_EXTRA_CONFIG environment variable: ${e.message}`,
);
}
}
return {};
}
// Only keep provider configuration that is set
const providers = [
configureArtifactory(),
configureNpm(),
configureDocker(),
configureTerraform(),
].filter((provider) => provider !== undefined);
console.log(
`Enabled providers: [${providers.map(({ name }) => name).join(", ")}]`,
);
module.exports = {
branchPrefix: "c/renovate_",
// Merge host rule for all the providers
hostRules: providers.flatMap((provider) => provider.hostRules),
onboarding: false,
// Only run renovate against the repository the action is running on
repositories: [`${process.env.RENOVATE_REPOSITORY_NAME}`],
// Add any extra configuration a provider may need
...providers.reduce(
(rules, provider) => ({
...rules,
...provider.config,
packageRules: (rules.packageRules || []).concat(
...(provider.config.packageRules || []),
),
}),
{},
),
...getExtraConfig(),
};