- Remove the `getLastRelease` plugin type - Retrieve the last release based on Git tags - Create the next release Git tag before calling the `publish` plugins BREAKING CHANGE: Remove the `getLastRelease` plugin type The `getLastRelease` plugins will not be called anymore. BREAKING CHANGE: Git repository authentication is now mandatory The Git authentication is now mandatory and must be set via `GH_TOKEN`, `GITHUB_TOKEN`, `GL_TOKEN`, `GITLAB_TOKEN` or `GIT_CREDENTIALS` as described in [CI configuration](https://github.com/semantic-release/semantic-release/blob/caribou/docs/usage/ci-configuration.md#authentication).
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
import Docker from 'dockerode';
|
|
import getStream from 'get-stream';
|
|
import pRetry from 'p-retry';
|
|
import {initBareRepo, gitShallowClone} from './git-utils';
|
|
|
|
const IMAGE = 'pvdlg/docker-gitbox';
|
|
const SERVER_PORT = 80;
|
|
const HOST_PORT = 2080;
|
|
const SERVER_HOST = 'localhost';
|
|
const GIT_USERNAME = 'integration';
|
|
const GIT_PASSWORD = 'suchsecure';
|
|
const docker = new Docker();
|
|
let container;
|
|
|
|
const gitCredential = `${GIT_USERNAME}:${GIT_PASSWORD}`;
|
|
|
|
/**
|
|
* Download the `gitbox` Docker image, create a new container and start it.
|
|
*
|
|
* @return {Promise} Promise that resolves when the container is started.
|
|
*/
|
|
async function start() {
|
|
await getStream(await docker.pull(IMAGE));
|
|
|
|
container = await docker.createContainer({
|
|
Tty: true,
|
|
Image: IMAGE,
|
|
PortBindings: {[`${SERVER_PORT}/tcp`]: [{HostPort: `${HOST_PORT}`}]},
|
|
});
|
|
await container.start();
|
|
|
|
const exec = await container.exec({
|
|
Cmd: ['ng-auth', '-u', GIT_USERNAME, '-p', GIT_PASSWORD],
|
|
AttachStdout: true,
|
|
AttachStderr: true,
|
|
});
|
|
await exec.start();
|
|
}
|
|
|
|
/**
|
|
* Stop and remote the `mockserver` Docker container.
|
|
*
|
|
* @return {Promise} Promise that resolves when the container is stopped.
|
|
*/
|
|
async function stop() {
|
|
await container.stop();
|
|
await container.remove();
|
|
}
|
|
|
|
/**
|
|
* Initialize a remote repository and creates a shallow clone.
|
|
*
|
|
* @param {String} name The remote repository name.
|
|
* @param {String} [branch='master'] The branch to initialize.
|
|
* @param {String} [description=`Repository ${name}`] The repository description.
|
|
* @return {Object} The `repositoryUrl` (URL without auth) and `authUrl` (URL with auth).
|
|
*/
|
|
async function createRepo(name, branch = 'master', description = `Repository ${name}`) {
|
|
const exec = await container.exec({
|
|
Cmd: ['repo-admin', '-n', name, '-d', description],
|
|
AttachStdout: true,
|
|
AttachStderr: true,
|
|
});
|
|
await exec.start();
|
|
|
|
const repositoryUrl = `http://${SERVER_HOST}:${HOST_PORT}/git/${name}.git`;
|
|
const authUrl = `http://${gitCredential}@${SERVER_HOST}:${HOST_PORT}/git/${name}.git`;
|
|
|
|
// Retry as the server might take a few ms to make the repo available push
|
|
await pRetry(() => initBareRepo(authUrl, branch), {retries: 3, minTimeout: 500, factor: 2});
|
|
await gitShallowClone(authUrl);
|
|
return {repositoryUrl, authUrl};
|
|
}
|
|
|
|
export default {start, stop, gitCredential, createRepo};
|