Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/verify-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,21 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- run: npm install
- name: Validate that changed packages are versioned as snapshots
if: ${{ needs.check_for_postrelease_keyword.outputs.is-postrelease == 'false' }}
run: |
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
git diff --name-only $HEAD_SHA $BASE_SHA > changed_files.txt
node ./.github/workflows/verify-pr/validate-changed-package-versions.js changed_files.txt
git diff --name-only $HEAD_SHA $BASE_SHA > `pwd`/changed_files.txt
node ./.node-scripts/validate-changed-package-versions.js `pwd`/changed_files.txt
Comment on lines +58 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the husky precommit stuff... do you want to also update these to use the .scatchfile as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but it doesn't matter terribly because there's no chance of the file being committed or anything like that.

- name: Validate that packages properly depend on each other
if: ${{ needs.check_for_postrelease_keyword.outputs.is-postrelease == 'false' }}
run: |
cd packages
PACKAGE_NAMES=`ls`
cd ..
node ./.github/workflows/verify-pr/validate-package-interdependencies.js "$PACKAGE_NAMES"
node ./.node-scripts/validate-package-interdependencies.js "$PACKAGE_NAMES"
run_tests:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dist/
coverage/
*.tsbuildinfo
*.tgz
.sfdx
.sfdx
.scratchfile
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
git diff --name-only --cached --diff-filter=ACMR > `pwd`/.scratchfile
node ./.node-scripts/validate-changed-package-versions.js `pwd`/.scratchfile
cd packages
PACKAGE_NAMES=`ls`
cd ..
node ./.node-scripts/validate-package-interdependencies.js "$PACKAGE_NAMES"
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const path = require('path');
const fs = require('fs');
const cp = require('child_process');
const semver = require('semver');

function main() {
const changedFiles = readChangedFilesFile(process.argv[2]);
Expand Down Expand Up @@ -39,7 +41,7 @@ function displayList(header, list) {
}

function readChangedFilesFile(changedFilesFileName) {
return fs.readFileSync(path.join(__dirname, '..', '..', '..', changedFilesFileName), 'utf-8').split('\n').map(s => s.trim());
return fs.readFileSync(changedFilesFileName, 'utf-8').split('\n').map(s => s.trim());
}

function identifyMeaningfullyChangedPackages(changedFiles) {
Expand Down Expand Up @@ -74,18 +76,31 @@ function isFileInTestFolder(changedFile) {
function identifyIncorrectlyVersionedPackages(changedPackages) {
const incorrectlyVersionedPackages = [];
for (const changedPackage of changedPackages) {
//A temporary workaround for the rename of the flowtest-engine package to flow-engine
if (changedPackage === 'packages/code-analyzer-flowtest-engine') {
continue;
}
const packageVersion = getPackageVersion(changedPackage);
if (!packageVersion.endsWith('-SNAPSHOT')) {
incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) lacks a trailing "-SNAPSHOT"`);
continue;
}
const releasedPackageVersion = getLatestReleasedVersion(changedPackage);
if (semver.lte(semver.parse(packageVersion.slice(0, packageVersion.length - 9)), semver.parse(releasedPackageVersion))) {
incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) is not semantically ahead of latest published release ${releasedPackageVersion}`);
}
}
return incorrectlyVersionedPackages;
}

function getLatestReleasedVersion(changedPackage) {
const publishedPackageName = JSON.parse(fs.readFileSync(path.join(changedPackage, 'package.json'), 'utf-8')).name;
try {

return cp.execSync(`npm view ${publishedPackageName} version`, {
encoding: 'utf-8'
});
} catch (e) {
console.log(`NOTE: Could not fetch latest release version of ${publishedPackageName} (located in ${changedPackage}). Is that an error?`);
return undefined;
}
}

function getPackageVersion(changedPackage) {
const packageJsonPath = path.join(changedPackage, 'package.json');
Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
"scrub": "npm run clean && npm run scrub --workspaces --if-present && rimraf node_modules && rimraf package-lock.json",
"showcoverage-java": "npm run showcoverage-java --workspaces --if-present",
"showcoverage-typescript": "open ./coverage/lcov-report/index.html",
"showcoverage": "npm run showcoverage-java && npm run showcoverage-typescript"
"showcoverage": "npm run showcoverage-java && npm run showcoverage-typescript",
"prepare": "husky"
},
"devDependencies": {
"cross-env": "^10.0.0",
"husky": "^9.1.7",
"jest": "^30.0.5",
"rimraf": "^6.0.1",
"semver": "^7.7.2",
"ts-jest": "^29.4.1"
},
"jest": {
Expand Down
Loading