-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use js scripts to set output variables (#348)
- Loading branch information
Showing
13 changed files
with
182 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7.0.2 | ||
7.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* eslint-disable no-console */ | ||
import { getNbGitDiff } from './utils'; | ||
|
||
const JS_CLIENT_FOLDER = 'clients/algoliasearch-client-javascript'; | ||
|
||
/** | ||
* Exhaustive list of output variables to use in the CI. | ||
* | ||
* Those variables are used to determine if jobs should run, based on the changes | ||
* made in their respective `path`s. | ||
* | ||
* Negative paths should start with `:!`. | ||
* | ||
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`. | ||
*/ | ||
const VARIABLES_TO_CHECK = [ | ||
{ | ||
name: 'GITHUB_ACTIONS_CHANGED', | ||
path: ['.github/actions', '.github/workflows'], | ||
}, | ||
{ | ||
name: 'SPECS_CHANGED', | ||
path: ['specs', ':!specs/bundled'], | ||
}, | ||
{ | ||
name: 'COMMON_SPECS_CHANGED', | ||
path: ['specs/common'], | ||
}, | ||
{ | ||
name: 'TESTS_CHANGED', | ||
path: ['tests'], | ||
}, | ||
{ | ||
name: 'SCRIPTS_CHANGED', | ||
path: ['scripts'], | ||
}, | ||
{ | ||
name: 'GENERATORS_CHANGED', | ||
path: ['generators'], | ||
}, | ||
{ | ||
name: 'JS_CLIENT_CHANGED', | ||
path: [JS_CLIENT_FOLDER, `:!${JS_CLIENT_FOLDER}/.github`], | ||
}, | ||
{ | ||
name: 'JS_ALGOLIASEARCH_CHANGED', | ||
path: [ | ||
`${JS_CLIENT_FOLDER}/packages/algoliasearch`, | ||
`${JS_CLIENT_FOLDER}/packages/client-search`, | ||
`${JS_CLIENT_FOLDER}/packages/client-analytics`, | ||
`${JS_CLIENT_FOLDER}/packages/client-personalization`, | ||
], | ||
}, | ||
{ | ||
name: 'JS_COMMON_CHANGED', | ||
path: [ | ||
`${JS_CLIENT_FOLDER}/packages/client-common`, | ||
`${JS_CLIENT_FOLDER}/packages/requester-browser-xhr`, | ||
`${JS_CLIENT_FOLDER}/packages/requester-node-http`, | ||
], | ||
}, | ||
{ | ||
name: 'JS_COMMON_TESTS_CHANGED', | ||
path: [`${JS_CLIENT_FOLDER}/packages/client-common/src/__tests__`], | ||
}, | ||
{ | ||
name: 'JS_TEMPLATE_CHANGED', | ||
path: ['templates/javascript'], | ||
}, | ||
{ | ||
name: 'JAVA_CLIENT_CHANGED', | ||
path: ['clients/algoliasearch-client-java-2'], | ||
}, | ||
{ | ||
name: 'JAVA_TEMPLATE_CHANGED', | ||
path: ['templates/java'], | ||
}, | ||
{ | ||
name: 'PHP_CLIENT_CHANGED', | ||
path: ['clients/algoliasearch-client-php'], | ||
}, | ||
{ | ||
name: 'PHP_TEMPLATE_CHANGED', | ||
path: ['templates/php'], | ||
}, | ||
]; | ||
|
||
/** | ||
* Outputs variables used in the CI to determine if a job should run. | ||
*/ | ||
async function setRunVariables({ | ||
originBranch, | ||
}: { | ||
originBranch: string; | ||
}): Promise<void> { | ||
console.log(`Checking diff between ${originBranch} and HEAD`); | ||
|
||
for (const check of VARIABLES_TO_CHECK) { | ||
const diff = await getNbGitDiff({ | ||
branch: originBranch, | ||
path: check.path.join(' '), | ||
}); | ||
|
||
console.log(`Found ${diff} changes for '${check.name}'`); | ||
console.log(`::set-output name=${check.name}::${diff}`); | ||
} | ||
|
||
console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`); | ||
} | ||
|
||
if (require.main === module) { | ||
const [origin] = process.argv.slice(2); | ||
|
||
if (!origin) { | ||
throw new Error(`Unable to retrieve the origin: ${origin}`); | ||
} | ||
|
||
setRunVariables({ originBranch: origin }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { run } from '../common'; | ||
|
||
/** | ||
* Returns the number of diff between a `branch` and its `HEAD` for the given `path`. | ||
* Head defaults to `HEAD`, providing `null` will check unstaged changes. | ||
*/ | ||
export async function getNbGitDiff({ | ||
branch, | ||
head = 'HEAD', | ||
path, | ||
}: { | ||
branch: string; | ||
head?: string | null; | ||
path: string; | ||
}): Promise<number> { | ||
const checkHead = head === null ? '' : `...${head}`; | ||
|
||
return parseInt( | ||
( | ||
await run(`git diff --shortstat ${branch}${checkHead} -- ${path} | wc -l`) | ||
).trim(), | ||
10 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.