File tree Expand file tree Collapse file tree 5 files changed +62
-4
lines changed
packages/artillery/lib/platform/aws-ecs/legacy Expand file tree Collapse file tree 5 files changed +62
-4
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ name: Build & publish ECS/Fargate worker image to ECR
2
2
3
3
on :
4
4
workflow_dispatch :
5
- push :
6
- branches :
7
- - main
8
5
workflow_call :
9
6
inputs :
10
7
ref :
Original file line number Diff line number Diff line change 18
18
- ' packages/artillery-plugin-memory-inspector/**'
19
19
20
20
jobs :
21
+ publish-fargate-worker-image :
22
+ if : " !contains( github.event.head_commit.message, 'ci: release v')"
23
+ uses : ./.github/workflows/docker-ecs-worker-image.yml
24
+ permissions :
25
+ contents : read
26
+ id-token : write
27
+ secrets :
28
+ ECR_WORKER_IMAGE_PUSH_ROLE_ARN : ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
29
+
21
30
build :
22
31
runs-on : ubuntu-latest
32
+ if : " !contains( github.event.head_commit.message, 'ci: release v')"
23
33
permissions :
24
34
contents : read
25
35
packages : write
32
42
node-version : ' 18.x'
33
43
registry-url : ' https://registry.npmjs.org'
34
44
scope : ' @artilleryio'
45
+ - run : node ./github/workflows/scripts/replace-worker-version-in-js-file.js
46
+ env :
47
+ COMMIT_SHA : ${{ github.sha }}
35
48
- run : |
36
49
export COMMIT_SHA=$(git rev-parse --short HEAD)
37
50
node .github/workflows/scripts/replace-package-versions-with-commit-sha.js
Original file line number Diff line number Diff line change 6
6
paths :
7
7
- packages/artillery/package.json
8
8
jobs :
9
+ publish-fargate-worker-image :
10
+ if : " contains( github.event.head_commit.message, 'ci: release v')"
11
+ uses : ./.github/workflows/docker-ecs-worker-image.yml
12
+ permissions :
13
+ contents : read
14
+ id-token : write
15
+ secrets :
16
+ ECR_WORKER_IMAGE_PUSH_ROLE_ARN : ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
17
+
9
18
build :
10
19
if : " contains(github.event.head_commit.message, 'ci: release v')"
20
+ needs : publish-fargate-worker-image
11
21
runs-on : ubuntu-latest
12
22
permissions :
13
23
contents : read
19
29
node-version : ' 18.x'
20
30
registry-url : ' https://registry.npmjs.org'
21
31
scope : ' @artilleryio'
22
- - run : PACKAGE_FOLDER_NAME=artillery node .github/workflows/scripts/rename-packages-to-correct-version.js
32
+ - run : node ./github/workflows/scripts/replace-worker-version-in-js-file.js
33
+ env :
34
+ COMMIT_SHA : ${{ github.sha }}
35
+ - run : node .github/workflows/scripts/rename-packages-to-correct-version.js
36
+ env :
37
+ PACKAGE_FOLDER_NAME : artillery
23
38
- run : npm -w artillery publish --tag latest
24
39
env :
25
40
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
3
+
4
+ const commitSha = process . env . COMMIT_SHA ;
5
+
6
+ const filePath = path . join (
7
+ __dirname ,
8
+ '../../../packages/artillery/lib/platform/aws-ecs/legacy/constants.js'
9
+ ) ;
10
+
11
+ try {
12
+ let content = fs . readFileSync ( filePath , 'utf8' ) ;
13
+
14
+ // This regex matches "const DEFAULT_IMAGE_TAG" followed by any characters, and then an equal sign and more characters
15
+ // until it reaches a semicolon or end of the line
16
+ const regex = / c o n s t D E F A U L T _ I M A G E _ T A G \s * = \s * ( [ ' " ] ) [ ^ ' " ] * ?\1/ ;
17
+ const replacement = `const DEFAULT_IMAGE_TAG = '${ commitSha } '` ; // Replace with commitSha in single quotes
18
+ content = content . replace ( regex , replacement ) ;
19
+
20
+ // Write the modified content back to the file
21
+ fs . writeFileSync ( filePath , content ) ;
22
+
23
+ // Verify by reading the content again and console logging it
24
+ const verifyContent = fs . readFileSync ( filePath , 'utf8' ) ;
25
+ console . log ( verifyContent ) ;
26
+
27
+ if ( ! verifyContent . includes ( commitSha ) ) {
28
+ throw new Error ( 'Failed to replace commit SHA in JS file' ) ;
29
+ }
30
+ } catch ( error ) {
31
+ console . error ( 'Error occurred:' , error ) ;
32
+ }
Original file line number Diff line number Diff line change
1
+ // NOTE: if changing this, change replace-worker-version-in-js-file.js script in github workflows that looks for a specific pattern here.
1
2
const DEFAULT_IMAGE_TAG = 'f7534a2844b58ee2a851081a3c498e671ad94f17' ;
2
3
3
4
module . exports = {
You can’t perform that action at this time.
0 commit comments