diff --git a/.github/workflows/npm-publish-artillery.yml b/.github/workflows/npm-publish-artillery.yml index 8478423889..b2293db493 100644 --- a/.github/workflows/npm-publish-artillery.yml +++ b/.github/workflows/npm-publish-artillery.yml @@ -29,7 +29,12 @@ jobs: node-version: '18.x' registry-url: 'https://registry.npmjs.org' scope: '@artilleryio' - - run: PACKAGE_FOLDER_NAME=artillery node .github/workflows/scripts/rename-packages-to-correct-version.js + - run: node ./github/workflows/scripts/replace-worker-version-in-js-file.js + env: + COMMIT_SHA: ${{ github.sha }} + - run: node .github/workflows/scripts/rename-packages-to-correct-version.js + env: + PACKAGE_FOLDER_NAME: artillery - run: npm -w artillery publish --tag latest env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/scripts/replace-worker-version-in-js-file.js b/.github/workflows/scripts/replace-worker-version-in-js-file.js new file mode 100644 index 0000000000..666fb2812d --- /dev/null +++ b/.github/workflows/scripts/replace-worker-version-in-js-file.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const path = require('path'); + +const commitSha = process.env.COMMIT_SHA; + +const filePath = path.join( + __dirname, + '../../../packages/artillery/lib/platform/aws-ecs/legacy/constants.js' +); + +try { + let content = fs.readFileSync(filePath, 'utf8'); + + // This regex matches "const DEFAULT_IMAGE_TAG" followed by any characters, and then an equal sign and more characters + // until it reaches a semicolon or end of the line + const regex = /const DEFAULT_IMAGE_TAG\s*=\s*(['"])[^'"]*?\1/; + const replacement = `const DEFAULT_IMAGE_TAG = '${commitSha}'`; // Replace with commitSha in single quotes + content = content.replace(regex, replacement); + + // Write the modified content back to the file + fs.writeFileSync(filePath, content); + + // Verify by reading the content again and console logging it + const verifyContent = fs.readFileSync(filePath, 'utf8'); + console.log(verifyContent); + + if (!verifyContent.includes(commitSha)) { + throw new Error('Failed to replace commit SHA in JS file'); + } +} catch (error) { + console.error('Error occurred:', error); +} diff --git a/packages/artillery/lib/platform/aws-ecs/legacy/constants.js b/packages/artillery/lib/platform/aws-ecs/legacy/constants.js index 97beb889d9..142ff8351a 100644 --- a/packages/artillery/lib/platform/aws-ecs/legacy/constants.js +++ b/packages/artillery/lib/platform/aws-ecs/legacy/constants.js @@ -1,3 +1,4 @@ +// NOTE: if changing this, change replace-worker-version-in-js-file.js script in github workflows that looks for a specific pattern here. const DEFAULT_IMAGE_TAG = 'f7534a2844b58ee2a851081a3c498e671ad94f17'; module.exports = {