Use script on pipeline

This commit is contained in:
Adria Navarro 2024-07-02 11:48:01 +02:00
parent e14c569aa4
commit 8e4ccdcb95
2 changed files with 17 additions and 12 deletions

View File

@ -141,7 +141,7 @@ jobs:
- name: Test worker - name: Test worker
run: | run: |
if ${{ env.ONLY_AFFECTED_TASKS }}; then if ${{ env.ONLY_AFFECTED_TASKS }}; then
yarn test --scope=@budibase/worker --since=${{ env.NX_BASE_BRANCH }} node scripts/run-affected.js --task=test --scope=@budibase/worker --since=${{ env.NX_BASE_BRANCH }}
else else
yarn test --scope=@budibase/worker yarn test --scope=@budibase/worker
fi fi
@ -181,7 +181,7 @@ jobs:
- name: Test server - name: Test server
run: | run: |
if ${{ env.ONLY_AFFECTED_TASKS }}; then if ${{ env.ONLY_AFFECTED_TASKS }}; then
yarn test --scope=@budibase/server --since=${{ env.NX_BASE_BRANCH }} node scripts/run-affected.js --task=test --scope=@budibase/server --since=${{ env.NX_BASE_BRANCH }}
else else
yarn test --scope=@budibase/server yarn test --scope=@budibase/server
fi fi

View File

@ -1,12 +1,17 @@
/***
* Running lerna with since and scope is not working as expected.
* For example, running the command `yarn test --scope=@budibase/worker --since=master`, with changes only on @budibase/backend-core will not work, as it does not analyse the dependencies properly.
*
* This script is using `lerna ls` to detect all the affected projects from a given commit, and if the scoped package is affected, the actual command will be executed
*
* The current version of the script only supports a single project in the scope.
*/
const { execSync } = require("child_process") const { execSync } = require("child_process")
const argv = require("yargs").demandOption([ const argv = require("yargs").demandOption(["task", "since", "scope"]).argv
"task",
"since",
"package-name",
]).argv
const { task, since, packageName } = argv const { task, since, scope } = argv
const affectedPackages = execSync( const affectedPackages = execSync(
`yarn --silent lerna ls --since=${since} --json`, `yarn --silent lerna ls --since=${since} --json`,
@ -17,13 +22,13 @@ const affectedPackages = execSync(
const packages = JSON.parse(affectedPackages) const packages = JSON.parse(affectedPackages)
const isAffected = packages.some(pkg => pkg.name === packageName) const isAffected = packages.some(pkg => pkg.name === scope)
if (isAffected) { if (isAffected) {
console.log(`${packageName} is affected. Running ${task}...`) console.log(`${scope} is affected. Running task "${task}"`)
execSync(`yarn ${task} --scope=${packageName}`, { execSync(`yarn ${task} --scope=${scope}`, {
stdio: "inherit", stdio: "inherit",
}) })
} else { } else {
console.log(`${packageName} is not affected. Skipping ${task}...`) console.log(`${scope} is not affected. Skipping task "${task}"`)
} }