Skip to content

Commit e2e9c88

Browse files
refactor: update github CI workflow
- also added handy fs-extra json functions for JSON reading/writing - update docker image to node 20.12.2
1 parent 6e0a5b5 commit e2e9c88

File tree

12 files changed

+99
-88
lines changed

12 files changed

+99
-88
lines changed

.github/actions/semantic/action.yml

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: semantic-release-node
22
description: 'perform semantic-release actions for node'
33

4-
inputs:
5-
publish:
6-
description: 'tell semantic-release to publish or run in DRY-RUN mode (default)'
7-
required: false
8-
default: 'false'
9-
104
outputs:
115
last_release_version:
126
description: 'version before semantic-release'
@@ -24,17 +18,9 @@ runs:
2418
- name: run-release
2519
id: release
2620
shell: bash
27-
env:
28-
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN || env.GH_TOKEN }}
29-
NPM_TOKEN: ${{ env.NPM_TOKEN }}
3021
run: |
3122
echo "last_release_version=`cat package.json | jq -r .version`" >> $GITHUB_OUTPUT
32-
33-
if [[ '${{ inputs.publish }}' == 'true' ]]; then
34-
npx semantic-release | tee release.output;
35-
else
36-
npx semantic-release --dry-run --no-ci --branches ${{ github.ref_name }} | tee release.output;
37-
fi
23+
echo npx semantic-release | tee release.output;
3824
3925
- name: post-release
4026
if: always()
@@ -48,15 +34,3 @@ runs:
4834
echo "new_release_published=false" >> $GITHUB_OUTPUT
4935
echo "new_release_version=none" >> $GITHUB_OUTPUT
5036
fi
51-
52-
- name: Update job summary after semantic-release
53-
if: always()
54-
shell: bash
55-
run: |
56-
if [ '${{ steps.release.outputs.new_release_published }}' == 'true' ]; then
57-
echo - A new release ${{ inputs.publish == 'true' && 'was' || 'will be' }} published! >> $GITHUB_STEP_SUMMARY
58-
echo - Last Release: **${{ steps.release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
59-
echo - New Release: **${{ steps.release.outputs.new_release_version }}** >> $GITHUB_STEP_SUMMARY
60-
else
61-
echo - No new Release! The current release is: **${{ steps.release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
62-
fi

.github/workflows/test-release-publish.yml

+76-33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ on:
1212
default: false
1313
type: boolean
1414

15+
defaults:
16+
run:
17+
shell: bash
18+
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22+
23+
permissions:
24+
contents: read # for checkout
25+
1526
jobs:
1627
test:
1728
runs-on: ubuntu-latest
@@ -22,6 +33,9 @@ jobs:
2233
steps:
2334
- name: Checkout
2435
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
persist-credentials: false
2539

2640
- name: Setup Node.js ${{ matrix.node-version }}
2741
uses: actions/setup-node@v4
@@ -33,66 +47,75 @@ jobs:
3347
npm ci --ignore-scripts
3448
npm test
3549
36-
release:
50+
semantic-release:
3751
runs-on: ubuntu-latest
3852
needs: test
39-
if: github.ref == 'refs/heads/main' && needs.test.result == 'success'
53+
if: github.ref_name == 'main' && needs.test.result == 'success'
54+
permissions:
55+
contents: write # to be able to publish a GitHub release
56+
issues: write # to be able to comment on released issues
57+
pull-requests: write # to be able to comment on released pull requests
58+
id-token: write # to enable use of OIDC for npm provenance
4059
outputs:
4160
last_release_version: ${{ steps.release.outputs.last_release_version }}
4261
new_release_version: ${{ steps.release.outputs.new_release_version }}
4362
new_release_published: ${{ steps.release.outputs.new_release_published }}
4463
steps:
4564
- name: Checkout
4665
uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
persist-credentials: false
4769

48-
- name: Setup Node.js
70+
- name: Print info
71+
run: |
72+
# Echo the version from package.json
73+
echo "Current package version: [$(jq -r .version package.json)]"
74+
75+
- name: Setup NodeJS 21
4976
uses: actions/setup-node@v4
5077
with:
5178
node-version: 21
5279
cache: 'npm'
5380

54-
- name: Install node modules and run tests
81+
- name: NPM install
5582
run: |
5683
npm ci --ignore-scripts
5784
5885
- name: Semantic Release [PUBLISH]
59-
uses: ./.github/actions/semantic
6086
id: release
61-
env:
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
64-
with:
65-
publish: true
87+
uses: ./.github/actions/semantic
6688

67-
deploy:
89+
publish-docker:
6890
runs-on: ubuntu-latest
69-
needs: release
70-
if: github.ref == 'refs/heads/main' && (needs.release.outputs.new_release_published == 'true' || github.event.inputs.force-docker == true)
91+
needs: semantic-release
92+
if: github.ref_name == 'main' && (needs.semantic-release.outputs.new_release_published == 'true' || github.event.inputs.force-docker == true)
93+
outputs:
94+
docker_imageid: ${{ steps.docker_build.outputs.imageid }}
7195
steps:
7296
- name: Checkout
7397
uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0
100+
persist-credentials: false
101+
102+
- name: Print npm package info
103+
run: |
104+
# Echo the version from package.json
105+
echo "Current package version: [$(jq -r .version package.json)]"
74106
75-
- name: Setup Node.js
107+
- name: Setup NodeJS 21
76108
uses: actions/setup-node@v4
77109
with:
78110
node-version: 21
79111

80-
- name: Install node modules and run tests
112+
- name: NPM install
81113
run: |
82114
npm ci --ignore-scripts
83115
84-
- name: Set up Docker Buildx
85-
id: buildx
116+
- name: Install Docker Buildx
86117
uses: docker/setup-buildx-action@v3
87118

88-
- name: Cache Docker layers
89-
uses: actions/cache@v4
90-
with:
91-
path: /tmp/.buildx-cache
92-
key: ${{ runner.os }}-buildx-${{ github.sha }}
93-
restore-keys: |
94-
${{ runner.os }}-buildx-
95-
96119
- name: Login to Docker Hub
97120
uses: docker/login-action@v3
98121
with:
@@ -103,15 +126,35 @@ jobs:
103126
id: docker_build
104127
uses: docker/build-push-action@v5
105128
with:
106-
builder: ${{ steps.buildx.outputs.name }}
129+
context: .
107130
push: true
108131
tags: |
109132
godaddy/timings:latest
110-
godaddy/timings:${{ needs.release.outputs.new_release_version }}
111-
cache-from: type=local,src=/tmp/.buildx-cache
112-
cache-to: type=local,dest=/tmp/.buildx-cache
133+
godaddy/timings:${{ needs.semantic-release.outputs.new_release_version }}
134+
cache-from: type=registry,ref=user/app:buildcache
135+
cache-to: type=registry,ref=user/app:buildcache,mode=max
113136

114-
- name: Image digest
115-
run: |
116-
echo Docker image was published sucessfully! >> $GITHUB_STEP_SUMMARY
117-
echo - Image ID: **${{ steps.docker_build.outputs.imageid }}** >> $GITHUB_STEP_SUMMARY
137+
finish:
138+
runs-on: ubuntu-latest
139+
needs: [semantic-release, publish-docker]
140+
steps:
141+
- name: Print info
142+
run: |
143+
echo "needs.semantic-release: ${{ toJSON(needs.semantic-release) }}"
144+
145+
- name: Report
146+
run: |
147+
if [ '${{ needs.semantic-release.outputs.new_release_published }}' == 'true' ]; then
148+
echo - A new release was published! >> $GITHUB_STEP_SUMMARY
149+
echo - Last Release: **${{ needs.semantic-release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
150+
echo - New Release: **${{ needs.semantic-release.outputs.new_release_version }}** >> $GITHUB_STEP_SUMMARY
151+
else
152+
echo - No new Release! The current release is: **${{ needs.semantic-release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
153+
fi
154+
if [ '${{ needs.publish-docker.result }}' == 'success' ]; then
155+
echo - Docker image was published! >> $GITHUB_STEP_SUMMARY
156+
echo - Image ID: **${{ needs.publish-docker.outputs.docker_imageid }}** >> $GITHUB_STEP_SUMMARY
157+
else
158+
echo - Docker image was not published! >> $GITHUB_STEP_SUMMARY
159+
fi
160+

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:20.2.0-slim
1+
FROM node:20.12.2-slim
22
RUN apt-get update && apt-get upgrade -y
33

44
LABEL Description="timings"

routes/v2/post-routes.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Created by mverkerk on 9/25/2016.
33
*/
4-
import fs from 'fs';
4+
import fs from 'fs-extra';
55
import { Router } from 'express';
66
import crypto from 'crypto';
77
// eslint-disable-next-line new-cap
@@ -48,15 +48,13 @@ export default function (app) {
4848
req.body.env.ES_PASS = app.locals.env.ES_PASS;
4949
}
5050

51-
const data = JSON.stringify(req.body);
52-
5351
// Write the file and send the response
5452
try {
5553
const returnJSON = req.body;
5654
if (returnJSON.env?.ES_PASS) returnJSON.env.ES_PASS = '********';
5755
res.json(returnJSON);
5856
// eslint-disable-next-line no-sync
59-
fs.writeFileSync(app.locals.env.APP_CONFIG, data);
57+
fs.writeJsonSync(app.locals.env.APP_CONFIG, returnJSON);
6058
// Config updated - re-init the server
6159
const es = new Elastic(app);
6260
setConfig(app, app.locals.appRootPath); // this resets the config!

routes/v2/static-routes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// eslint-disable-next-line new-cap
22
import os from 'os';
3-
import fs from 'fs';
3+
import fs from 'fs-extra';
44
import { Router } from 'express';
55
import path from 'path';
66
import isDocker from 'is-docker';
@@ -63,7 +63,7 @@ export default function (app) {
6363
try {
6464
if (cfgFile && fs.existsSync(cfgFile)) {
6565
if (cfgFile.endsWith('.json')) {
66-
config = JSON.parse(fs.readFileSync(cfgFile, 'utf8'));
66+
config = fs.readJsonSync(cfgFile);
6767
} else {
6868
config.error = `Sorry - your config file [${cfgFile}] is not JSON - we hope to add more options soon!`;
6969
}

server.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
/* eslint-disable no-process-exit */
33
/* eslint-disable id-length */
4-
import fs from 'fs';
4+
import fs from 'fs-extra';
55
import path from 'path';
66
import winston from 'winston';
77
import expressWinston from 'express-winston';
@@ -27,7 +27,7 @@ const logFileSettings = {
2727
};
2828

2929
// Loading package.json content
30-
const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url)));
30+
const pkg = fs.readJsonSync(new URL('./package.json', import.meta.url));
3131

3232
let app;
3333

src/v2/config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import fs from 'fs';
1+
import fs from 'fs-extra';
22
import os from 'os';
33
import path from 'path';
44
import winston from 'winston';
55
import logger from '../log.js';
66
const __dirname = path.dirname(new URL(import.meta.url).pathname);
77

8-
const pkg = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url)));
8+
const pkg = fs.readJsonSync(new URL('../../package.json', import.meta.url));
99
const { CONFIGFILE, ES_UPGRADE } = process.env;
1010

1111
// Load config file - only JSON!
@@ -19,7 +19,7 @@ if (!configFile || !configFile.endsWith('.json') || !fs.existsSync(path.resolve(
1919
function setConfig(app, appRootPath) {
2020
app.locals.configFile = app.locals.configFile || configFile;
2121

22-
const appConfig = JSON.parse(fs.readFileSync(path.resolve(configFile)));
22+
const appConfig = fs.readJsonSync(configFile);
2323

2424
// Check for missing keys & add some ENV vars
2525
if (!appConfig.env) {

src/v2/es-utils.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/** Created by mverkerk on 10/20/2016. */
2-
import fs from 'fs';
2+
import fs from 'fs-extra';
33
import { Client } from '@elastic/elasticsearch';
44

55
// Loading sample data content
6-
const sampleData = JSON.parse(fs.readFileSync(new URL('../../config/.sample_data.json', import.meta.url)));
7-
const { version } = JSON.parse(fs.readFileSync(
8-
new URL('../../node_modules/@elastic/elasticsearch/package.json', import.meta.url)
9-
));
6+
const sampleData = fs.readJsonSync(new URL('../../config/.sample_data.json', import.meta.url));
7+
const { version } = fs.readJsonSync(new URL('../../node_modules/@elastic/elasticsearch/package.json', import.meta.url));
108

119
/* eslint no-sync: 0 */
1210
class ESClass {

src/v2/kb-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Created by mverkerk on 10/20/2016.
33
*/
4-
import fs from 'fs';
4+
import fs from 'fs-extra';
55
import path from 'path';
66
import FormData from 'form-data';
77

src/v2/perf-utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class PUClass {
100100
e.message = 'Missing first run - currentRun has to be 1 for the first run!';
101101
throw e;
102102
}
103-
const appendObject = this.objParams.multirun.currentRun < 2 ? {} : await fs.readJson(multiFile);
103+
const appendObject = this.objParams.multirun.currentRun < 2 ? {} : fs.readJsonSync(multiFile);
104104
appendObject[this.objParams.multirun.currentRun] = this.objParams;
105105
appendObject[this.objParams.multirun.currentRun].route = this.route;
106106
// Write to the file

src/v2/run-es.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import fs from 'fs';
1+
import fs from 'fs-extra';
22
import semver from 'semver';
33
import { ESClass } from './es-utils.js';
44
import { KBClass } from './kb-utils.js';
55

6-
const esTemplate = JSON.parse(fs.readFileSync(new URL('../../config/.es_template.json', import.meta.url)));
6+
const esTemplate = fs.readJsonSync(new URL('../../config/.es_template.json', import.meta.url));
77

88
/* eslint no-sync: 0 */
99
class Elastic {

test/setup/add-globals.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
/* eslint-disable no-sync */
22
/* eslint-disable no-undef */
33
import './config-generic-env.js';
4-
import fs from 'fs';
5-
import path from 'path';
4+
import fs from 'fs-extra';
65
import mocks from '../__mocks__.js';
76
import fixtures from './fixtures.js';
87

9-
console.log('Adding vitest globals - see `test/setup/add-globals.js`');
108

119
// Get the current package version from package.json
12-
const packageJsonPath = path.resolve(__dirname, '../../package.json');
13-
const packageJsonData = fs.readFileSync(packageJsonPath);
14-
const packageJson = JSON.parse(packageJsonData);
15-
const { version } = packageJson;
10+
const { version } = fs.readJsonSync(new URL('../../package.json', import.meta.url));
11+
12+
console.log(`Adding vitest globals - see 'test/setup/add-globals.js'`);
13+
console.log(`Current package version: ${version}`);
1614

1715
// Add the global variables
1816
globalThis.mocks = mocks;

0 commit comments

Comments
 (0)