From 60a3236ff25ea4ebd43dc293811e9ef809bc0dbd Mon Sep 17 00:00:00 2001 From: Paul Varache Date: Fri, 10 Aug 2018 15:44:08 +0100 Subject: [PATCH 1/2] Add namePattern option --- lib/data.js | 19 ++++++++++++++++++- lib/deploy-methods/s3-copy.js | 23 +++++++++++------------ test/release-test.js | 13 +++++++++++++ test/test-util.js | 7 +++++++ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/lib/data.js b/lib/data.js index 2f1e044..e0c2508 100644 --- a/lib/data.js +++ b/lib/data.js @@ -87,6 +87,7 @@ class Release extends Build { constructor(opts) { super(opts); this.releaseDate = new Date(opts.releaseDate); + this.namePattern = opts.namePattern || ':project_:version-:number_:arch.:ext'; } toJSON() { @@ -100,10 +101,26 @@ class Release extends Build { metadata: this.metadata }); } - updateReleaseDate () { this.releaseDate = new Date(); } + get path() { + return `${this.project}/${this.channel}/` + + `${Release.generateName(this.namePattern, this)}`; + } + static generateName(pattern, build) { + const keys = [ + 'project', + 'channel', + 'version', + 'number', + 'arch', + 'ext', + ]; + return keys.reduce((acc, key) => { + return acc.replace(new RegExp(`:${key}`, 'g'), build[key]); + }, pattern); + } } module.exports = { diff --git a/lib/deploy-methods/s3-copy.js b/lib/deploy-methods/s3-copy.js index 5b0ca68..0dba871 100644 --- a/lib/deploy-methods/s3-copy.js +++ b/lib/deploy-methods/s3-copy.js @@ -9,16 +9,15 @@ function _updateProgress(reporter, message) { } } -function _doRelease(build, track, reporter) { +function _doRelease(build, track, namePattern, reporter) { // Copy the original build and change the channel to the target one - const targetBuild = Build.fromListEntry({ Key: build.path, LastModified: build.buildDate }); - targetBuild.channel = track; + const release = new Release(Object.assign({}, build, { namePattern, channel: track })); // Copt the s3 object to the new location return (new Promise((resolve, reject) => { s3.getInstance().copyObject({ Bucket: config.local.rootBucket.name, CopySource: `${config.local.rootBucket.name}/${build.path}`, - Key: targetBuild.path, + Key: release.path, }, (err, res) => { if (err) { return reject(err); @@ -28,7 +27,6 @@ function _doRelease(build, track, reporter) { })) .then(() => { _updateProgress(reporter, 'File moved to release channel') - const release = new Release(build); release.updateReleaseDate(); return release; }); @@ -110,20 +108,21 @@ function _downloadKartFile(project, channel) { * * overwrite: Writes all the files into the bucked without clearing it out first. * * sync: Uses the `aws sync` command to minimise bandwith usage. * - * @param {Object} build The build object to be released. - * @param {Object} opts Options. - * @param {String} opts.track Target track. - * @param {String} opts.reporter An optional event listener to report events. + * @param {Object} build The build object to be released. + * @param {Object} opts Options. + * @param {String} opts.track Target track. + * @param {String} opts.namePattern A pattern for the naming of the released file. + * @param {String} opts.reporter An optional event listener to report events. */ function release(build, opts) { if (!opts.track) { throw new Error('No track specified'); } - const { track, reporter } = opts; + const { track, reporter, namePattern } = opts; - return _doRelease(build, track, reporter) + return _doRelease(build, track, namePattern, reporter) .then((r) => { - return _uploadKartFile(r, config.local.rootBucket.name) + return _uploadKartFile(build, config.local.rootBucket.name) .then(() => r); }); } diff --git a/test/release-test.js b/test/release-test.js index e381e71..f6f995c 100644 --- a/test/release-test.js +++ b/test/release-test.js @@ -297,6 +297,19 @@ describe('kart', function () { assert.equal(status.version, release.version, 'Release status does not match'); }); }); + it('rename archive', () => { + let build, release + + return testUtil.generateAndArchiveBuilds([ + { project: 'testing', channel: 'rename', version: '1.2.3', metadata: { revision: '1234567' }, options: { fileCount: 1, subdirs: 0 } }, + ]).then((res) => { + build = res[0]; + return kart.release(build.archive); + }).then((r) => { + release = r; + assert.equal(release.path, 'testing/testing-public/testing-1.2.3.tar.gz'); + }); + }); }); }); }); \ No newline at end of file diff --git a/test/test-util.js b/test/test-util.js index 85ca600..67d3b5e 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -53,6 +53,13 @@ class TestUtil { method: "s3-copy", track: "testing-public", } + }, + rename: { + deploy: { + method: "s3-copy", + track: "testing-public", + namePattern: ":project-:version.:ext" + } } } } From 9a9d6160aca889fed15f134ef5bb818a17c3e540 Mon Sep 17 00:00:00 2001 From: Paul Varache Date: Fri, 10 Aug 2018 15:51:39 +0100 Subject: [PATCH 2/2] Update Readme --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f402db..0b7f2f9 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,34 @@ setting the `algorithm` option to one of the following * **overwrite**: Upload the new build into the bucket without removing everyting first. * **sync**: Use `aws s3 sync` to deploy into the bucket. +### S3 Copy + +```json + { + "method": "s3-copy", + "track": "internal", + "namePattern": ":project_:version-:number_:arch.:ext" + } +``` + +This method copies an archive to a release track. A release track is located in the same directory as an archive. +This method will not download and extract your archive, it will copy the s3 object across + +#### Naming + +Optionally, you can change the naming of the relased file using the namePattern option + +This option will receive the following properties from the archive: +``` +project +channel +version +number +arch +ext +``` +And replace the keys in your name pattern + ## TODO * Additional deploy-methods @@ -219,9 +247,7 @@ setting the `algorithm` option to one of the following * UI for remote configuration management via the kart binary * Adding/removing projects * UI for listing and downloading builds - * Tests using [mock-aws-s3](https://github.com/MathieuLoutre/mock-aws-s3) * Make a Github release when pushing to certain channels - * Add --version flag ## Licence