Skip to content

Commit dc8c4f4

Browse files
authored
CIF-2687 - Push queries to reference repo (#828)
* CIF-2687 - Push queries to reference repo * CIF-2687 - Push queries to reference repo * CIF-2687 - Push queries to reference repo * CIF-2687 - Push queries to reference repo * CIF-2687 - Push queries to reference repo * CIF-2687 - Update schema location * CIF-2687 - Add feedback
1 parent 39c92f5 commit dc8c4f4

5 files changed

Lines changed: 121 additions & 195 deletions

File tree

.circleci/ci/ci.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,15 @@ module.exports = class CI {
180180
return output;
181181
}
182182

183+
parsePom() {
184+
const metaData = this.sh('printf \'${project.groupId}|${project.artifactId}|${project.name}|${project.version}|${project.packaging}\' | mvn help:evaluate --non-recursive | grep -Ev "(Download|\\[)"', true, false).split('|');
185+
return {
186+
groupId: metaData[0],
187+
artifactId: metaData[1],
188+
name: metaData[2],
189+
version: metaData[3],
190+
packaging: metaData[4]
191+
};
192+
}
193+
183194
};

.circleci/ci/deploy-queries.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
~ Copyright 2022 Adobe
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
16+
'use strict';
17+
18+
const { readFileSync, writeFileSync } = require('fs');
19+
20+
const ci = new (require('./ci.js'))();
21+
22+
const repo = 'commerce-cif-graphql-integration-reference';
23+
const path = `schemas/components`;
24+
25+
ci.stage('Push changes to reference repo');
26+
27+
// Parse POM to get version
28+
const { version } = ci.parsePom();
29+
30+
// Checkout public rep
31+
ci.checkout(`https://github.com/adobe/${repo}.git`);
32+
33+
// Commit and push
34+
ci.dir(repo, () => {
35+
// Copy query file
36+
const targetFile = `${path}/components-queries.log`;
37+
ci.sh(`mkdir -p ${path}`);
38+
ci.sh(`cp -r ../bundles/core/src/test/resources/test-queries/graphql-requests.log ${targetFile}`);
39+
sortFile(targetFile);
40+
ci.sh(`ls -aslh ${path}`);
41+
42+
ci.sh(`git add ${targetFile}`);
43+
ci.sh('git status');
44+
45+
// Abort early if there aren't any changes staged
46+
const status = ci.sh('git status', true, false);
47+
if (status.indexOf('Changes to be committed') === -1) {
48+
console.log('No changes to commit.');
49+
return;
50+
}
51+
52+
// Commit and push changes
53+
ci.gitImpersonate('CircleCI', 'no-reply@adobe.com', () => {
54+
ci.sh(`git commit -m "releng - Update Queries for CIF Core Components v${version}"`);
55+
ci.sh(`git push --set-upstream origin master`);
56+
});
57+
});
58+
59+
function sortFile(filePath) {
60+
let data;
61+
62+
try {
63+
data = readFileSync(filePath, 'UTF-8');
64+
} catch (err) {
65+
console.error(`Could not read query log file at ${filePath}`, err);
66+
}
67+
68+
let lines = data.split(/\r?\n/);
69+
lines = lines
70+
// Remove empty lines
71+
.filter(line => line.trim().length > 0)
72+
// Sort alphabetically
73+
.sort();
74+
writeFileSync(filePath, lines.join('\n'), 'UTF-8');
75+
}

.circleci/config.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,27 @@ jobs:
275275
rm -rf /home/circleci/.gnupg
276276
rm -rf /home/circleci/.npmrc
277277
278+
deploy-queries:
279+
executor: cif_executor
280+
steps:
281+
- checkout
282+
- *restore_cache
283+
- run:
284+
name: Update permissions
285+
command: sudo chown -R circleci /usr/local/lib/node_modules
286+
- run:
287+
name: Generate Queries
288+
command: |
289+
mvn -B clean verify
290+
working_directory: bundles/core
291+
- add_ssh_keys:
292+
fingerprints:
293+
- "16:2d:61:b7:70:89:21:ee:5f:53:30:ed:34:33:90:06"
294+
- run:
295+
name: Deploy Queries
296+
command: |
297+
node --unhandled-rejections=strict .circleci/ci/deploy-queries.js
298+
278299
workflows:
279300
version: 2
280301
build-and-release:
@@ -363,3 +384,13 @@ workflows:
363384
ignore: /.*/
364385
tags:
365386
only: /^core-cif-components-reactor-\d+\.\d+\.\d+$/
387+
- deploy-queries:
388+
context:
389+
- CIF Artifactory Cloud
390+
requires:
391+
- build-java-11
392+
filters:
393+
branches:
394+
ignore: /.*/
395+
tags:
396+
only: /^core-cif-components-reactor-\d+\.\d+\.\d+$/

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ yarn-error.log
5757
.npmrc
5858

5959
# UI Tests
60-
ui.tests/test-module/reports
60+
ui.tests/test-module/reports
61+
62+
# GraphQL query logs
63+
bundles/core/src/test/resources/test-queries/graphql-requests.log

0 commit comments

Comments
 (0)