Skip to content

Commit 860e2c8

Browse files
committed
Add versionist.conf.js
Signed-off-by: Kyle Harding <[email protected]>
1 parent f956f8c commit 860e2c8

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

repo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type: docker

versionist.conf.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
'use strict';
2+
3+
const execSync = require('child_process').execSync;
4+
const fs = require('fs')
5+
const path = require('path')
6+
const os = require('os')
7+
8+
const getAuthor = (commitHash) => {
9+
return execSync(`git show --quiet --format="%an" ${commitHash}`, {
10+
encoding: 'utf8'
11+
}).replace('\n', '');
12+
};
13+
14+
// Install balena-semver to a temporary directory
15+
const install_semver = async () => {
16+
const tmpDir = path.join(os.tmpdir(), 'versionist')
17+
fs.mkdirSync(tmpDir, { recursive: true })
18+
19+
return execSync(`npm install balena-semver@^3.0.2 --prefix "${tmpDir}"`, {
20+
encoding: 'utf8'
21+
}).replace('\n', '')
22+
}
23+
24+
const getRev = async (documentedVersions, history, callback) => {
25+
await install_semver()
26+
const semver = require(path.join(os.tmpdir(), 'versionist/node_modules/balena-semver'))
27+
28+
const latestDocumented = documentedVersions.sort(semver.compare).pop().trim()
29+
if (!latestDocumented) {
30+
return callback(new Error('Could not determine version from documentedVersions'))
31+
}
32+
console.log(`latestDocumented: ${latestDocumented}`)
33+
34+
// Extract ARG DNSCRYPT_PROXY_VERSION from Dockerfile
35+
const dockerfile = fs.readFileSync('Dockerfile', 'utf8')
36+
const argVersion = dockerfile.match(/ARG DNSCRYPT_PROXY_VERSION=(\d+\.\d+\.\d+)/)[1]
37+
38+
if (!argVersion) {
39+
return callback(new Error('Could not determine version from Dockerfile'))
40+
}
41+
42+
console.log(`argVersion: ${argVersion}`)
43+
44+
const latestDocumentedRevision = latestDocumented.includes('rev')? latestDocumented : `${semver.parse(latestDocumented).version}+rev0`
45+
46+
// semver.gt will ignore the revision numbers but still compare the version
47+
// If argVersion <= latestDocumented then the latestDocumented version is a revision of the current argVersion
48+
const latestVersion = semver.gt(argVersion, latestDocumentedRevision) ? `${argVersion}+rev0` : latestDocumentedRevision
49+
50+
console.log(`latestVersion: ${latestVersion}`)
51+
return callback(null, latestVersion)
52+
}
53+
54+
module.exports = {
55+
editChangelog: true,
56+
parseFooterTags: true,
57+
updateVersion: (cwd, ver, cb) => cb(),
58+
59+
addEntryToChangelog: {
60+
preset: 'prepend',
61+
fromLine: 6
62+
},
63+
64+
getChangelogDocumentedVersions: {
65+
preset: 'changelog-headers',
66+
clean: /^v/
67+
},
68+
69+
includeCommitWhen: (commit) => { return true; },
70+
getIncrementLevelFromCommit: (commit) => {
71+
return 'patch'
72+
},
73+
incrementVersion: (currentVersion, incrementLevel) => {
74+
const semver = require(path.join(os.tmpdir(), 'versionist/node_modules/balena-semver'))
75+
76+
const parsedCurrentVersion = semver.parse(currentVersion)
77+
console.log(`parsedCurrentVersion: ${JSON.stringify(parsedCurrentVersion)}`)
78+
if (parsedCurrentVersion.build != null && parsedCurrentVersion.build.length > 0) {
79+
let revision = Number(String(parsedCurrentVersion.build).split('rev').pop())
80+
console.log(`revision: ${revision}`)
81+
if (!Number.isFinite(revision)) {
82+
throw new Error(`Could not extract revision number from ${currentVersion}`)
83+
}
84+
return `${parsedCurrentVersion.version}+rev${revision + 1}`
85+
}
86+
return `${parsedCurrentVersion.version}`
87+
},
88+
89+
getCurrentBaseVersion: getRev,
90+
// If a 'changelog-entry' tag is found, use this as the subject rather than the
91+
// first line of the commit.
92+
transformTemplateData: (data) => {
93+
data.commits.forEach((commit) => {
94+
commit.subject = commit.footer['changelog-entry'] || commit.subject;
95+
commit.author = getAuthor(commit.hash);
96+
});
97+
98+
return data;
99+
}
100+
}

0 commit comments

Comments
 (0)