Skip to content

feat: release metadata #457

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

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions cmds/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ module.exports = {
type: 'string',
default: ''
},
metadata: {
describe: 'SemVer metadata to be appended to released version',
type: 'string',
default: ''
},
type: {
describe: 'The type of version bump for this release',
type: 'string',
Expand Down
6 changes: 6 additions & 0 deletions src/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const docs = require('../docs')

const releaseChecks = require('./prerelease')
const bump = require('./bump')
const metadata = require('./metadata')
const changelog = require('./changelog')
const commit = require('./commit')
const tag = require('./tag')
Expand All @@ -35,6 +36,11 @@ function release (opts) {
task: bump,
enabled: (ctx) => ctx.bump
},
{
title: 'Metadata',
task: metadata,
enabled: (ctx) => ctx.metadata
},
{
title: 'Build',
task: (ctx) => build(ctx),
Expand Down
22 changes: 22 additions & 0 deletions src/release/metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const fs = require('fs-extra')

const getPathToPkg = require('../utils').getPathToPkg

function metadata (ctx, task) {
const { metadata } = ctx

return fs.readJson(getPathToPkg())
.then((pkg) => {
const version = pkg.version
const newVersion = `${version}+${metadata}`

task.title += `: v${version} -> v${newVersion}`

pkg.version = newVersion
return fs.writeJson(getPathToPkg(), pkg, { spaces: 2 })
})
}

module.exports = metadata
14 changes: 12 additions & 2 deletions src/release/prerelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function validGh (opts) {

if (!opts.ghtoken) {
return Promise.reject(new Error('Missing GitHub access token. ' +
'Have you set `AEGIR_GHTOKEN`?'))
'Have you set `AEGIR_GHTOKEN`?'))
}
return Promise.resolve()
}
Expand All @@ -24,13 +24,23 @@ async function isDirty () {
}
}

function isMetadataValid (opts) {
if (opts.metadata && !opts.metadata.match(/^[0-9A-Za-z-]+$/)) {
return Promise.reject(new Error('The metadata has to consists only of alphanumeric characters and hypen!'))
}

return Promise.resolve()
}

// Validate that all requirements are met before starting the release
// - No dirty git
// - github token for github release, if github release is enabled
// - Metadata is valid string
function prerelease (opts) {
return Promise.all([
isDirty(),
validGh(opts)
validGh(opts),
isMetadataValid(opts)
])
}

Expand Down