Skip to content
Snippets Groups Projects
Commit 41203e3d authored by Arno Rossouw's avatar Arno Rossouw
Browse files

5-INFRASTRUCTURE :: husky for auto versioning and build on dev when not tag

parent 1e1dae67
Branches
Tags
2 merge requests!201.0.41,!165-INFRASTRUCTURE :: husky for auto versioning and build on dev when not tag
*.pdf
node_modules
.git
package.json
.husky
package-lock.json
.distignore
make-zip.sh
update-version.js
.gitlab-ci.yml
.gitignore
node_modules
*.zip
......@@ -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
npm config set git-tag-version false && npm version patch && npm run update-version-files && git add package.json etc/module.xml 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.34",
"authors": [
{
"name": "Bob Go",
......
......@@ -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.34">
<sequence>
<module name="Magento_Webapi"/>
<module name="Magento_Catalog"/>
......
#!/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
{
"name": "bobgo-magento-plugin",
"description": "Bob Go magento plugin",
"version": "1.0.34",
"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"
}
}
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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment