Skip to content

Commit

Permalink
Rework CI to use dev blueprint instead of bash scripts. (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Jan 29, 2025
1 parent 14bea9c commit fa06640
Show file tree
Hide file tree
Showing 165 changed files with 260 additions and 1,519 deletions.
4 changes: 4 additions & 0 deletions .blueprint/cli/commands.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const defaultCommands = {
desc: 'Generate a test sample',
blueprint: '@jhipster/jhipster-dev',
},
'github-build-matrix': {
desc: 'Build a matrix of jobs for github actions',
blueprint: '@jhipster/jhipster-dev',
},
synchronize: {
desc: 'Synchronize templates from generator-jhipster',
blueprint: '@jhipster/jhipster-dev',
Expand Down
34 changes: 21 additions & 13 deletions .blueprint/generate-sample/command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
* limitations under the License.
*/
import { existsSync, readdirSync } from 'node:fs';
import { entitiesByType, workflowSamples } from '../generate-sample/support/index.mjs';
import { getSamples } from './get-samples.mjs';
import { entitiesByType, workflowSamples } from './support/index.mjs';

const updateSampleName = sample =>
sample.replace('ngx', 'ng').replace('ms-ng-eureka-oauth2-mongodb-caffeine', 'ms-ng-oauth2-mongodb-caffeine');

const revertSampleName = sample =>
sample.replace('ng-', 'ngx-').replace('ms-ng-oauth2-mongodb-caffeine', 'ms-ng-eureka-oauth2-mongodb-caffeine');

/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
Expand All @@ -43,6 +37,18 @@ const command = {
message: 'which sample do you want to generate?',
choices: async () => getSamples(gen.templatePath(gen.samplesFolder)),
}),
configure: gen => {
const sample = workflowSamples[gen.sampleName];
if (!sample) {
throw new Error(`Sample ${gen.sampleName} not found`);
}

gen.sampleName = undefined;
gen.appSample = sample['app-sample'];
gen.jdlSamples = sample['jdl-samples'];
gen.jdlEntities = sample['jdl-entity'];
gen.entityType = sample.entity;
},
scope: 'generator',
},
all: {
Expand Down Expand Up @@ -81,11 +87,9 @@ const command = {
},
configure: gen => {
if (gen.appSample && gen.appSample !== 'jdl') {
gen.appSample = revertSampleName(gen.appSample);

let { appSample } = gen;
appSample = workflowSamples[appSample]?.['app-sample'] ?? appSample;
gen.samplesFolder = `json-samples/${updateSampleName(appSample)}`;
gen.samplesFolder = `_json-samples/${appSample}`;
gen.entrypointGenerator = 'app';
}
},
Expand All @@ -98,9 +102,13 @@ const command = {
env: 'JHI_JDL_APP',
},
configure: gen => {
if (gen.jdlSamples) {
const [app, ...entities] = gen.jdlSamples.split(',');
gen.samplesFolder = `jdl-samples/${updateSampleName(app)}`;
let { jdlSamples } = gen;
if (!jdlSamples && gen.appSample) {
jdlSamples = workflowSamples[gen.appSample]?.['jdl-samples'];
}
if (jdlSamples) {
const [app, ...entities] = jdlSamples.split(',');
gen.samplesFolder = `_jdl-samples/${app}`;
gen.generatorArgs = '*.jdl';
if (entities && entities.length > 0) {
gen.supportingSamples.push(...entities.map(entity => `${entity}.jdl`));
Expand Down
2 changes: 1 addition & 1 deletion .blueprint/generate-sample/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class extends BaseGenerator {
if (supportingSamples && supportingSamples.length > 0) {
this.log.info(`Copying support samples ${supportingSamples}`);
this.copyTemplate(supportingSamples, '', {
fromBasePath: this.templatePath('supporting-samples'),
fromBasePath: this.templatePath('_supporting-samples'),
globOptions: { dot: true },
});
}
Expand Down
15 changes: 11 additions & 4 deletions .blueprint/generate-sample/support/workflow-samples.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { readFileSync } from 'fs';

const angularSamples = readFileSync(new URL('../../../test-integration/workflow-samples/angular.json', import.meta.url), 'utf8');
const reactSamples = readFileSync(new URL('../../../test-integration/workflow-samples/react.json', import.meta.url), 'utf8');
const prepareSamples = samples => Object.fromEntries(samples.map(({ name, ...sample }) => [name, sample]));
const addSamplesGroup = (samples, samplesGroup) => samples.map(sample => ({ ...sample, 'samples-group': samplesGroup }));

const samples = [...JSON.parse(angularSamples).include, ...JSON.parse(reactSamples).include];
export const workflowSamples = Object.fromEntries(samples.map(({ name, ...sample }) => [name, sample]));
const angularJson = readFileSync(new URL('../templates/_workflow-samples/angular.json', import.meta.url), 'utf8');
const angularWorkflowSamples = addSamplesGroup(JSON.parse(angularJson).include, 'angular');

const reactJson = readFileSync(new URL('../templates/_workflow-samples/react.json', import.meta.url), 'utf8');
const reactWorkflowSamples = addSamplesGroup(JSON.parse(reactJson).include, 'react');

export const workflowSamples = prepareSamples([...angularWorkflowSamples, ...reactWorkflowSamples]);
export const angularSamples = prepareSamples(angularWorkflowSamples);
export const reactSamples = prepareSamples(reactWorkflowSamples);
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
{
"include": [
{
"name": "ngx-default",
"app-sample": "ngx-default",
"name": "ng-default",
"app-sample": "ng-default",
"entity": "sqlfull",
"sonar-analyse": "true"
},
{
"name": "ngx-default-additional",
"name": "ng-default-additional",
"entity": "none",
"app-sample": "ngx-default",
"app-sample": "ng-default",
"jdl-entity": "custom-id,entities"
},
{
"name": "ngx-mongodb-kafka-cucumber",
"app-sample": "ngx-mongodb-kafka-cucumber",
"name": "ng-mongodb-kafka-cucumber",
"app-sample": "ng-mongodb-kafka-cucumber",
"entity": "mongodb",
"environment": "dev"
},
{
"name": "ngx-gradle-fr",
"app-sample": "ngx-gradle-fr",
"name": "ng-gradle-fr",
"app-sample": "ng-gradle-fr",
"entity": "sql"
},
{
"name": "ngx-gradle-h2disk-ws-nocache",
"app-sample": "ngx-gradle-h2disk-ws-nocache",
"name": "ng-gradle-h2disk-ws-nocache",
"app-sample": "ng-gradle-h2disk-ws-nocache",
"entity": "sql",
"environment": "dev",
"war": 1,
"testcontainers": "false"
},
{
"name": "ngx-webflux-mongodb",
"name": "ng-webflux-mongodb",
"app-sample": "webflux-mongodb",
"entity": "mongodb"
},
{
"name": "ngx-webflux-gradle-mongodb-oauth2",
"name": "ng-webflux-gradle-mongodb-oauth2",
"app-sample": "webflux-mongodb-oauth2",
"entity": "mongodb"
},
{
"name": "ngx-webflux-psql-default",
"name": "ng-webflux-psql-default",
"app-sample": "webflux-psql",
"entity": "sql"
},
{
"name": "ngx-webflux-psql-additional",
"name": "ng-webflux-psql-additional",
"jdl-samples": "webflux-psql,custom-domain"
},
{
"name": "ngx-webflux-gradle-session-h2mem-es",
"name": "ng-webflux-gradle-session-h2mem-es",
"app-sample": "webflux-gradle-session-h2mem-es",
"environment": "dev",
"entity": "sqllight"
},
{
"name": "ms-ngx-oauth2-mongodb-caffeine",
"jdl-samples": "ms-ngx-oauth2-mongodb-caffeine",
"name": "ms-ng-oauth2-mongodb-caffeine",
"jdl-samples": "ms-ng-oauth2-mongodb-caffeine",
"extra-args": "--workspaces --monorepository",
"disabled": "unstable",
"workspaces": "true"
},
{
"name": "mf-ngx-eureka-jwt-psql-ehcache",
"jdl-samples": "mf-ngx-eureka-jwt-psql-ehcache",
"name": "mf-ng-eureka-jwt-psql-ehcache",
"jdl-samples": "mf-ng-eureka-jwt-psql-ehcache",
"extra-args": "--workspaces --monorepository",
"workspaces": "true"
},
{
"name": "ms-mf-ngx-consul-oauth2-neo4j",
"jdl-samples": "ms-mf-ngx-consul-oauth2-neo4j",
"name": "ms-mf-ng-consul-oauth2-neo4j",
"jdl-samples": "ms-mf-ng-consul-oauth2-neo4j",
"extra-args": "--workspaces --monorepository",
"disabled": "https://github.com/neo4j/neo4j/issues/13025",
"workspaces": "true"
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions .blueprint/generate-sample/templates/angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { angularSamples } from '../support/workflow-samples.mjs';

export default angularSamples;
3 changes: 3 additions & 0 deletions .blueprint/generate-sample/templates/react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reactSamples } from '../support/workflow-samples.mjs';

export default reactSamples;
25 changes: 25 additions & 0 deletions .blueprint/github-build-matrix/command.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @type {import('generator-jhipster').JHipsterCommandDefinition}
*/
const command = {
configs: {
samplesFolder: {
description: 'Samples folder',
cli: {
type: String,
},
scope: 'generator',
},
samplesGroup: {
description: 'Samples Group',
argument: {
type: String,
},
default: 'samples',
scope: 'generator',
},
},
options: {},
};

export default command;
36 changes: 36 additions & 0 deletions .blueprint/github-build-matrix/generator.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { join } from 'node:path';
import BaseGenerator from 'generator-jhipster/generators/base';
import { convertToGitHubMatrix, getGithubOutputFile, getGithubSamplesGroup, setGithubTaskOutput } from 'generator-jhipster/testing';

export default class extends BaseGenerator {
/** @type {string} */
samplesFolder;
/** @type {string} */
samplesGroup;
/** @type {object} */
matrix;

constructor(args, opts, features) {
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
}

get [BaseGenerator.WRITING]() {
return this.asWritingTaskGroup({
async buildMatrix() {
const { samplesGroup = 'samples' } = this;
const templatePath = this.templatePath('../../generate-sample/templates/');
const samplesFolder = this.samplesFolder ? join(templatePath, this.samplesFolder) : templatePath;
const { samples, warnings } = await getGithubSamplesGroup(samplesFolder, samplesGroup);
if (warnings.length > 0) {
this.log.info(warnings.join('\n'));
}
this.matrix = convertToGitHubMatrix(samples);
const githubOutputFile = getGithubOutputFile();
this.log.info('matrix', this.matrix);
if (githubOutputFile) {
setGithubTaskOutput('matrix', JSON.stringify(this.matrix));
}
},
});
}
}
2 changes: 2 additions & 0 deletions .blueprint/github-build-matrix/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './generator.mjs';
export { default as command } from './command.mjs';
Loading

0 comments on commit fa06640

Please sign in to comment.