Skip to content

Commit

Permalink
ci(publish): pin dependant versions of packages to current ones (#2263)
Browse files Browse the repository at this point in the history
* ci(publish): pin dependant versions of packages to current ones

* ci(publish): remove old file

* refactor(publish): remove unnecessary variable
  • Loading branch information
bernardobridge authored Nov 1, 2023
1 parent 8ddaa8a commit dc13e3c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish-artillery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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-latest.js
- run: PACKAGE_FOLDER_NAME=artillery node .github/workflows/scripts/rename-packages-to-correct-version.js
- run: npm -w artillery publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish-int-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
scope: '@artilleryio'
- run: PACKAGE_FOLDER_NAME=core node .github/workflows/scripts/rename-packages-to-latest.js
- run: PACKAGE_FOLDER_NAME=core node .github/workflows/scripts/rename-packages-to-correct-version.js
- run: npm -w @artilleryio/int-core publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish-skytrace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
scope: '@artilleryio'
- run: PACKAGE_FOLDER_NAME=skytrace node .github/workflows/scripts/rename-packages-to-latest.js
- run: PACKAGE_FOLDER_NAME=skytrace node .github/workflows/scripts/rename-packages-to-correct-version.js
- run: npm install -w skytrace --ignore-scripts
- run: npm run build -w skytrace
- run: npm -w skytrace publish
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/scripts/rename-packages-to-correct-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const fs = require('fs');
const path = require('path');

const packageJsonRelativePath = `../../../packages/${process.env.PACKAGE_FOLDER_NAME}/package.json`;
const packageJsonFullPath = path.join(__dirname, packageJsonRelativePath);

if (!fs.existsSync(packageJsonFullPath)) {
throw new Error(
`Path ${packageJsonRelativePath} does not exist! Please ensure you pass the correct PACKAGE_FOLDER_NAME environment variable. Perhaps your folder name has changed?`
);
} else {
artilleryPackage = require(packageJsonRelativePath);
}

const updatePackageWithDependencies = (originalPackage) => {
const packagesDir = '../../../packages';
const finalPackage = { ...originalPackage };

const packageFolders = fs
.readdirSync(path.join(__dirname, packagesDir), { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);

packageFolders.forEach((folder) => {
const packageJsonRelativePath = `${packagesDir}/${folder}/package.json`;
const packageJsonFullPath = path.join(__dirname, packageJsonRelativePath);

if (!fs.existsSync(packageJsonFullPath)) {
throw new Error(
`Path ${packageJsonRelativePath} does not exist! Please ensure that it is a package!`
);
}

const packageData = fs.readFileSync(packageJsonFullPath);
const packageJson = JSON.parse(packageData);

if (
finalPackage.dependencies[packageJson.name] &&
finalPackage.dependencies[packageJson.name] == '*'
) {
console.log(
`Switching package ${packageJson.name} from ${
finalPackage.dependencies[packageJson.name]
} to version ${packageJson.version}`
);
finalPackage.dependencies[packageJson.name] = packageJson.version;
}
});

return finalPackage;
};

const modifiedPackage = updatePackageWithDependencies(artilleryPackage);

fs.writeFileSync(
`${packageJsonFullPath}`,
JSON.stringify(modifiedPackage, null, 2)
);
22 changes: 0 additions & 22 deletions .github/workflows/scripts/rename-packages-to-latest.js

This file was deleted.

0 comments on commit dc13e3c

Please sign in to comment.