-
Notifications
You must be signed in to change notification settings - Fork 35
/
migrate.js
54 lines (46 loc) · 1.64 KB
/
migrate.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
'use strict'
const yaml = require('js-yaml')
const fs = require('fs')
module.exports = function factory(args, logger) {
// DO WHAT YOU WANT IN SYNC
// This function will be called for each REPO you are processing
return {
onRepo(repo) {
logger(`Processing ${repo}`)
},
async onFile(file) {
if (file.includes('.github/workflows')) {
logger(`Processing ${file}`)
const fileContent = fs.readFileSync(file, 'utf8')
const oldModuleVersion = 'fastify/github-action-merge-dependabot@v2'
if (!fileContent.includes(oldModuleVersion)) {
return
}
const doc = yaml.load(fileContent);
const jobs = Object.keys(doc.jobs)
for (const jobName of jobs) {
logger(`Checking ${jobName}`)
const job = doc.jobs[jobName]
const automergeStep = job.steps.find(step => step.uses && step.uses.startsWith(oldModuleVersion))
if (automergeStep !== undefined) {
logger(`\tUpgrading job: ${jobName}`)
if (!job.permissions) {
const steps = job.steps
delete job.steps // doing this to order the yml output
job.permissions = {}
job.steps = steps
}
automergeStep.uses = 'fastify/github-action-merge-dependabot@v3.0.0'
job.permissions['pull-requests'] = 'write'
job.permissions['contents'] = 'write'
}
}
const fileYml = yaml.dump(doc);
fs.writeFileSync(file, fileYml, 'utf8');
}
},
// onComplete (repo) {
// OPTIONAL, sync function called after all the processed files
// }
}
}