From 8e4ccdcb9598b6aad7f7a54f95cf436012f4fb1c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 2 Jul 2024 11:48:01 +0200 Subject: [PATCH] Use script on pipeline --- .github/workflows/budibase_ci.yml | 4 ++-- scripts/run-affected.js | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/budibase_ci.yml b/.github/workflows/budibase_ci.yml index 050417144e..86fd4f6799 100644 --- a/.github/workflows/budibase_ci.yml +++ b/.github/workflows/budibase_ci.yml @@ -141,7 +141,7 @@ jobs: - name: Test worker run: | 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 yarn test --scope=@budibase/worker fi @@ -181,7 +181,7 @@ jobs: - name: Test server run: | 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 yarn test --scope=@budibase/server fi diff --git a/scripts/run-affected.js b/scripts/run-affected.js index 051c61f114..3e7f9bed03 100755 --- a/scripts/run-affected.js +++ b/scripts/run-affected.js @@ -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 argv = require("yargs").demandOption([ - "task", - "since", - "package-name", -]).argv +const argv = require("yargs").demandOption(["task", "since", "scope"]).argv -const { task, since, packageName } = argv +const { task, since, scope } = argv const affectedPackages = execSync( `yarn --silent lerna ls --since=${since} --json`, @@ -17,13 +22,13 @@ const affectedPackages = execSync( const packages = JSON.parse(affectedPackages) -const isAffected = packages.some(pkg => pkg.name === packageName) +const isAffected = packages.some(pkg => pkg.name === scope) if (isAffected) { - console.log(`${packageName} is affected. Running ${task}...`) - execSync(`yarn ${task} --scope=${packageName}`, { + console.log(`${scope} is affected. Running task "${task}"`) + execSync(`yarn ${task} --scope=${scope}`, { stdio: "inherit", }) } else { - console.log(`${packageName} is not affected. Skipping ${task}...`) + console.log(`${scope} is not affected. Skipping task "${task}"`) }