-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
79 lines (77 loc) · 2.34 KB
/
index.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
const core = require('@actions/core')
const github = require('@actions/github')
const semver = require('semver')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
// load inputs.
const language = core.getInput('language') || 'txt'
const excluding = (core.getInput('excluding') || '').split(/\r?\n/)
// process.
exec('swift package show-dependencies')
.then(x => {
if (x['stderror']) throw new Error(x['stderror'])
else return x['stdout']
})
.then(stdout => (
stdout
.match(/<(.*?)>/g)
.map(x => {
const url = x.match(/^<(.*?)@/)[1]
const version = x.match(/@(.*?)>$/)[1]
const name = url.match(/\/([^\/]*?)\/([^\/]*?)(.git)?$/)
return {
url: url,
installed: semver.clean(version),
owner: name[1],
name: name[2]
}
})
.filter(x => !(excluding.includes(x.name) || excluding.includes('@'+x.author)))
))
.then(deps => (
Promise.all(
deps.map(d => (
exec(`git ls-remote --tags ${d.url}`)
.then(x => {
if (x['stderror']) throw new Error(x['stderror'])
else return x['stdout']
})
.then(tags => (
{
...d,
last: tags
.match(/[0-9]+\.[0-9]+\.[0-9]+/g)
.sort(semver.rcompare)[0]
}
))
))
)
))
.then(x => x.filter(x => semver.gt(x.last, x.installed)))
.then(x => {
core.setOutput('outdated-dependencies', JSON.stringify(x))
// Write message.
switch (language) {
case 'html':
if (x.length === 0) {
core.setOutput(
'message',
`<h3>Dependencies<h3>
<p>No dependencies need updating.</p>`
)
} else {
core.setOutput(
'message',
`<h3>Dependencies<h3>
<p>
<ul>${x.map(d => `<li><a href=${d.url}><strong>${d.author}/${d.name}</strong></a>: ${d.installed} → ${d.last}</li>`).join('')}</ul>
</p>`
)
}
break
default:
if (x.length === 0) { core.setOutput('message', 'No dependencies need updating.') }
else { core.setOutput('message', `${x.map(d => `${d.url} (${d.installed} -> ${d.last})`).join(', ')} need(s) updating.`) }
}
})
.catch(error => core.setFailed(error.message))