forked from patrickjahns/version-drafter-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (52 loc) · 1.78 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
const { getConfig } = require('./lib/config')
const log = require('release-drafter-github-app/lib/log')
const core = require('@actions/core')
const { findReleases } = require('release-drafter-github-app/lib/releases')
const {
findCommitsWithAssociatedPullRequests
} = require('release-drafter-github-app/lib/commits')
const { incrementVersion } = require('./lib/version')
module.exports = app => {
app.on('push', async context => {
log({ app, context, message: 'init' })
let config = await getConfig({
app,
context,
configName: core.getInput('config-name')
})
if (config === null) return
// TODO: allow to override major/minor/next labels via input vars
// GitHub Actions merge payloads slightly differ, in that their ref points
// to the PR branch instead of refs/heads/master
const ref = process.env['GITHUB_REF'] || context.payload.ref
const branch = ref.replace(/^refs\/heads\//, '')
// get latest release information
let { lastRelease: lastRelease } = await findReleases({ app, context })
if (lastRelease == undefined) {
log({
app,
context,
message: 'last releases was not found, assuming 0.0.0 as tag'
})
lastRelease = { tag_name: '0.0.0' }
}
// fetch upcoming pull requests
const {
pullRequests: mergedPullRequests
} = await findCommitsWithAssociatedPullRequests({
app,
context,
branch,
lastRelease
})
// calculate new version based on template
const nextVersion = incrementVersion(
lastRelease,
mergedPullRequests,
config
)
log({ app, context, message: 'calculated next version: ' + nextVersion })
core.setOutput('current-version', lastRelease.tag_name)
core.setOutput('next-version', nextVersion)
})
}