Skip to content

Commit

Permalink
ci(publish): replace default image before npm latest publish
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobridge committed Jan 31, 2024
1 parent 1be8638 commit 7d6e8c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/npm-publish-artillery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
32 changes: 32 additions & 0 deletions .github/workflows/scripts/replace-worker-version-in-js-file.js
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down

0 comments on commit 7d6e8c9

Please sign in to comment.