-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): allow templated build arguments
allows docker build arguents to be treated as a string template
- Loading branch information
1 parent
e157d3f
commit 7167dcf
Showing
22 changed files
with
343 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,5 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
*.vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
const semver = require('semver') | ||
|
||
module.exports = buildTemplateVars | ||
|
||
function buildTemplateVars(context, opts) { | ||
const {nextRelease = {}, lastRelease = {}} = context | ||
|
||
const versions = { | ||
next: semver.parse(nextRelease.version) || {} | ||
, previous: semver.parse(lastRelease.version) || {} | ||
} | ||
|
||
const {tags: _, ...rest} = opts | ||
return { | ||
...versions.next | ||
, ...versions | ||
, ...nextRelease | ||
, ...rest | ||
, git_tag: nextRelease.gitTag | ||
, git_sha: nextRelease.gitHead | ||
, release_type: nextRelease.type | ||
, release_notes: nextRelease.notes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
'use strict' | ||
|
||
/* istanbul ignore file */ | ||
module.exports = { | ||
branches: [ | ||
'master' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
|
||
module.exports = add | ||
|
||
async function add(cwd, file = '.') { | ||
await execa('git', ['add', file], {cwd: cwd}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
const head = require('./head.js') | ||
|
||
module.exports = commit | ||
|
||
async function commit(cwd, message) { | ||
await execa('git', ['commit', '-m', message], {cwd: cwd}) | ||
return head(cwd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
|
||
module.exports = head | ||
|
||
async function head(cwd) { | ||
const {stdout} = await execa('git', ['rev-parse', 'HEAD'], {cwd: cwd}) | ||
return stdout | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
add: require('./add.js') | ||
, commit: require('./commit.js') | ||
, head: require('./head.js') | ||
, initOrigin: require('./init-origin.js') | ||
, initRemote: require('./init-remote.js') | ||
, init: require('./init.js') | ||
, push: require('./push.js') | ||
, tag: require('./tag.js') | ||
, tags: require('./tags.js') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
const initRemote = require('./init-remote.js') | ||
|
||
module.exports = initOrigin | ||
|
||
async function initOrigin(cwd) { | ||
const origin = await initRemote() | ||
await execa('git', ['remote', 'add', 'origin', origin], {cwd: cwd}) | ||
await execa('git', ['push', '--all', 'origin'], {cwd: cwd}) | ||
return origin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const os = require('os') | ||
const {promises: fs} = require('fs') | ||
const execa = require('execa') | ||
|
||
module.exports = initRemote | ||
|
||
async function initRemote(branch = 'main') { | ||
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), path.sep)) | ||
await execa('git', [ | ||
'init', '--bare', `--initial-branch=${branch}` | ||
], {cwd: cwd}) | ||
return `file://${cwd}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const os = require('os') | ||
const {promises: fs} = require('fs') | ||
const execa = require('execa') | ||
|
||
module.exports = init | ||
|
||
async function init(dir, branch = 'main') { | ||
const cwd = dir || await fs.mkdtemp(path.join(os.tmpdir(), path.sep)) | ||
await execa('git', ['init'], {cwd: cwd}) | ||
await execa('git', ['checkout', '-b', branch], {cwd: cwd}) | ||
await execa('git', ['config', '--add', 'commit.gpgsign', false]) | ||
await execa('git', ['config', '--add', 'pull.default', 'current']) | ||
await execa('git', ['config', '--add', 'push.default', 'current']) | ||
return cwd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
|
||
module.exports = push | ||
|
||
async function push(cwd, remote = 'origin', branch = 'main') { | ||
await execa('git', ['push', '--tags', remote, `HEAD:${branch}`], {cwd: cwd}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
|
||
module.exports = tag | ||
|
||
async function tag(cwd, name, hash) { | ||
const args = hash | ||
? ['tag', '-f', name, hash] | ||
: ['tag', name] | ||
|
||
await execa('git', args, {cwd: cwd}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
const os = require('os') | ||
const execa = require('execa') | ||
|
||
module.exports = tags | ||
|
||
async function tags(cwd, hash) { | ||
const cmd = hash | ||
? ['describe', '--tags', '--exact-match', hash] | ||
: ['tag', '-l', '--sort', 'v:refname'] | ||
const {stdout} = await execa('git', cmd, {cwd: cwd}) | ||
return stdout.split(os.EOL).filter(Boolean) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use strict' | ||
|
||
const execa = require('execa') | ||
const {test, threw} = require('tap') | ||
const git = require('../common/git/index.js') | ||
|
||
const stringify = JSON.stringify | ||
|
||
test('docker release', async (t) => { | ||
const cwd = t.testdir({ | ||
'package.json': stringify({ | ||
name: 'service-meta-package' | ||
, version: '0.0.0-development' | ||
, scripts: { | ||
'test-release': 'semantic-release' | ||
} | ||
, release: { | ||
ci: true | ||
, npmPublish: false | ||
, branches: ['main'] | ||
, docker: { | ||
registry: 'localhost:5000' | ||
, project: 'docker-release' | ||
, image: 'fake' | ||
, args: { | ||
SAMPLE_THING: '{type}.{version}' | ||
, GIT_REF: '{git_sha}-{git_tag}' | ||
} | ||
} | ||
, plugins: [ | ||
'@semantic-release/commit-analyzer' | ||
, '@semantic-release/release-notes-generator' | ||
, '@semantic-release/npm' | ||
, '@codedependant/semantic-release-docker' | ||
] | ||
} | ||
, devDependencies: { | ||
'semantic-release': '*' | ||
, '@semantic-release/commit-analyzer': '*' | ||
, '@semantic-release/release-notes-generator': '*' | ||
, '@semantic-release/npm': '*' | ||
, '@codedependant/semantic-release-docker': 'file:../../../' | ||
} | ||
}) | ||
, Dockerfile: 'FROM debian:buster-slim\n\nRUN ls -alh' | ||
, '.gitignore': 'node_modules/' | ||
}) | ||
|
||
await git.init(cwd) | ||
await git.add(cwd) | ||
await git.commit(cwd, 'feat: initial release') | ||
|
||
const origin = await git.initOrigin(cwd) | ||
t.comment(`repository: ${cwd}`) | ||
t.comment(`origin: ${origin}`) | ||
|
||
{ | ||
const stream = execa('npm', [ | ||
'install' | ||
], { | ||
cwd: cwd | ||
, extendEnv: false | ||
, env: { | ||
BRANCH_NAME: 'main' | ||
, CI_BRANCH: 'main' | ||
, CI: 'true' | ||
, GITHUB_REF: 'refs/heads/main' | ||
, PWD: cwd | ||
, DEBUG: process.env.DEBUG | ||
, PATH: process.env.PATH | ||
, HOME: process.env.HOME | ||
, USER: process.env.USER | ||
} | ||
}) | ||
|
||
stream.stdout.pipe(process.stdout) | ||
await stream | ||
} | ||
|
||
const stream = execa('npm', [ | ||
'run' | ||
, 'test-release' | ||
, `--repositoryUrl=${origin}`], { | ||
cwd: cwd | ||
, extendEnv: false | ||
, env: { | ||
BRANCH_NAME: 'main' | ||
, CI_BRANCH: 'main' | ||
, CI: 'true' | ||
, GITHUB_REF: 'refs/heads/main' | ||
, PWD: cwd | ||
, DEBUG: process.env.DEBUG | ||
, PATH: process.env.PATH | ||
, HOME: process.env.HOME | ||
, USER: process.env.USER | ||
} | ||
}) | ||
await stream | ||
|
||
}).catch(threw) |
Oops, something went wrong.