Skip to content

Commit 9c8a948

Browse files
mshimajhipster-bot
andauthored
update generator-jhipster to 8.8.0 (#50)
Co-authored-by: JHipster Bot <[email protected]>
1 parent 6005cc7 commit 9c8a948

File tree

13 files changed

+1763
-970
lines changed

13 files changed

+1763
-970
lines changed

.blueprint/generate-sample/command.mjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
* limitations under the License.
1818
*/
1919
import { GENERATOR_APP } from 'generator-jhipster/generators';
20-
import { getGithubSamplesGroup } from 'generator-jhipster/testing';
20+
import { getGithubSamplesGroup, getGithubSamplesGroups } from 'generator-jhipster/testing';
21+
22+
const DEFAULT_SAMPLES_GROUP = 'samples';
2123

2224
/**
2325
* @type {import('generator-jhipster').JHipsterCommandDefinition}
@@ -34,15 +36,34 @@ const command = {
3436
cli: {
3537
type: String,
3638
},
37-
default: 'samples',
39+
scope: 'generator',
40+
},
41+
samplesGroup: {
42+
description: 'Samples group to lookup',
43+
cli: {
44+
type: String,
45+
},
46+
prompt: gen => ({
47+
when: !gen.all && !gen.sampleName,
48+
type: 'list',
49+
message: 'which sample group do you want to lookup?',
50+
choices: async () => getGithubSamplesGroups(gen.templatePath(gen.samplesFolder ?? '')),
51+
default: DEFAULT_SAMPLES_GROUP,
52+
}),
53+
configure: gen => {
54+
gen.samplesGroup = DEFAULT_SAMPLES_GROUP;
55+
},
3856
scope: 'generator',
3957
},
4058
sampleName: {
4159
prompt: gen => ({
4260
when: !gen.all,
4361
type: 'list',
4462
message: 'which sample do you want to generate?',
45-
choices: async () => getGithubSamplesGroup(gen.templatePath(gen.samplesFolder)),
63+
choices: async answers => {
64+
const samples = await getGithubSamplesGroup(gen.templatePath(), answers.samplesFolder ?? gen.samplesFolder);
65+
return Object.keys(samples.samples);
66+
},
4667
}),
4768
scope: 'generator',
4869
},

.blueprint/generate-sample/generator.mjs

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,20 @@ import BaseGenerator from 'generator-jhipster/generators/base';
55
import { getGithubSamplesGroup } from 'generator-jhipster/testing';
66

77
export default class extends BaseGenerator {
8+
/** @type {string | undefined} */
9+
samplesFolder;
10+
/** @type {string} */
11+
samplesGroup;
12+
/** @type {string} */
813
sampleName;
14+
/** @type {boolean} */
915
all;
10-
samplesFolder;
16+
/** @type {string} */
17+
sampleType;
18+
/** @type {string} */
19+
sampleFile;
20+
/** @type {any} */
21+
generatorOptions;
1122

1223
constructor(args, opts, features) {
1324
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
@@ -16,20 +27,33 @@ export default class extends BaseGenerator {
1627
get [BaseGenerator.WRITING]() {
1728
return this.asWritingTaskGroup({
1829
async copySample() {
19-
const { samplesFolder, all, sampleName } = this;
30+
const { samplesFolder, samplesGroup, all, sampleName } = this;
31+
const samplesPath = samplesFolder ? join(samplesFolder, samplesGroup) : samplesGroup;
2032
if (all) {
21-
this.copyTemplate(`${samplesFolder}/*.jdl`, '');
33+
this.copyTemplate(`${samplesPath}/*.jdl`, '');
34+
this.sampleType = 'jdl';
2235
} else if (extname(sampleName) === '.jdl') {
23-
this.copyTemplate(join(samplesFolder, sampleName), sampleName, { noGlob: true });
36+
this.copyTemplate(join(samplesPath, sampleName), sampleName, { noGlob: true });
37+
this.sampleType = 'jdl';
2438
} else {
25-
const { samples } = await getGithubSamplesGroup(this.templatePath(), samplesFolder);
26-
const { 'sample-type': sampleType } = samples[sampleName];
39+
const { samples } = await getGithubSamplesGroup(this.templatePath(), samplesPath);
40+
const {
41+
'sample-type': sampleType,
42+
'sample-file': sampleFile = sampleName,
43+
'sample-folder': sampleFolder = samplesPath,
44+
generatorOptions,
45+
} = samples[sampleName];
46+
47+
this.generatorOptions = generatorOptions;
48+
this.sampleType = sampleType;
49+
2750
if (sampleType === 'jdl') {
28-
const jdlFile = `${sampleName}.jdl`;
29-
this.copyTemplate(join(samplesFolder, jdlFile), jdlFile, { noGlob: true });
51+
const jdlFile = `${sampleFile}.jdl`;
52+
this.copyTemplate(join(sampleFolder, jdlFile), jdlFile, { noGlob: true });
3053
} else if (sampleType === 'yo-rc') {
31-
this.copyTemplate(join(samplesFolder, sampleName, '**'), '', {
32-
fromBasePath: this.templatesPath(samplesFolder, sampleName),
54+
this.copyTemplate('**', '', {
55+
fromBasePath: this.templatePath(sampleFolder, sampleFile),
56+
globOptions: { dot: true },
3357
});
3458
}
3559
}
@@ -39,17 +63,23 @@ export default class extends BaseGenerator {
3963

4064
get [BaseGenerator.END]() {
4165
return this.asEndTaskGroup({
42-
async generateSample() {
43-
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
44-
const projectVersion = `${packageJson.version}-git`;
66+
async generateYoRcSample() {
67+
if (this.sampleType !== 'yo-rc') return;
68+
69+
const generatorOptions = this.getDefaultComposeOptions();
70+
await this.composeWithJHipster('app', { generatorOptions });
71+
},
72+
async generateJdlSample() {
73+
if (this.sampleType !== 'jdl') return;
74+
75+
const generatorOptions = this.getDefaultComposeOptions();
76+
const folderContent = await readdir(this.destinationPath());
77+
const jdlFiles = folderContent.filter(file => file.endsWith('.jdl'));
4578

4679
await this.composeWithJHipster('jdl', {
47-
generatorArgs: this.all ? await readdir(this.templatePath('samples')) : [this.sampleName],
80+
generatorArgs: jdlFiles,
4881
generatorOptions: {
49-
skipJhipsterDependencies: true,
50-
insight: false,
51-
skipChecks: true,
52-
projectVersion,
82+
...generatorOptions,
5383
...(this.all ? { workspaces: true, monorepository: true } : { skipInstall: true }),
5484
},
5585
});
@@ -59,4 +89,14 @@ export default class extends BaseGenerator {
5989
},
6090
});
6191
}
92+
93+
getDefaultComposeOptions() {
94+
const packageJson = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url)));
95+
const projectVersion = `${packageJson.version}-git`;
96+
return {
97+
skipJhipsterDependencies: true,
98+
projectVersion,
99+
...this.generatorOptions,
100+
};
101+
}
62102
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`generator - github-build-matrix > with samples > should match matrix value 1`] = `
4+
{
5+
"include": [
6+
{
7+
"default-environment": "prod",
8+
"java-version": "17",
9+
"job-name": "imperative-gradle",
10+
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
11+
"node-version": "22.12.0",
12+
"npm-version": "11.0.0",
13+
"os": "ubuntu-latest",
14+
"sample": "imperative-gradle",
15+
"sample-type": "jdl",
16+
"samples-group": "samples",
17+
},
18+
{
19+
"default-environment": "prod",
20+
"java-version": "17",
21+
"job-name": "imperative-maven",
22+
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
23+
"node-version": "22.12.0",
24+
"npm-version": "11.0.0",
25+
"os": "ubuntu-latest",
26+
"sample": "imperative-maven",
27+
"sample-type": "jdl",
28+
"samples-group": "samples",
29+
},
30+
{
31+
"default-environment": "prod",
32+
"java-version": "17",
33+
"job-name": "reactive-gradle",
34+
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
35+
"node-version": "22.12.0",
36+
"npm-version": "11.0.0",
37+
"os": "ubuntu-latest",
38+
"sample": "reactive-gradle",
39+
"sample-type": "jdl",
40+
"samples-group": "samples",
41+
},
42+
{
43+
"default-environment": "prod",
44+
"java-version": "17",
45+
"job-name": "reactive-maven",
46+
"jwt-secret-key": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
47+
"node-version": "22.12.0",
48+
"npm-version": "11.0.0",
49+
"os": "ubuntu-latest",
50+
"sample": "reactive-maven",
51+
"sample-type": "jdl",
52+
"samples-group": "samples",
53+
},
54+
],
55+
}
56+
`;

.blueprint/github-build-matrix/command.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ const command = {
88
cli: {
99
type: String,
1010
},
11+
scope: 'generator',
12+
},
13+
samplesGroup: {
14+
description: 'Samples Group',
15+
argument: {
16+
type: String,
17+
},
1118
default: 'samples',
1219
scope: 'generator',
1320
},

.blueprint/github-build-matrix/generator.mjs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { join } from 'node:path';
12
import BaseGenerator from 'generator-jhipster/generators/base';
23
import { convertToGitHubMatrix, getGithubOutputFile, getGithubSamplesGroup, setGithubTaskOutput } from 'generator-jhipster/testing';
34

45
export default class extends BaseGenerator {
56
/** @type {string} */
67
samplesFolder;
8+
/** @type {string} */
9+
samplesGroup;
10+
/** @type {object} */
11+
matrix;
712

813
constructor(args, opts, features) {
914
super(args, opts, { ...features, queueCommandTasks: true, jhipsterBootstrap: false });
@@ -12,16 +17,18 @@ export default class extends BaseGenerator {
1217
get [BaseGenerator.WRITING]() {
1318
return this.asWritingTaskGroup({
1419
async buildMatrix() {
15-
const { samplesFolder } = this;
16-
const { samples, warnings } = await getGithubSamplesGroup(this.templatePath('../../generate-sample/templates/'), samplesFolder);
20+
const { samplesGroup = 'samples' } = this;
21+
const templatePath = this.templatePath('../../generate-sample/templates/');
22+
const samplesFolder = this.samplesFolder ? join(templatePath, this.samplesFolder) : templatePath;
23+
const { samples, warnings } = await getGithubSamplesGroup(samplesFolder, samplesGroup);
1724
if (warnings.length > 0) {
18-
this.info(warnings.join('\n'));
25+
this.log.info(warnings.join('\n'));
1926
}
20-
const matrix = JSON.stringify(convertToGitHubMatrix(samples));
21-
const githubOutputFile = getGithubOutputFile(matrix);
22-
this.log.info('matrix', matrix);
27+
this.matrix = convertToGitHubMatrix(samples);
28+
const githubOutputFile = getGithubOutputFile();
29+
this.log.info('matrix', this.matrix);
2330
if (githubOutputFile) {
24-
setGithubTaskOutput('matrix', matrix);
31+
setGithubTaskOutput('matrix', JSON.stringify(this.matrix));
2532
}
2633
},
2734
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { basename, dirname, join } from 'path';
2+
import { fileURLToPath } from 'url';
3+
import { beforeAll, describe, expect, it } from 'vitest';
4+
import { getGithubSamplesGroups, defaultHelpers as helpers, runResult } from 'generator-jhipster/testing';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
const generator = basename(__dirname);
10+
11+
describe(`generator - ${generator}`, async () => {
12+
const groups = await getGithubSamplesGroups(join(__dirname, '../generate-sample/templates/'));
13+
for (const workflow of groups.map(sample => sample.split('.')[0])) {
14+
describe(`with ${workflow}`, () => {
15+
beforeAll(async () => {
16+
await helpers.runJHipster(join(__dirname, 'index.mjs'), { useEnvironmentBuilder: true }).withArguments(workflow);
17+
});
18+
19+
it('should match matrix value', () => {
20+
expect(runResult.generator.matrix).toMatchSnapshot();
21+
});
22+
});
23+
}
24+
});

.github/workflows/samples.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
name: Verify Sample Projects
2+
concurrency:
3+
# Group PRs by head_ref, push to main branch by commit id, and others branch by ref.
4+
group: ${{ github.workflow }}-${{ github.head_ref || (github.ref == 'refs/heads/main' && github.sha) || github.ref }}
5+
cancel-in-progress: true
26
on:
37
push:
48
branches:
@@ -11,6 +15,8 @@ on:
1115
- '*'
1216
permissions:
1317
contents: read
18+
env:
19+
FORCE_COLOR: 2
1420
jobs:
1521
build-matrix:
1622
runs-on: ubuntu-latest
@@ -26,8 +32,8 @@ jobs:
2632
npm install
2733
./cli/cli.cjs github-build-matrix
2834
samples:
29-
name: ${{ matrix.job-name || matrix.sample-name }}
30-
runs-on: ubuntu-latest
35+
name: ${{ matrix.job-name || matrix.sample }}
36+
runs-on: ${{ matrix.os }}
3137
needs: build-matrix
3238
defaults:
3339
run:
@@ -50,15 +56,15 @@ jobs:
5056
binary-dir: ${{ github.workspace }}/generator-jhipster-jooq/cli/
5157
- run: npm install
5258
working-directory: ${{ github.workspace }}/generator-jhipster-jooq
53-
- run: cli.cjs generate-sample ${{ matrix.sample }}.jdl --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
59+
- run: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
5460
- uses: jhipster/actions/compare-sample@v0
5561
id: compare
5662
if: >-
5763
github.event.pull_request &&
5864
!contains(github.event.pull_request.labels.*.name, 'pr: disable-compare')
5965
with:
6066
generator-path: generator-jhipster-jooq
61-
cmd: cli.cjs generate-sample ${{ matrix.sample }}.jdl --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
67+
cmd: cli.cjs generate-sample ${{ matrix.sample }} --skip-jhipster-dependencies --skip-install ${{ matrix.extra-args }}
6268
- run: npm run ci:backend:test
6369
if: steps.compare.outputs.equals != 'true'
6470
id: backend
@@ -75,15 +81,15 @@ jobs:
7581
uses: actions/upload-artifact@v4
7682
if: always() && steps.backend.outcome == 'failure'
7783
with:
78-
name: log-${{ matrix.sample-name }}
84+
name: log-${{ matrix.job-name || matrix.sample }}
7985
path: |
8086
${{ github.workspace }}/app/build/test-results/**/*.xml
8187
${{ github.workspace }}/app/target/surefire-reports
8288
- name: Store cypress screenshots
8389
uses: actions/upload-artifact@v4
8490
if: always() && steps.e2e.outcome == 'failure'
8591
with:
86-
name: screenshots-${{ matrix.sample-name }}
92+
name: screenshots-${{ matrix.job-name || matrix.sample }}
8793
path: ${{ github.workspace }}/app/**/cypress/screenshots
8894
- name: Dump docker logs
8995
if: always()

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,8 @@ Desktop.ini
149149
######################
150150
# Code coverage
151151
######################
152-
/coverage/
153-
/.nyc_output/
152+
coverage/
153+
.nyc_output/
154+
155+
# added by generate-blueprint:
156+
generators/**/package-lock.json

.yo-rc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
},
2222
"githubWorkflows": true,
23-
"jhipsterVersion": "8.7.3",
23+
"jhipsterVersion": "8.8.0",
2424
"js": false,
2525
"localBlueprint": false,
2626
"packageJsonType": "module",

0 commit comments

Comments
 (0)