generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
101 lines (80 loc) · 3 KB
/
main.ts
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
import './setupEnvToOverrideDefaultRenovateLogger'
import './setupLogger'
import * as core from '@actions/core'
import {getOctokit} from '@actions/github'
import {extractAllDependencies} from 'renovate/dist/workers/repository/extract'
import {fetchUpdates} from 'renovate/dist/workers/repository/process/fetch'
import {fetchChangelogs} from './fetchChangelogs'
import {commentTitle, getPrCommentBody} from './getPrCommentBody'
import {getRenovateConfig} from './getRenovateConfig'
import {getUpdatedDependencies} from './getUpdatedDependencies'
import {ensurePrCommentRemoved, upsertPrComment} from './updatePrComment'
import {getRunContext} from './getRunContext'
async function run(): Promise<void> {
try {
const {baseRef, headRef, pullRequestNumber, repo} = getRunContext()
const token = core.getInput('token')
core.info(`Configuring renovate`)
const {config, git} = await getRenovateConfig({...repo, token})
core.info(`Fetching ${headRef} from origin`)
await git.fetch(['origin', '--depth=2', headRef])
if (typeof pullRequestNumber === 'number') {
core.info(
`Not fetching baseRef ${baseRef} for PRs because the first parent will be used`
)
} else {
core.info(`Fetching ${baseRef} from origin`)
await git.fetch(['origin', '--depth=1', baseRef])
}
core.info(`Checking out PR base sha ${baseRef}`)
await git.checkout(baseRef)
core.info(`Looking for all dependencies in base`)
const baseDependencies = await extractAllDependencies(config)
core.info(`Fetching possible updates for all base ref dependencies`)
await fetchUpdates(config, baseDependencies)
core.info(`Checking out PR head sha ${headRef}`)
await git.checkout(headRef)
core.info(`Looking for all dependencies in head`)
const headDependencies = await extractAllDependencies(config)
let updatedDependencies = [
...getUpdatedDependencies(baseDependencies, headDependencies)
]
const github = getOctokit(token)
if (updatedDependencies.length > 0) {
core.info(`Found ${updatedDependencies.length} updated dependencies`)
} else {
core.info(`No updated dependencies, exiting`)
if (typeof pullRequestNumber === 'number') {
await ensurePrCommentRemoved(
github,
repo,
pullRequestNumber,
commentTitle
)
return
}
return
}
const changelogs = core.getInput('changelogs') === 'true'
if (typeof pullRequestNumber !== 'number') {
return
}
if (changelogs) {
core.info(`Fetching changelogs...`)
updatedDependencies = await fetchChangelogs(config, updatedDependencies)
}
const commentBody = getPrCommentBody(updatedDependencies)
await upsertPrComment(
github,
repo,
pullRequestNumber,
commentTitle,
commentBody
)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
core.info(`Error stack: ${error.stack}`)
core.setFailed(error.message)
}
}
run()