Skip to content

Commit

Permalink
[FEATURE] Déployer pix-lcms-minimal en même temps que la production
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Feb 2, 2023
2 parents bd13757 + c34467d commit ddbb09b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
9 changes: 8 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ module.exports = (function () {

PIX_REPO_NAME: 'pix',
PIX_BOT_REPO_NAME: 'pix-bot',
PIX_BOT_APPS: {
production: ['pix-bot-run-production'],
recette: ['pix-bot-build-production'],
},
PIX_LCMS_REPO_NAME: 'pix-editor',
PIX_LCMS_APP_NAME: 'pix-lcms',
PIX_LCMS_APPS: {
production: ['pix-lcms-production'],
recette: ['pix-lcms-minimal-production'],
},
PIX_UI_REPO_NAME: 'pix-ui',
PIX_EMBER_TESTING_LIBRARY_REPO_NAME: 'ember-testing-library',
PIX_DB_STATS_REPO_NAME: 'pix-db-stats',
Expand Down
36 changes: 26 additions & 10 deletions run/services/slack/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const {
PIX_SITE_REPO_NAME,
PIX_SITE_APPS,
PIX_BOT_REPO_NAME,
PIX_BOT_APPS,
PIX_DATAWAREHOUSE_REPO_NAME,
PIX_DATAWAREHOUSE_APPS_NAME,
PIX_LCMS_REPO_NAME,
PIX_LCMS_APP_NAME,
PIX_LCMS_APPS,
PIX_UI_REPO_NAME,
PIX_EMBER_TESTING_LIBRARY_REPO_NAME,
PIX_DB_STATS_REPO_NAME,
Expand Down Expand Up @@ -117,20 +118,25 @@ async function publishAndDeployRelease(repoName, appNamesList = [], releaseType,
}
}

async function publishAndDeployPixBot(repoName, releaseType, responseUrl) {
async function publishAndDeployReleaseWithAppsByEnvironment(repoName, appsByEnv, releaseType, responseUrl) {
if (_isReleaseTypeInvalid(releaseType)) {
releaseType = 'minor';
}
await releasesService.publishPixRepo(repoName, releaseType);
const releaseTag = await githubServices.getLatestReleaseTag(repoName);

const recette = await ScalingoClient.getInstance('recette');
await recette.deployFromArchive('pix-bot-build-production', releaseTag, repoName, { withEnvSuffix: false });
await Promise.all(
Object.keys(appsByEnv).map(async (scalingoEnv) => {
const scalingoInstance = await ScalingoClient.getInstance(scalingoEnv);

const production = await ScalingoClient.getInstance('production');
await production.deployFromArchive('pix-bot-run', releaseTag, repoName);

sendResponse(responseUrl, `Pix Bot deployed (${releaseTag})`);
await Promise.all(
appsByEnv[scalingoEnv].map((scalingoAppName) => {
return scalingoInstance.deployFromArchive(scalingoAppName, releaseTag, repoName, { withEnvSuffix: false });
})
);
})
);
sendResponse(responseUrl, getSuccessMessage(releaseTag, Object.values(appsByEnv).join(', ')));
}

async function getAndDeployLastVersion({ appName }) {
Expand Down Expand Up @@ -193,7 +199,12 @@ module.exports = {
},

async createAndDeployPixLCMS(payload) {
await publishAndDeployRelease(PIX_LCMS_REPO_NAME, [PIX_LCMS_APP_NAME], payload.text, payload.response_url);
await publishAndDeployReleaseWithAppsByEnvironment(
PIX_LCMS_REPO_NAME,
PIX_LCMS_APPS,
payload.text,
payload.response_url
);
},

async createAndDeployPixUI(payload) {
Expand All @@ -218,7 +229,12 @@ module.exports = {
},

async createAndDeployPixBotRelease(payload) {
await publishAndDeployPixBot(PIX_BOT_REPO_NAME, payload.text, payload.response_url);
await publishAndDeployReleaseWithAppsByEnvironment(
PIX_BOT_REPO_NAME,
PIX_BOT_APPS,
payload.text,
payload.response_url
);
},

async getAndDeployLastVersion({ appName }) {
Expand Down
15 changes: 12 additions & 3 deletions test/unit/run/services/slack/commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ describe('Services | Slack | Commands', () => {
});

describe('#createAndDeployPixLCMS', () => {
let client;

beforeEach(async function () {
// given
client = { deployFromArchive: sinon.spy() };
sinon.stub(ScalingoClient, 'getInstance').resolves(client);
const payload = { text: 'minor' };
// when
await createAndDeployPixLCMS(payload);
Expand All @@ -173,9 +177,14 @@ describe('Services | Slack | Commands', () => {
sinon.assert.calledWith(githubServices.getLatestReleaseTag, 'pix-editor');
});

it('should deploy the release', () => {
it('should deploy the release on production', () => {
// then
sinon.assert.calledWith(releasesServices.deployPixRepo);
sinon.assert.calledWith(client.deployFromArchive, 'pix-lcms-production');
});

it('should deploy the release on minimal', () => {
// then
sinon.assert.calledWith(client.deployFromArchive, 'pix-lcms-minimal-production');
});
});

Expand Down Expand Up @@ -207,7 +216,7 @@ describe('Services | Slack | Commands', () => {

it('should deploy the release for pix-bot-run', () => {
// then
sinon.assert.calledWith(client.deployFromArchive, 'pix-bot-run');
sinon.assert.calledWith(client.deployFromArchive, 'pix-bot-run-production');
});
});

Expand Down

0 comments on commit ddbb09b

Please sign in to comment.