diff --git a/.distignore b/.distignore new file mode 100644 index 0000000000000000000000000000000000000000..e06a04781c032573c660a3a26a7c9f47fd8bff93 --- /dev/null +++ b/.distignore @@ -0,0 +1,12 @@ +*.pdf +node_modules +.git +package.json +.husky +package-lock.json +.distignore +make-zip.sh +update-version.js +.gitlab-ci.yml +.gitignore +package diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..918863b01e95277a3617602cd1167911d287b815 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +*.zip diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index de5cdd5e509b31e9302f902adec4fb53deba29ed..bc49012c4a4845e2dab9257ac8c1ce1be67dd98b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,24 +4,20 @@ variables: GIT_SUBMODULE_STRATEGY: recursive stages: - - tagged_release + - deploy -tagged_deploy: - stage: tagged_release - only: - - tags +deploy: + stage: deploy before_script: - # - AWS_ACCESS_KEY_ID_KEY=$(echo "$AWS_ACCESS_KEY_ID") - # - AWS_SECRET_ACCESS_KEY_KEY=$(echo "$AWS_SECRET_ACCESS_KEY") - # - AWS_ACCESS_KEY_ID=$(eval echo -e "\$$AWS_ACCESS_KEY_ID_KEY") - # - AWS_SECRET_ACCESS_KEY=$(eval echo -e "\$$AWS_SECRET_ACCESS_KEY_KEY") - # - export AWS_ACCESS_KEY_ID - # - export AWS_SECRET_ACCESS_KEY + - AWS_ACCESS_KEY_ID_KEY=$(echo "$CI_COMMIT_BRANCH"_"AWS_ACCESS_KEY_ID") + - AWS_ACCESS_KEY_ID=$(eval echo -e "\$$AWS_ACCESS_KEY_ID_KEY") + - AWS_SECRET_ACCESS_KEY_KEY=$(echo "$CI_COMMIT_BRANCH"_"AWS_SECRET_ACCESS_KEY") + - AWS_SECRET_ACCESS_KEY=$(eval echo -e "\$$AWS_SECRET_ACCESS_KEY_KEY") + - export AWS_ACCESS_KEY_ID + - export AWS_SECRET_ACCESS_KEY script: - # - echo $AWS_ACCESS_KEY_ID - # - echo $AWS_SECRET_ACCESS_KEY - - wget https://gitlab.bob.co.za/bob-public-utils/bobgo-magento-extension/-/archive/"$CI_COMMIT_TAG"/bobgo-magento-extension-"$CI_COMMIT_TAG".tar.gz - - ls -al - - aws s3 cp bobgo-magento-extension-"$CI_COMMIT_TAG".tar.gz s3://bobgo-s3-magento-plugin/ --region=af-south-1 - allow_failure: false - when: on_success \ No newline at end of file + - ./make-zip.sh + - aws s3 cp bobgo-magento-plugin.zip s3://bobgo-s3-magento-plugin/ --region=af-south-1 + rules: + - if: '$CI_COMMIT_BRANCH == "dev" && $CI_COMMIT_TAG == null' + when: always diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000000000000000000000000000000000..0e8cbb02c99d4ef73e87ef96554f3c0f4e3db95f --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npm config set git-tag-version false && npm version patch && npm run update-version-files && git add package.json etc/module.xml composer.json diff --git a/composer.json b/composer.json index 637ad878c7781f367b045144816252b0b374fec8..7962a857ac079fc5976b0817776177a91217d93a 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "bobgo/bobgo-magento-extension", "description": "Smart shipping and order management solution in South Africa", "type": "magento2-module", - "version": "1.0.33", + "version": "1.0.36", "authors": [ { "name": "Bob Go", diff --git a/etc/module.xml b/etc/module.xml index fe2b36da4d6bad5e35cb60c85d1f1ff05d245001..6a1ae0446d58c5de0f866d2def4da1de736d17df 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -7,7 +7,7 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> - <module name="BobGroup_BobGo" setup_version="1.0.0"> + <module name="BobGroup_BobGo" setup_version="1.0.36"> <sequence> <module name="Magento_Webapi"/> <module name="Magento_Catalog"/> diff --git a/make-zip.sh b/make-zip.sh new file mode 100755 index 0000000000000000000000000000000000000000..6385066a926187eb2b6734463bd258256cd2cfe1 --- /dev/null +++ b/make-zip.sh @@ -0,0 +1,153 @@ +#!/bin/bash + +# Exit immediately if a command exits with a non-zero status +# +set -e + +# Function to log messages +log() { + echo "** $1" +} + +# Function to install jq if not installed +install_jq() { + if command -v jq >/dev/null 2>&1; then + log "jq is already installed." + else + log "jq is not installed. Attempting to install..." + + if [[ "$OSTYPE" == "darwin"* ]]; then + if command -v brew >/dev/null 2>&1; then + log "Installing jq using Homebrew..." + brew install jq + else + log "Homebrew is not installed. Please install Homebrew first:" + log "https://brew.sh/" + exit 1 + fi + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + if command -v apt-get >/dev/null 2>&1; then + log "Installing jq using apt-get..." + sudo apt-get update + sudo apt-get install -y jq + else + log "apt-get not found. Please install jq manually." + exit 1 + fi + else + log "Unsupported OS. Please install jq manually." + exit 1 + fi + + if command -v jq >/dev/null 2>&1; then + log "jq installed successfully." + else + log "Failed to install jq. Please install it manually." + exit 1 + fi + fi +} + +# Function to ensure Perl is installed +install_perl() { + if command -v perl >/dev/null 2>&1; then + log "Perl is already installed." + else + log "Perl is not installed. Please install Perl to proceed." + exit 1 + fi +} + +# Function to extract version using jq +get_version() { + if command -v jq >/dev/null 2>&1; then + jq -r '.version' package.json + else + # Fallback to grep and awk if jq is not available + grep '"version":' package.json | head -1 | awk -F'"' '{print $4}' + fi +} + +# Function to update the 'Version:' header in bobpay-plugin.php using Perl +update_version_header() { + local VERSION=$1 + local FILE="composer.json" + + log "Updating 'version:' header in ${FILE} using Perl..." + + # Use Perl to update the 'Version:' line + perl -pi -e "s/(\"version\":\s*\")([0-9.]+)(\"\,)/\${1}${VERSION}\"\,/g" "$FILE" + log "'version:' header updated to ${VERSION}." +} + +update_define_constant() { + local VERSION=$1 + local FILE="etc/module.xml" + + log "Updating 'version' constant in ${FILE} using Perl..." + + # Use Perl to replace the version constant + perl -pi -e "s/(setup_version=\")([^\"]*)/\${1}${VERSION}/g" "$FILE" + log "'setup_version' constant updated to ${VERSION}." +} + +# Function to build the plugin +build_plugin() { + log "Building plugin..." + npm install + log "Plugin built successfully." +} + +# Function to create the zip package +create_zip() { + local VERSION=$1 + local ZIPNAME="bobgo-magento-plugin.zip" + local PACKAGE_DIR="package" + + log "Creating zip file: ${ZIPNAME}..." + + # Remove any existing package directory and zip file + rm -rf "${PACKAGE_DIR}" + rm -f "${ZIPNAME}" + + # Create the package directory + mkdir -p "${PACKAGE_DIR}" + + # Use rsync to copy files, excluding those in .distignore + log "Copying files to package directory..." + rsync -av --exclude-from='.distignore' ./ "${PACKAGE_DIR}/" + + # Create the zip file from the package directory + log "Creating zip file..." + cd "${PACKAGE_DIR}" + zip -r "../${ZIPNAME}" . + cd .. + + # Clean up the package directory + log "Cleaning up..." + rm -rf "${PACKAGE_DIR}" + + log "Zip file '${ZIPNAME}' created successfully." +} + +# Main script execution +main() { + log "Starting build process..." + + install_jq + install_perl + + VERSION=$(get_version) + log "Extracted version: ${VERSION}" + + build_plugin + update_version_header "${VERSION}" + update_define_constant "${VERSION}" + create_zip "${VERSION}" + + log "Build process completed successfully." +} + +# Execute the main function +main + diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..91a85bc7c447aec7dc081156c1b6abb0fda08346 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "bobgo-magento-plugin", + "description": "Bob Go magento plugin", + "version": "1.0.36", + "license": "GPL-2.0-or-later", + "scripts": { + "prepare": "husky install", + "update-version-files": "node update-version.js" + }, + "husky": { + "hooks": { + "pre-commit": "npm config set git-tag-version false && npm version patch && npm run update-version-files && git add package.json etc/module.xml composer.json && pretty-quick --staged" + } + }, + "devDependencies": { + "husky": "^8.0.1", + "npm-run-all": "^4.1.5" + } +} diff --git a/update-version.js b/update-version.js new file mode 100644 index 0000000000000000000000000000000000000000..f5a9606305502bad56e35c586a0f27771e4d1c3c --- /dev/null +++ b/update-version.js @@ -0,0 +1,36 @@ +const fs = require('fs'); + +// Read version from package.json +const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); +const version = packageJson.version; + +// Files to update +const filesToUpdate = ['composer.json', 'etc/module.xml']; + +// Function to update version in files +function updateVersionInFile(filePath) { + let content = fs.readFileSync(filePath, 'utf8'); + + if (filePath === 'composer.json') { + // Update the Version header in the plugin file + // Update the version in composer.json + content = content.replace( + /(\"version\":\s*\")([0-9.]+)(\"\,)/g, + `$1${version}$3` + ); + } + + if (filePath === 'etc/module.xml') { + // Update the version tag in etc/module.xml + content = content.replace( + /(setup_version=")([^"]*)/g, + `$1${version}` + ); + + } + + fs.writeFileSync(filePath, content); +} + +// Update each file +filesToUpdate.forEach(updateVersionInFile);