Skip to content

Enable versioning via Flowzone and versionist #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/flowzone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
with:
disable_versioning: true
toggle_auto_merge: false
token_retrieval_mode: user
docker_images: |
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

# Ignore auto-generated files
exclude: ^(.versionbot/|CHANGELOG.md|VERSION)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
Expand Down
Empty file added .versionbot/CHANGELOG.yml
Empty file.
1 change: 1 addition & 0 deletions repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type: docker
100 changes: 100 additions & 0 deletions versionist.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
'use strict';

const execSync = require('child_process').execSync;
const fs = require('fs')
const path = require('path')
const os = require('os')

const getAuthor = (commitHash) => {
return execSync(`git show --quiet --format="%an" ${commitHash}`, {
encoding: 'utf8'
}).replace('\n', '');
};

// Install balena-semver to a temporary directory
const install_semver = async () => {
const tmpDir = path.join(os.tmpdir(), 'versionist')
fs.mkdirSync(tmpDir, { recursive: true })

return execSync(`npm install balena-semver@^3.0.2 --prefix "${tmpDir}"`, {
encoding: 'utf8'
}).replace('\n', '')
}

const getRev = async (documentedVersions, history, callback) => {
await install_semver()
const semver = require(path.join(os.tmpdir(), 'versionist/node_modules/balena-semver'))

const latestDocumented = documentedVersions.sort(semver.compare).pop().trim()
if (!latestDocumented) {
return callback(new Error('Could not determine version from documentedVersions'))
}
console.log(`latestDocumented: ${latestDocumented}`)

// Extract ARG DNSCRYPT_PROXY_VERSION from Dockerfile
const dockerfile = fs.readFileSync('Dockerfile', 'utf8')
const argVersion = dockerfile.match(/ARG DNSCRYPT_PROXY_VERSION=(\d+\.\d+\.\d+)/)[1]

if (!argVersion) {
return callback(new Error('Could not determine version from Dockerfile'))
}

console.log(`argVersion: ${argVersion}`)

const latestDocumentedRevision = latestDocumented.includes('rev')? latestDocumented : `${semver.parse(latestDocumented).version}+rev0`

// semver.gt will ignore the revision numbers but still compare the version
// If argVersion <= latestDocumented then the latestDocumented version is a revision of the current argVersion
const latestVersion = semver.gt(argVersion, latestDocumentedRevision) ? `${argVersion}+rev0` : latestDocumentedRevision

console.log(`latestVersion: ${latestVersion}`)
return callback(null, latestVersion)
}

module.exports = {
editChangelog: true,
parseFooterTags: true,
updateVersion: (cwd, ver, cb) => cb(),

addEntryToChangelog: {
preset: 'prepend',
fromLine: 6
},

getChangelogDocumentedVersions: {
preset: 'changelog-headers',
clean: /^v/
},

includeCommitWhen: (commit) => { return true; },
getIncrementLevelFromCommit: (commit) => {
return 'patch'
},
incrementVersion: (currentVersion, incrementLevel) => {
const semver = require(path.join(os.tmpdir(), 'versionist/node_modules/balena-semver'))

const parsedCurrentVersion = semver.parse(currentVersion)
console.log(`parsedCurrentVersion: ${JSON.stringify(parsedCurrentVersion)}`)
if (parsedCurrentVersion.build != null && parsedCurrentVersion.build.length > 0) {
let revision = Number(String(parsedCurrentVersion.build).split('rev').pop())
console.log(`revision: ${revision}`)
if (!Number.isFinite(revision)) {
throw new Error(`Could not extract revision number from ${currentVersion}`)
}
return `${parsedCurrentVersion.version}+rev${revision + 1}`
}
return `${parsedCurrentVersion.version}`
},

getCurrentBaseVersion: getRev,
// If a 'changelog-entry' tag is found, use this as the subject rather than the
// first line of the commit.
transformTemplateData: (data) => {
data.commits.forEach((commit) => {
commit.subject = commit.footer['changelog-entry'] || commit.subject;
commit.author = getAuthor(commit.hash);
});

return data;
}
}
Loading