Skip to content

Commit fd63c51

Browse files
Merge pull request #2456 from artilleryio/bernardobridge/art-1607-use-the-right-docker-image-version-in-published-versions-of
ci: use the right docker image version in published artillery versions
2 parents 52b9e3b + dbe2c01 commit fd63c51

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

.github/workflows/docker-ecs-worker-image.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Build & publish ECS/Fargate worker image to ECR
22

33
on:
44
workflow_dispatch:
5-
push:
6-
branches:
7-
- main
85
workflow_call:
96
inputs:
107
ref:

.github/workflows/npm-publish-all-packages-canary.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ on:
1818
- 'packages/artillery-plugin-memory-inspector/**'
1919

2020
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+
2130
build:
2231
runs-on: ubuntu-latest
32+
if: "!contains( github.event.head_commit.message, 'ci: release v')"
2333
permissions:
2434
contents: read
2535
packages: write
@@ -32,6 +42,9 @@ jobs:
3242
node-version: '18.x'
3343
registry-url: 'https://registry.npmjs.org'
3444
scope: '@artilleryio'
45+
- run: node ./github/workflows/scripts/replace-worker-version-in-js-file.js
46+
env:
47+
COMMIT_SHA: ${{ github.sha }}
3548
- run: |
3649
export COMMIT_SHA=$(git rev-parse --short HEAD)
3750
node .github/workflows/scripts/replace-package-versions-with-commit-sha.js

.github/workflows/npm-publish-artillery.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ on:
66
paths:
77
- packages/artillery/package.json
88
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+
918
build:
1019
if: "contains(github.event.head_commit.message, 'ci: release v')"
20+
needs: publish-fargate-worker-image
1121
runs-on: ubuntu-latest
1222
permissions:
1323
contents: read
@@ -19,7 +29,12 @@ jobs:
1929
node-version: '18.x'
2030
registry-url: 'https://registry.npmjs.org'
2131
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
2338
- run: npm -w artillery publish --tag latest
2439
env:
2540
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 = /const DEFAULT_IMAGE_TAG\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+
}

packages/artillery/lib/platform/aws-ecs/legacy/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// NOTE: if changing this, change replace-worker-version-in-js-file.js script in github workflows that looks for a specific pattern here.
12
const DEFAULT_IMAGE_TAG = 'f7534a2844b58ee2a851081a3c498e671ad94f17';
23

34
module.exports = {

0 commit comments

Comments
 (0)