From d147b8cd714537d73774e96f4b508676afaa1ed5 Mon Sep 17 00:00:00 2001 From: Matthias Goudjil Date: Thu, 4 Jul 2024 12:38:40 +0200 Subject: [PATCH 1/4] feat: [pack:all command] - fix #354 - remove increment_versions script --- CONTRIBUTING.md | 4 +-- package.json | 2 +- scripts/create_packages_tars.sh | 6 ++++ scripts/increment_version.sh | 59 --------------------------------- 4 files changed, 9 insertions(+), 62 deletions(-) create mode 100755 scripts/create_packages_tars.sh delete mode 100755 scripts/increment_version.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 25786c9e..8020d95c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -175,7 +175,7 @@ You can specify the dependencies in the `package.json` file of your project as s ```json "dependencies": { - "@prestashopcorp/puik-components": "file:[path_to_tar]/prestashopcorp-puik-components-[0.0.x].tgz", - "@prestashopcorp/puik-resolver": "file:[path_to_tar]/prestashopcorp-puik-resolver-[0.0.x].tgz", + "@prestashopcorp/puik-components": "file:[path_to_tar]/prestashopcorp-puik-components-[x.x.x].tgz", + "@prestashopcorp/puik-resolver": "file:[path_to_tar]/prestashopcorp-puik-resolver-[x.x.x].tgz", } ``` diff --git a/package.json b/package.json index 66dbeafc..667f82a5 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "chromatic": "chromatic", "dev": "pnpm --filter @prestashopcorp/puik-playground dev", "component": "hygen component new", - "pack:all": "pnpm -r --parallel --filter './packages/**' exec pnpm pack --pack-destination ../../packages-tars/tmp && scripts/increment_version.sh", + "pack:all": "scripts/create_packages_tars.sh && pnpm -r --parallel --filter './packages/**' exec pnpm pack --pack-destination ../../packages-tars", "prepare": "husky install", "preinstall": "npx only-allow pnpm -y" }, diff --git a/scripts/create_packages_tars.sh b/scripts/create_packages_tars.sh new file mode 100755 index 00000000..80e7630c --- /dev/null +++ b/scripts/create_packages_tars.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Create packages-tars directory if it does not exist +if [ ! -d "./packages-tars" ]; then + mkdir -p "./packages-tars" +fi diff --git a/scripts/increment_version.sh b/scripts/increment_version.sh deleted file mode 100755 index ca4a5a1e..00000000 --- a/scripts/increment_version.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Path to the versions.json file -VERSIONS_FILE="./packages-tars/versions.json" - -# Create packages-tars and packages-tars/tmp directories if they don't exist -if [ ! -d "./packages-tars" ]; then - mkdir -p "./packages-tars" -fi - -if [ ! -d "./packages-tars/tmp" ]; then - mkdir -p "./packages-tars/tmp" -fi - -# Iterate over all .tgz files in packages-tars/tmp -for TGZ_PATH in ./packages-tars/tmp/*.tgz; do - # Extract the package name from the .tgz filename - PACKAGE_NAME=$(basename $TGZ_PATH | sed -n -e 's/^prestashopcorp-\(.*\)-0.0.1.tgz$/\1/p') - - echo "Processing $PACKAGE_NAME..." - - # Check if versions.json exists, if not, create it - if [ ! -f "$VERSIONS_FILE" ]; then - echo "Creating $VERSIONS_FILE..." - echo "{}" > $VERSIONS_FILE - fi - - # Read the current version of the package from versions.json - CURRENT_VERSION=$(grep -Po "\"$PACKAGE_NAME\": \"\K[^\"]+" $VERSIONS_FILE) - - # If no version is found, use 0.0.0 as default and add a new entry to versions.json - if [ -z "$CURRENT_VERSION" ]; then - echo "No current version found for $PACKAGE_NAME. Using 0.0.0 as default..." - CURRENT_VERSION="0.0.0" - # Add a comma if versions.json is not empty - if [ "$(cat $VERSIONS_FILE)" != "{}" ]; then - sed -i "s/}/, \"${PACKAGE_NAME}\": \"${CURRENT_VERSION}\"}/" $VERSIONS_FILE - else - echo "{\"$PACKAGE_NAME\": \"$CURRENT_VERSION\"}" > $VERSIONS_FILE - fi - fi - - echo "Current version of $PACKAGE_NAME is $CURRENT_VERSION." - - # Increment the version - IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" - VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1)) - NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}" - - echo "New version of $PACKAGE_NAME is $NEW_VERSION." - - # Update versions.json with the new version - echo "Updating $VERSIONS_FILE with new version for $PACKAGE_NAME..." - sed -i "s/\"$PACKAGE_NAME\": \"$CURRENT_VERSION\"/\"$PACKAGE_NAME\": \"$NEW_VERSION\"/" $VERSIONS_FILE - - # Move and rename the .tgz file - echo "Moving $TGZ_PATH to ./packages-tars/prestashopcorp-$PACKAGE_NAME-$NEW_VERSION.tgz..." - mv "$TGZ_PATH" "./packages-tars/prestashopcorp-$PACKAGE_NAME-$NEW_VERSION.tgz" -done From 7165cb5b1f5678fd4f35a7e383b27defd1ab8314 Mon Sep 17 00:00:00 2001 From: Matthias Goudjil Date: Thu, 4 Jul 2024 15:17:44 +0200 Subject: [PATCH 2/4] feat: [pack:all command] - related #354 - finally update increment_versions script --- package.json | 2 +- scripts/create_packages_tars.sh | 6 --- scripts/increment_versions.sh | 75 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 7 deletions(-) delete mode 100755 scripts/create_packages_tars.sh create mode 100755 scripts/increment_versions.sh diff --git a/package.json b/package.json index 667f82a5..618cbed7 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "chromatic": "chromatic", "dev": "pnpm --filter @prestashopcorp/puik-playground dev", "component": "hygen component new", - "pack:all": "scripts/create_packages_tars.sh && pnpm -r --parallel --filter './packages/**' exec pnpm pack --pack-destination ../../packages-tars", + "pack:all": "pnpm -r --parallel --filter './packages/**' exec pnpm pack --pack-destination ../../packages-tars/tmp && scripts/increment_versions.sh", "prepare": "husky install", "preinstall": "npx only-allow pnpm -y" }, diff --git a/scripts/create_packages_tars.sh b/scripts/create_packages_tars.sh deleted file mode 100755 index 80e7630c..00000000 --- a/scripts/create_packages_tars.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Create packages-tars directory if it does not exist -if [ ! -d "./packages-tars" ]; then - mkdir -p "./packages-tars" -fi diff --git a/scripts/increment_versions.sh b/scripts/increment_versions.sh new file mode 100755 index 00000000..a66e664f --- /dev/null +++ b/scripts/increment_versions.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Chemin vers le fichier versions.json +VERSIONS_FILE="./packages-tars/versions.json" + +# Créez les répertoires packages-tars et packages-tars/tmp s'ils n'existent pas +if [ ! -d "./packages-tars" ]; then + mkdir -p "./packages-tars" +fi + +if [ ! -d "./packages-tars/tmp" ]; then + mkdir -p "./packages-tars/tmp" +fi + +# Parcourez tous les fichiers .tgz dans packages-tars/tmp +for TGZ_PATH in ./packages-tars/tmp/*.tgz; do + # Extrait le nom du package du nom de fichier .tgz + PACKAGE_NAME=$(basename $TGZ_PATH | sed -n -e 's/^prestashopcorp-\(.*\)-[0-9]*\.[0-9]*\.[0-9]*\.tgz$/\1/p') + + echo "Traitement de $PACKAGE_NAME..." + + # Vérifie si versions.json existe, sinon, créez-le + if [ ! -f "$VERSIONS_FILE" ]; then + echo "Création de $VERSIONS_FILE..." + echo "{}" > $VERSIONS_FILE + fi + + # Lisez la version actuelle du package à partir de versions.json + CURRENT_VERSION=$(grep -Po "\"$PACKAGE_NAME\": \"\K[^\"]+" $VERSIONS_FILE) + + # Si aucune version n'est trouvée, utilisez 0.0.0-test-0 par défaut et ajoutez une nouvelle entrée à versions.json + if [ -z "$CURRENT_VERSION" ]; then + echo "Aucune version actuelle trouvée pour $PACKAGE_NAME. Utilisation de 0.0.0-test-0 par défaut..." + CURRENT_VERSION="0.0.0-test-0" + # Ajoutez une virgule si versions.json n'est pas vide + if [ "$(cat $VERSIONS_FILE)" != "{}" ]; then + sed -i "s/}/, \"${PACKAGE_NAME}\": \"${CURRENT_VERSION}\"}/" $VERSIONS_FILE + else + echo "{\"$PACKAGE_NAME\": \"$CURRENT_VERSION\"}" > $VERSIONS_FILE + fi + fi + + echo "La version actuelle de $PACKAGE_NAME est $CURRENT_VERSION." + + # Incrémentez la version + IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" + VERSION_BASE="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}" + + # Initialisez le suffixe de la version de test + TEST_VERSION_SUFFIX=0 + + # Vérifiez si la version de base a déjà un suffixe de test + if [[ $CURRENT_VERSION == *"-test-"* ]]; then + # Extrait le suffixe de la version de test + TEST_VERSION_SUFFIX=$(echo $CURRENT_VERSION | sed -n -e 's/^.*-test-\([0-9]*\)$/\1/p') + # Supprimez le suffixe de test existant de la version de base + VERSION_BASE=$(echo $VERSION_BASE | sed -n -e 's/^\(.*\)-test-.*$/\1/p') + fi + + # Incrémentez le suffixe de la version de test + TEST_VERSION_SUFFIX=$((TEST_VERSION_SUFFIX + 1)) + + # Construisez la nouvelle version + NEW_VERSION="${VERSION_BASE}-test-${TEST_VERSION_SUFFIX}" + + echo "La nouvelle version de $PACKAGE_NAME est $NEW_VERSION." + + # Mettez à jour versions.json avec la nouvelle version + echo "Mise à jour de $VERSIONS_FILE avec la nouvelle version pour $PACKAGE_NAME..." + sed -i "s/\"$PACKAGE_NAME\": \"$CURRENT_VERSION\"/\"$PACKAGE_NAME\": \"$NEW_VERSION\"/" $VERSIONS_FILE + + # Déplacez et renommez le fichier .tgz + echo "Déplacement de $TGZ_PATH vers ./packages-tars/prestashopcorp-$PACKAGE_NAME-$NEW_VERSION.tgz..." + mv "$TGZ_PATH" "./packages-tars/prestashopcorp-$PACKAGE_NAME-$NEW_VERSION.tgz" +done From eb05a2c449458b6d882360e19b4c76e4abaa9d9f Mon Sep 17 00:00:00 2001 From: Matthias Goudjil Date: Thu, 4 Jul 2024 16:30:15 +0200 Subject: [PATCH 3/4] feat: [pack:all command] - related #354 - update contributing doc --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8020d95c..2772c617 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -175,7 +175,7 @@ You can specify the dependencies in the `package.json` file of your project as s ```json "dependencies": { - "@prestashopcorp/puik-components": "file:[path_to_tar]/prestashopcorp-puik-components-[x.x.x].tgz", - "@prestashopcorp/puik-resolver": "file:[path_to_tar]/prestashopcorp-puik-resolver-[x.x.x].tgz", + "@prestashopcorp/puik-components": "file:[path_to_tar]/prestashopcorp-puik-components-0.0.0-test-[x].tgz", + "@prestashopcorp/puik-resolver": "file:[path_to_tar]/prestashopcorp-puik-resolver-0.0.0-test-[x].tgz", } ``` From ecc737f5ef71f42474f15c6fe9229955982b8a97 Mon Sep 17 00:00:00 2001 From: Matthias Goudjil Date: Thu, 4 Jul 2024 16:38:07 +0200 Subject: [PATCH 4/4] chore: [github-actions] - checks fails : try to update pnpm/action-setup to v4 --- .github/actions/build-and-publish/action.yml | 2 +- .github/workflows/cd-publish-beta-release.yml | 2 +- .github/workflows/cd-publish-release.yml | 2 +- .github/workflows/chromatic.yml | 2 +- .github/workflows/ci.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/actions/build-and-publish/action.yml b/.github/actions/build-and-publish/action.yml index 397f7bc7..551f4337 100644 --- a/.github/actions/build-and-publish/action.yml +++ b/.github/actions/build-and-publish/action.yml @@ -32,7 +32,7 @@ runs: # git config user.name "Github action" # npm version ${{ inputs.version }} --allow-same-version - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 - name: Setup node env 🏗 uses: actions/setup-node@v3 diff --git a/.github/workflows/cd-publish-beta-release.yml b/.github/workflows/cd-publish-beta-release.yml index b950f5b5..91356623 100644 --- a/.github/workflows/cd-publish-beta-release.yml +++ b/.github/workflows/cd-publish-beta-release.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v3 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: version: 9.1.2 diff --git a/.github/workflows/cd-publish-release.yml b/.github/workflows/cd-publish-release.yml index ed6be352..fa6abdab 100644 --- a/.github/workflows/cd-publish-release.yml +++ b/.github/workflows/cd-publish-release.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v3 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: version: 9.1.2 diff --git a/.github/workflows/chromatic.yml b/.github/workflows/chromatic.yml index ad867436..31dafdf9 100644 --- a/.github/workflows/chromatic.yml +++ b/.github/workflows/chromatic.yml @@ -30,7 +30,7 @@ jobs: node-version: 18 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: version: 9.1.2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9773b10d..8e33d811 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v3 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: version: 9.1.2