Skip to content

Commit

Permalink
Merge pull request #355 from PrestaShopCorp/354-bug-pack-script-remov…
Browse files Browse the repository at this point in the history
…e-increment_version-script-for-pack-all-command

feat: [pack:all command] - fix #354 - update increment_versions script
  • Loading branch information
mattgoud authored Jul 4, 2024
2 parents e284bce + ecc737f commit 4ac28f2
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/actions/build-and-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-publish-beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-0.0.0-test-[x].tgz",
"@prestashopcorp/puik-resolver": "file:[path_to_tar]/prestashopcorp-puik-resolver-0.0.0-test-[x].tgz",
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "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"
},
Expand Down
59 changes: 0 additions & 59 deletions scripts/increment_version.sh

This file was deleted.

75 changes: 75 additions & 0 deletions scripts/increment_versions.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4ac28f2

Please sign in to comment.