From 7bef983184db4504b0b50ea8ca80a9aed596e9bc Mon Sep 17 00:00:00 2001 From: Marius Tobiassen Bungum Date: Fri, 29 Nov 2024 07:55:44 +0100 Subject: [PATCH 1/3] :hammer: Update install script so it works for projects where client folder isn't a thing --- config/install-deployment-files.sh | 13 +++++++------ config/install.sh | 31 +++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/config/install-deployment-files.sh b/config/install-deployment-files.sh index 7d202ff92..62412ba0e 100644 --- a/config/install-deployment-files.sh +++ b/config/install-deployment-files.sh @@ -3,15 +3,16 @@ printf -- "Running frontend configuration script\n" printf -- "-------------------------------------\n\n" -currentDir=$(basename "$PWD") - -if [ $currentDir != "client" ] +if [ ! -d ".github" ] then - printf -- "Not in ./client folder, moving to it...\n" - cd ./client || exit 1 + cd .. fi -cd .. +if [ ! -d ".github" ] +then + printf -- "Couldn't found .github folder, stopping...n\n" + exit 1 +fi printf -- "Downloading client github actions specific to deployment from github to radix...\n" workflowsList=$(curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/github_actions_deployment_list.txt") diff --git a/config/install.sh b/config/install.sh index b092a80d6..2c4cf214e 100644 --- a/config/install.sh +++ b/config/install.sh @@ -4,11 +4,16 @@ printf -- "Running frontend configuration script\n" printf -- "-------------------------------------\n\n" currentDir=$(basename "$PWD") - -if [ $currentDir != "client" ] +hasClientFolder=0 +if [ $currentDir != "client" ] && [ -d "client" ] +then + printf -- "Not in ./client folder, moving to it...\n\n" + cd ./client + hasClientFolder=1 +elif [ $currentDir !== "client" ] then - printf -- "Not in ./client folder, moving to it...\n" - cd ./client || exit 1 + printf -- "Not in client folder and client folder doesn't exist.\n" + printf -- "Downloading config files to where you are now\n\n" fi printf -- "Downloading config files...\n" @@ -80,17 +85,25 @@ do fi done -cd ../.. - printf -- "Going into root folder...\n" +if hasClientFolder -eq 1; then + cd ../.. +else + cd .. +fi printf -- "Downloading client github actions...\n" workflowsList=$(curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/github_actions_list.txt") +aclIgnorePath="./.acl-ignore" +if hasClientFolder -eq 1; then + aclIgnorePath="./client/.acl-ignore" +fi + for line in $workflowsList do fileName=$(echo $line | rev | cut -d '/' -f 1 | rev) - if grep -q $fileName "./client/.acl-ignore"; then + if grep -q $fileName $aclIgnorePath; then printf -- "$fileName in .acl-ignore, skipping...\n" else printf -- "Downloading $fileName file...\n" @@ -101,14 +114,14 @@ done printf -- "Generating .github/workflows/check_config.yaml...\n" bash <(curl -s https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/config_files/check_config_workflow/generate_check_config.sh) -if grep -q "CODEOWNERS" "./client/.acl-ignore"; then +if grep -q "CODEOWNERS" $aclIgnorePath; then printf -- "CODEOWNERS .acl-ignore, skipping...\n" else printf -- "Downloading CODEOWNERS file...\n" curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/config_files/CODEOWNERS" > .github/CODEOWNERS fi -if grep -q ".pre-commit-config.yaml" "./client/.acl-ignore"; then +if grep -q ".pre-commit-config.yaml" $aclIgnorePath; then printf -- ".pre-commit-config.yaml in .acl-ignore, skipping...\n" else printf -- "Downloading .pre-commit-config.yaml file...\n" From 83740e8f168ac5ad9d7848ee4925d27d1f3ab784 Mon Sep 17 00:00:00 2001 From: Marius Tobiassen Bungum Date: Fri, 29 Nov 2024 08:16:47 +0100 Subject: [PATCH 2/3] :hammer: Update build and use script so it works for both folder structures --- tooling/build-and-use.mjs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tooling/build-and-use.mjs b/tooling/build-and-use.mjs index 7703e3d90..cb90e36bc 100644 --- a/tooling/build-and-use.mjs +++ b/tooling/build-and-use.mjs @@ -1,6 +1,7 @@ import { runTask } from './taskrunner.mjs'; import chalk from 'chalk'; -import { readdir } from 'fs/promises'; +import { readdir} from 'fs/promises'; +import { existsSync } from 'fs'; import * as readline from 'node:readline/promises'; import { stdin as input, stdout as output } from 'node:process'; @@ -87,39 +88,44 @@ async function runTasks() { ) ); + let nodeModulesDir = `../${selectedDir}/node_modules` + if (existsSync(`../${selectedDir}/client`)) { + nodeModulesDir = `../${selectedDir}/client/node_modules` + } + await runTask({ - command: `rm -rf ../${selectedDir}/client/node_modules/.vite`, + command: `rm -rf ${nodeModulesDir}/.vite`, name: `Removing ${chalk.bold.greenBright( '.vite' )} folder from ${chalk.bold.greenBright( - `${selectedDir}/client/node_modules` + `${nodeModulesDir}` )}`, }); await runTask({ - command: `rm -rf ../${selectedDir}/client/node_modules/.cache`, + command: `rm -rf ${nodeModulesDir}/.cache`, name: `Removing ${chalk.bold.greenBright( '.cache' )} folder from ${chalk.bold.greenBright( - `${selectedDir}/client/node_modules` + `${nodeModulesDir}` )}`, }); await runTask({ - command: `rm -rf ../${selectedDir}/client/node_modules/@equinor/amplify-component-lib/dist`, + command: `rm -rf ${nodeModulesDir}/@equinor/amplify-component-lib/dist`, name: `Removing old ${chalk.bold.greenBright( 'amplify-component-lib/dist' )} folder from ${chalk.bold.greenBright( - `${selectedDir}/client/node_modules` + `${nodeModulesDir}` )}`, }); await runTask({ - command: `cp -r ./dist ../${selectedDir}/client/node_modules/@equinor/amplify-component-lib/dist`, + command: `cp -r ./dist ${nodeModulesDir}/@equinor/amplify-component-lib/dist`, name: `Copying newly built ${chalk.bold.greenBright( 'dist' )} folder into ${chalk.bold.greenBright( - `${selectedDir}/client/node_modules` + `${nodeModulesDir}` )}`, }); From cf22754d705721820aca06a1519742de97b12e29 Mon Sep 17 00:00:00 2001 From: Marius Tobiassen Bungum Date: Mon, 2 Dec 2024 14:12:59 +0100 Subject: [PATCH 3/3] :hammer: Update generate_check_config.sh so it works without client folder --- .../generate_check_config.sh | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/config/config_files/check_config_workflow/generate_check_config.sh b/config/config_files/check_config_workflow/generate_check_config.sh index 497d9b5b9..f84e74023 100644 --- a/config/config_files/check_config_workflow/generate_check_config.sh +++ b/config/config_files/check_config_workflow/generate_check_config.sh @@ -4,15 +4,38 @@ curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/co # Loop through the list from check_config/list.txt list=$(curl -s "https://raw.githubusercontent.com/equinor/amplify-component-lib/main/config/config_files/check_config_workflow/list.txt") +aclIgnorePath="./.acl-ignore" +if [ -d "client" ] +then + aclIgnorePath="./client/.acl-ignore" +fi + while read line; do read var1 var2 var3 <<< "$line" - if grep -q $var1 "./client/.acl-ignore"; then + if grep -q $var1 $aclIgnorePath; then printf -- "$var1 in .acl-ignore, skipping...\n" else + workingDir=$var2 + if [ ! -d "./client" ] + then + if [[ $var2 =~ "client/" ]] + then + workingDir=${var2#"client/"} + else + workingDir=${var2#"client"} + fi + fi + + if [[ $workingDir == "" ]] + then + workingDir="." + fi + + newLine=" - name: Compare remote $var1 to local - working-directory: $var2 + working-directory: $workingDir run: diff $var1 <(curl $var3)" echo "$newLine" >> ".github/workflows/check_config.yaml" fi