diff --git a/package.json b/package.json index df2e6c9c1..b7c62434f 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,7 @@ "_format": "prettier '**/*.{ts,tsx,json,md}'", "format": "yarn _format --write", "format:check": "yarn _format --list-different", - "link_inhouse_deps": "ts-node --skip-project src/bin/link_inhouse_deps.ts", - "emails_domain_accept_list_helper": "ts-node --skip-project src/bin/emails_domain_accept_list_helper.ts" + "emails-domain-accept-list-helper": "ts-node --skip-project src/bin/emails-domain-accept-list-helper.ts" }, "dependencies": { "onyxia-ui": "^1.0.0", diff --git a/src/bin/emails_domain_accept_list_helper.ts b/scripts/emails-domain-accept-list-helper.ts similarity index 96% rename from src/bin/emails_domain_accept_list_helper.ts rename to scripts/emails-domain-accept-list-helper.ts index 12f4144d1..a9d98f3ba 100644 --- a/src/bin/emails_domain_accept_list_helper.ts +++ b/scripts/emails-domain-accept-list-helper.ts @@ -5,7 +5,7 @@ import { emailDomainsToRegExpStr, regExpStrToEmailDomains -} from "keycloak-theme/login/emailDomainAcceptListHelper"; +} from "../src/keycloak-theme/login/emailDomainAcceptListHelper"; const emailDomains = regExpStrToEmailDomains( "^[^@]+@([^.]+\\.)*((insee\\.fr)|(gouv\\.fr)|(polytechnique\\.edu)|(ensae\\.fr)|(ensai\\.fr)|(centralesupelec\\.fr)|(student-cs\\.fr)|(student\\.ecp\\.fr)|(supelec\\.fr)|(ign\\.fr)|(has-sante\\.fr)|(casd\\.eu)|(ars\\.sante\\.fr)|(ansm\\.sante\\.fr)|(cnaf\\.fr)|(ac-lille\\.fr)|(ac-amiens\\.fr)|(ac-normandie\\.fr)|(ac-reims\\.fr)|(ac-nancy-metz\\.fr)|(ac-strasbourg\\.fr)|(ac-creteil\\.fr)|(ac-paris\\.fr)|(nantesmetropole\\.fr)|(ac-versailles\\.fr)|(ac-rennes\\.fr)|(ac-nantes\\.fr)|(ac-orleans-tours\\.fr)|(ac-dijon\\.fr)|(ac-besancon\\.fr)|(ac-poitiers\\.fr)|(ac-limoges\\.fr)|(ac-clermont\\.fr)|(ac-lyon\\.fr)|(ac-grenoble\\.fr)|(ac-bordeaux\\.fr)|(ac-toulouse\\.fr)|(ac-montpellier\\.fr)|(ac-aix-marseille\\.fr)|(ac-nice\\.fr)|(ac-corse\\.fr)|(ac-martinique\\.fr)|(ac-guadeloupe\\.fr)|(ac-reunion\\.fr)|(ac-guyane\\.fr)|(ac-mayotte\\.fr)|(ac-wf\\.wf)|(monvr\\.pf)|(anfr\\.fr)|(ccomptes\\.fr)|(ac-noumea\\.nc)|(ac-spm\\.fr)|(inrae\\.fr)|(inria\\.fr)|(irsn\\.fr)|(assemblee-nationale\\.fr)|(hceres\\.fr)|(ext\\.ec\\.europa\\.eu)|(health-data-hub\\.fr)|(datactivist\\.coop)|(inpi\\.fr)|(telecom-paris\\.fr)|(ineris\\.fr)|(cerema\\.fr)|(cnrs\\.fr)|(univ-paris1\\.fr)|(ens-paris-saclay\\.fr)|(ens\\.fr)|(ens-lyon\\.fr)|(cereq\\.fr)|(univ-eiffel\\.fr)|(chu-toulouse\\.fr))$" diff --git a/scripts/update-api.sh b/scripts/update-api.sh new file mode 100755 index 000000000..fc438dec7 --- /dev/null +++ b/scripts/update-api.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Find the repository root by looking for the .git directory +while [[ ! -d ".git" && "$PWD" != "/" ]]; do + cd .. +done + +if [[ ! -d ".git" ]]; then + echo "Error: Run this script from the root of the project" + exit 1 +fi + +git submodule update --init --recursive &>/dev/null + +# Assuming api/ is a submodule at the repository root +API_SUBMODULE="api" + +# Navigate to the submodule directory +cd $API_SUBMODULE + +# Fetch all tags from remote +git fetch --tags &>/dev/null + +# Get the latest tag name +latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) + +currentTag=$(git describe --tags $(git rev-parse HEAD)) + +# Check if the latest tag points to the current commit +if [ "$latestTag" == "$currentTag" ]; then + echo "Onyxia API is alredy pinned to the latest version: $latestTag" + exit 0 +fi + +# Checkout the latest tag +git checkout $latestTag &>/dev/null + +# Navigate back to the main repository directory +cd .. + +# Add the submodule change +git add $API_SUBMODULE + +# Ask for user confirmation +read -p "Do you want to pin onyxia-api to $latestTag (Currently pinned is $currentTag)? " \ +"This will trigger a new release of the Onyxia Helm Chart once pushed. " \ +"Press 'y' then Enter to confirm: " -n 1 -r +echo # Move to a new line + +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Abort. Changes not committed." + exit 1 +fi + +# Commit the update +git commit -m "Bump onyxia-api pin to $latestTag (previously pinned to $currentTag)" + +echo "Done. Don't forget to push the changes to the remote repository. 👋" diff --git a/src/bin/link_inhouse_deps.ts b/src/bin/link_inhouse_deps.ts deleted file mode 100644 index c0810c170..000000000 --- a/src/bin/link_inhouse_deps.ts +++ /dev/null @@ -1,212 +0,0 @@ -/* eslint-disable @typescript-eslint/no-non-null-assertion */ - -/* -This script enable to link the module we develop inhouse ("onyxia-ui", "powerhooks", "tss-react", "evt"). -Without it, if we want for example to add a new component to onyxia-ui we have publish a new version -before being able to test it in the project. - -By default the script will link all the libraries we have control over, -so, if you like to link them all, you should have the following directory structure - -onyxia-web/ -tss-react/ -powerhooks/ -onyxia-ui/ -keycloakify/ -evt/ -cra-envs/ -tsafe/ -redux-clean-architecture/ -i18nifty/ - -you must have cloned all the projects and run: -yarn && yarn build -in every directory. - -then after you can -cd onyxia-web -yarn link_inhouse_deps - -If you only want to link some specific package you can do, for example: -yarn link_inhouse_deps onyxia-ui tss-react - -When you change what's linked it is a good idea to first: -rm -rf node_modules .yarn_home -yarn - -In the repo you are working on (for example onyxia-ui) you probably want to run -npx tsc -w -to enable realtime compilation. -*/ -import { execSync } from "child_process"; -import { join as pathJoin, relative as pathRelative } from "path"; -import * as fs from "fs"; - -const webAppProjectRootDirPath = pathJoin(__dirname, "..", ".."); - -const inHouseModulePeerDepNames = ["powerhooks", "tss-react"]; - -const inHouseModuleNames = (() => { - const inHouseModuleNamesFromArgv = process.argv.slice(2); - - return inHouseModuleNamesFromArgv.length !== 0 - ? inHouseModuleNamesFromArgv - : [ - ...inHouseModulePeerDepNames, - "onyxia-ui", - "keycloakify", - "evt", - "tsafe", - "cra-envs", - "redux-clean-architecture", - "i18nifty" - ]; -})(); - -console.log(`Linking following modules: ${inHouseModuleNames.join(" ")}`); - -const commonThirdPartyDeps = (() => { - const namespaceModuleNames = ["@emotion", "@mui"]; - const standaloneModuleNames = [ - "react", - "@types/react", - ...inHouseModulePeerDepNames.filter( - moduleName => !inHouseModuleNames.includes(moduleName) - ) - ]; - - return [ - ...namespaceModuleNames - .map(namespaceModuleName => - fs - .readdirSync( - pathJoin( - webAppProjectRootDirPath, - "node_modules", - namespaceModuleName - ) - ) - .map(submoduleName => `${namespaceModuleName}/${submoduleName}`) - ) - .reduce((prev, curr) => [...prev, ...curr], []), - ...standaloneModuleNames - ]; -})(); - -const yarnHomeDirPath = pathJoin(webAppProjectRootDirPath, ".yarn_home"); - -execSync(["rm -rf", "mkdir"].map(cmd => `${cmd} ${yarnHomeDirPath}`).join(" && ")); - -const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => { - const { targetModuleName, cwd } = params; - - const cmd = [ - "yarn", - "link", - ...(targetModuleName !== undefined ? [targetModuleName] : []) - ].join(" "); - - console.log(`$ cd ${pathRelative(webAppProjectRootDirPath, cwd) || "."} && ${cmd}`); - - execSync(cmd, { - cwd, - "env": { - ...process.env, - "HOME": yarnHomeDirPath - } - }); -}; - -console.log("=== Linking common dependencies ==="); - -const total = commonThirdPartyDeps.length; -let current = 0; - -commonThirdPartyDeps.forEach(commonThirdPartyDep => { - current++; - - console.log(`${current}/${total} ${commonThirdPartyDep}`); - - const localInstallPath = pathJoin( - ...[ - webAppProjectRootDirPath, - "node_modules", - ...(commonThirdPartyDep.startsWith("@") - ? commonThirdPartyDep.split("/") - : [commonThirdPartyDep]) - ] - ); - - execYarnLink({ "cwd": localInstallPath }); - - inHouseModuleNames.forEach(inHouseModuleName => - execYarnLink({ - "targetModuleName": commonThirdPartyDep, - "cwd": pathJoin(webAppProjectRootDirPath, "..", inHouseModuleName) - }) - ); -}); - -console.log("=== Linking in house dependencies ==="); - -inHouseModuleNames.forEach(inHouseModuleName => { - const inHouseModuleRootPath = pathJoin( - webAppProjectRootDirPath, - "..", - inHouseModuleName - ); - - fs.writeFileSync( - pathJoin(inHouseModuleRootPath, "dist", "package.json"), - Buffer.from( - JSON.stringify( - (() => { - const packageJsonParsed = JSON.parse( - fs - .readFileSync(pathJoin(inHouseModuleRootPath, "package.json")) - .toString("utf8") - ); - - return { - ...packageJsonParsed, - "main": packageJsonParsed["main"].replace(/^dist\//, ""), - "types": packageJsonParsed["types"].replace(/^dist\//, "") - }; - })(), - null, - 2 - ), - "utf8" - ) - ); -}); - -inHouseModuleNames.forEach(inHouseModuleName => - execYarnLink({ - "cwd": pathJoin(webAppProjectRootDirPath, "..", inHouseModuleName, "dist") - }) -); - -console.log("=== Linking in house dependencies to one another ==="); - -inHouseModuleNames.forEach(inHouseModuleNameOuter => - inHouseModuleNames - .filter( - inHouseModuleNameInner => inHouseModuleNameInner !== inHouseModuleNameOuter - ) - .forEach(inHouseModuleNameInner => - execYarnLink({ - "targetModuleName": inHouseModuleNameInner, - "cwd": pathJoin(webAppProjectRootDirPath, "..", inHouseModuleNameOuter) - }) - ) -); - -console.log("=== Linking in house dependencies in web app ==="); - -inHouseModuleNames.forEach(inHouseModuleName => { - execYarnLink({ - "targetModuleName": inHouseModuleName, - "cwd": webAppProjectRootDirPath - }); -});