-
Notifications
You must be signed in to change notification settings - Fork 4
NEW @W-19365711@ Converted package versioning enforcement to git hooks #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ec3f9ad
f88bd81
79825ed
2dfee6f
2e436f9
dc74950
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,5 @@ dist/ | |
| coverage/ | ||
| *.tsbuildinfo | ||
| *.tgz | ||
| .sfdx | ||
| .sfdx | ||
| .scratchfile | ||
| 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]); | ||
|
|
@@ -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) { | ||
|
|
@@ -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 semantically behind 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'); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.