Skip to content

Commit 28a4133

Browse files
committed
feat(gitlab-registry): added minor major and channel tags
1 parent 917fc09 commit 28a4133

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
[![npm version](https://img.shields.io/npm/v/semantic-release-gitlab-registry.svg)](https://www.npmjs.com/package/semantic-release-gitlab-registry)
44
[![npm downloads](https://img.shields.io/npm/dm/semantic-release-gitlab-registry.svg)](https://www.npmjs.com/package/semantic-release-gitlab-registry)
55
[![Build Status](https://travis-ci.org/lgaticaq/semantic-release-gitlab-registry.svg?branch=master)](https://travis-ci.org/lgaticaq/semantic-release-gitlab-registry)
6-
[![dependencies Status](https://img.shields.io/david/lgaticaq/semantic-release-gitlab-registry/status.svg)](https://david-dm.org/lgaticaq/semantic-release-gitlab-registry)
7-
[![devDependencies Status](https://img.shields.io/david/lgaticaq/semantic-release-gitlab-registry/dev-status.svg)](https://david-dm.org/lgaticaq/semantic-release-gitlab-registry?type=dev)
8-
[![peerDependencies Status](https://img.shields.io/david/lgaticaq/semantic-release-gitlab-registry/peer-status.svg)](https://david-dm.org/lgaticaq/semantic-release-gitlab-registry?type=peer)
96
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
107

118
Set of [semantic-release](https://github.com/semantic-release/semantic-release) plugins for publishing a docker image to [GitLab Container Registry](https://docs.gitlab.com/ce/user/project/container_registry.html).

lib/publish.js

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,66 @@
11
const execa = require('execa')
2+
const semver = require('semver')
23

34
/**
45
* @typedef {import('./index').Context} Context
56
*/
67
/**
7-
* Push new docker image.
8+
* Tag and push new docker images with semantic versioning.
89
*
910
* @param {Object} pluginConfig - The plugin configuration.
1011
* @param {Context} context - The semantic-release context.
1112
* @returns {Promise} A `Promise` that resolve to docker push command.
1213
*/
1314
module.exports = async (pluginConfig, { nextRelease: { version }, logger }) => {
14-
try {
15+
/**
16+
* Tag and push docker image by version.
17+
*
18+
* @param {string} version - Tag version.
19+
* @returns {Promise} A `Promise` that resolve to docker push command.
20+
*/
21+
async function publish (version) {
1522
logger.log(
1623
`Pushing version ${
1724
process.env.CI_REGISTRY_IMAGE
1825
}:${version} to GitLab Container Registry`
1926
)
20-
21-
// Push both new version and latest
27+
// tag image
2228
await execa(
2329
'docker',
24-
[
25-
'tag',
26-
`${process.env.CI_REGISTRY_IMAGE}:latest`,
27-
`${process.env.CI_REGISTRY_IMAGE}:${version}`
28-
],
30+
['tag', `${process.env.CI_REGISTRY_IMAGE}:${version}`],
2931
{
3032
stdio: 'inherit'
3133
}
3234
)
35+
// push image
3336
await execa(
3437
'docker',
3538
['push', `${process.env.CI_REGISTRY_IMAGE}:${version}`],
3639
{ stdio: 'inherit' }
3740
)
38-
await execa('docker', ['push', `${process.env.CI_REGISTRY_IMAGE}:latest`], {
39-
stdio: 'inherit'
40-
})
41+
}
42+
43+
try {
44+
// parse version to parts
45+
const { major, minor, patch, prerelease } = semver(version)
46+
const isProdRelease = prerelease.length === 0
47+
48+
// first release version as it is
49+
await publish(version)
50+
51+
if (isProdRelease) {
52+
// on production release X:latest, X:1.1, X:1
53+
await publish(`${major}.${minor}`)
54+
await publish(`${major}`)
55+
await publish('latest')
56+
return
57+
}
58+
59+
const [channel] = prerelease
60+
61+
// on other channels release X:channel, X:1.1.1-channel
62+
await publish(channel)
63+
await publish(`${major}.${minor}.${patch}-${channel}`)
4164
} catch (err) {
4265
throw new Error('docker push failed')
4366
}

0 commit comments

Comments
 (0)