Skip to content

Commit 6652122

Browse files
chore: auto update version in openapi (#44)
1 parent 62d6e0d commit 6652122

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

api/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ RUN apk update && apk upgrade
88
COPY package.json .
99
COPY package-lock.json .
1010
COPY generateEsModulesFromJson.cjs .
11+
COPY updateVersionOpenApi.cjs .
12+
COPY openapi.yaml .
13+
1114
RUN npm ci --omit=dev
1215

1316
COPY src ./src
14-
COPY openapi.yaml .
1517

1618
CMD ["npm", "start"]

api/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ info:
33
title: iExec market API
44
description: >-
55
iExec market API OpenAPI specification
6-
version: 6.4.1
6+
version: 7.1.1
77
license:
88
name: Apache 2.0
99
url: http://www.apache.org/licenses/LICENSE-2.0.html

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"npm": ">=10.0.0"
1010
},
1111
"scripts": {
12-
"codegen": "node generateEsModulesFromJson.cjs",
12+
"codegen": "node generateEsModulesFromJson.cjs && node updateVersionOpenApi.cjs",
1313
"postinstall": "npm run codegen",
1414
"format": "prettier --write .",
1515
"check-format": "prettier --check .",

api/updateVersionOpenApi.cjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const path = require('path');
2+
const { writeFile, readFile } = require('fs/promises');
3+
4+
const OPEN_API_SPECIFICATION_FILE = 'openapi.yaml';
5+
6+
async function updateVersionOpenApi() {
7+
const packagePath = path.join(__dirname, 'package.json');
8+
const packageContent = await readFile(packagePath, 'utf8');
9+
const packageJson = JSON.parse(packageContent);
10+
const packageVersion = packageJson.version;
11+
12+
const openApiPath = path.join(__dirname, OPEN_API_SPECIFICATION_FILE);
13+
const openApiContent = await readFile(openApiPath, 'utf8');
14+
const openApiVersionPattern = /version: \d+\.\d+\.\d+(-\S+)?/;
15+
16+
const [match] = openApiContent.match(openApiVersionPattern);
17+
18+
const currentVersion = match.split('version: ')[1];
19+
if (currentVersion === packageVersion) {
20+
return;
21+
}
22+
const updatedContent = openApiContent.replace(
23+
openApiVersionPattern,
24+
`version: ${packageVersion}`,
25+
);
26+
await writeFile(openApiPath, updatedContent, 'utf8');
27+
console.log(
28+
`version updated from ${currentVersion} to ${packageVersion} in ${OPEN_API_SPECIFICATION_FILE}`,
29+
);
30+
}
31+
32+
updateVersionOpenApi().catch((error) => {
33+
console.error('Error updating OpenAPI version:', error);
34+
process.exit(1);
35+
});

0 commit comments

Comments
 (0)