This commit is contained in:
mydev committed 2026-11-25 04:59:49 +02:00
1 parent 80345d8633
commit 3dcd120ff3
3 files changed
+1282 -91

No files matched your search

+367 -41
View File
@@ -4,65 +4,391 @@ on:
push:
branches:
- main
tags:
- "v*"
workflow_dispatch:
inputs:
publish_release:
description: "Publish or replace the release for this version"
required: true
type: boolean
default: false
jobs:
build-release:
build:
name: Validate and package extension
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: Checkout repository
uses: actions/checkout@v4
- name: Install XML tools
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libxml2-utils zip
sudo apt-get install -y \
jq \
libxml2-utils \
zip \
unzip \
php-cli
- name: Extract metadata from install.xml
id: meta
- name: Validate and build package
id: package
shell: bash
run: |
CODE=$(xmllint --xpath "string(//code)" install.xml)
VERSION=v$(xmllint --xpath "string(//version)" install.xml)
set -Eeuo pipefail
echo "CODE=$CODE" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "FILENAME=${CODE}_${VERSION}.ocmod.zip" >> $GITHUB_ENV
CONFIG=".oc-extension.json"
echo "Extension code: $CODE"
if [[ ! -f "$CONFIG" ]]; then
echo "::error::Missing .oc-extension.json"
exit 1
fi
PLATFORM="$(jq -er '.platform' "$CONFIG")"
CODE="$(jq -er '.code' "$CONFIG")"
if [[ ! "$CODE" =~ ^[a-z0-9_]+$ ]]; then
echo "::error::Invalid extension code: $CODE"
exit 1
fi
mkdir -p build/package
case "$PLATFORM" in
oc3)
echo "Target platform: OpenCart 3"
if [[ ! -f install.xml ]]; then
echo "::error::OC3 requires install.xml"
exit 1
fi
if [[ -f install.json ]]; then
echo "::error::OC3 repository must not contain install.json"
exit 1
fi
if [[ ! -d upload ]]; then
echo "::error::OC3 requires an upload/ directory"
exit 1
fi
xmllint --noout install.xml
XML_CODE="$(xmllint --xpath \
'string(/modification/code)' install.xml)"
VERSION="$(xmllint --xpath \
'string(/modification/version)' install.xml)"
if [[ "$XML_CODE" != "$CODE" ]]; then
echo "::error::Configured code does not match install.xml"
exit 1
fi
if [[ -z "$VERSION" ]]; then
echo "::error::Missing version in install.xml"
exit 1
fi
if [[ ! "$VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Invalid extension version: $VERSION"
exit 1
fi
EMPTY_PATHS="$(xmllint --xpath \
'count(//file[not(normalize-space(@path))])' install.xml)"
EMPTY_SEARCHES="$(xmllint --xpath \
'count(//search[not(normalize-space(string(.)))])' install.xml)"
EMPTY_ADDS="$(xmllint --xpath \
'count(//add[not(normalize-space(string(.)))])' install.xml)"
if [[ "$EMPTY_PATHS" != "0" ]]; then
echo "::error::install.xml contains an empty file path"
exit 1
fi
if [[ "$EMPTY_SEARCHES" != "0" || "$EMPTY_ADDS" != "0" ]]; then
echo "::error::install.xml contains an empty search or add operation"
exit 1
fi
cp install.xml build/package/
cp -a upload build/package/
for FILE in install.php install.sql; do
if [[ -f "$FILE" ]]; then
cp "$FILE" build/package/
fi
done
;;
oc4)
echo "Target platform: OpenCart 4"
if [[ ! -f install.json ]]; then
echo "::error::OC4 requires install.json"
exit 1
fi
if [[ -f install.xml ]]; then
echo "::error::OC4 repository must not contain install.xml"
exit 1
fi
jq -e '
(.name | type == "string" and length > 0) and
(.version | type == "string" and length > 0) and
(.author | type == "string" and length > 0) and
(.link | type == "string" and length > 0)
' install.json >/dev/null
VERSION="$(jq -er '.version' install.json)"
if [[ ! "$VERSION" =~ ^[0-9]+(\.[0-9]+){1,2}([.-][0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Invalid extension version: $VERSION"
exit 1
fi
MIN_VERSION="$(jq -r '.minimum_version // "4.0.0"' "$CONFIG")"
if [[ ! "$MIN_VERSION" =~ ^4\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid OC4 minimum_version: $MIN_VERSION"
exit 1
fi
if [[ "$MIN_VERSION" == "4.0.0" || "$MIN_VERSION" == "4.0.1" ]]; then
if [[ -d ocmod ]]; then
echo "::error::OC4.0.0/4.0.1 targets must not contain OCMOD XML"
exit 1
fi
fi
FOUND_DIR=false
for DIR in admin catalog system ocmod; do
if [[ -d "$DIR" ]]; then
cp -a "$DIR" build/package/
FOUND_DIR=true
fi
done
if [[ "$FOUND_DIR" != "true" ]]; then
echo "::error::No OC4 extension directories found"
exit 1
fi
cp install.json build/package/
if [[ -d ocmod ]]; then
mapfile -t OCMOD_FILES < <(
find ocmod -type f -name '*.ocmod.xml' -print
)
if [[ ${#OCMOD_FILES[@]} -eq 0 ]]; then
echo "::error::ocmod/ exists but contains no *.ocmod.xml files"
exit 1
fi
for XML_FILE in "${OCMOD_FILES[@]}"; do
xmllint --noout "$XML_FILE"
done
fi
;;
*)
echo "::error::Unsupported platform: $PLATFORM"
exit 1
;;
esac
# PHP syntax validation
while IFS= read -r -d '' PHP_FILE; do
echo "Checking PHP: $PHP_FILE"
php -l "$PHP_FILE"
done < <(find build/package -type f -name '*.php' -print0)
# Package files from the package root
ZIP_NAME="${CODE}_v${VERSION}.ocmod.zip"
mkdir -p dist
(
cd build/package
zip -qr "../../dist/$ZIP_NAME" .
)
# ZIP integrity
unzip -t "dist/$ZIP_NAME"
# SHA-256 checksum
(
cd dist
sha256sum "$ZIP_NAME" > "$ZIP_NAME.sha256"
)
echo "platform=$PLATFORM" >> "$GITHUB_OUTPUT"
echo "code=$CODE" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "zip_name=$ZIP_NAME" >> "$GITHUB_OUTPUT"
echo "Package created: dist/$ZIP_NAME"
echo "Platform: $PLATFORM"
echo "Version: $VERSION"
- name: Prepare package
run: |
mkdir build
cp -r upload build/ 2>/dev/null || true
cp install.xml build/ 2>/dev/null || true
cp install.php build/ 2>/dev/null || true
cp install.sql build/ 2>/dev/null || true
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.package.outputs.code }}-${{ steps.package.outputs.platform }}-${{ steps.package.outputs.version }}
path: |
dist/*.ocmod.zip
dist/*.sha256
if-no-files-found: error
- name: Build ocmod package
- name: Publish or replace Gitea release
if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.publish_release)
env:
GITEA_SERVER: ${{ github.server_url }}
GITEA_REPOSITORY: ${{ github.repository }}
GITEA_TOKEN: ${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }}
VERSION: ${{ steps.package.outputs.version }}
CODE: ${{ steps.package.outputs.code }}
ZIP_NAME: ${{ steps.package.outputs.zip_name }}
REF_NAME: ${{ github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
COMMIT_SHA: ${{ github.sha }}
shell: bash
run: |
cd build
zip -r ../${FILENAME} .
cd ..
set -Eeuo pipefail
- name: Install tea CLI
run: |
curl -L https://dl.gitea.io/tea/main/tea-main-linux-amd64 -o tea
chmod +x tea
sudo mv tea /usr/local/bin/
if [[ -z "$GITEA_TOKEN" ]]; then
echo "::error::Missing OC3_EXTENSION_RELEASE_TOKEN secret"
exit 1
fi
- name: Configure tea
run: |
tea login add \
--name gitea \
--url ${{ vars.SERVER_URL }} \
--token ${{ secrets.OC3_EXTENSION_RELEASE_TOKEN }}
TAG="v${VERSION}"
- name: Create release
run: |
TAG="${VERSION}"
# A tag-triggered release must match the extension metadata.
if [[ "$EVENT_NAME" == "push" && "$REF_NAME" != "$TAG" ]]; then
echo "::error::Git tag $REF_NAME does not match metadata version $TAG"
exit 1
fi
tea release create "$TAG" \
--title "${CODE}_${VERSION}" \
--asset "${FILENAME}" \
--repo ${{ gitea.repository }}
API="${GITEA_SERVER%/}/api/v1"
OWNER="${GITEA_REPOSITORY%%/*}"
REPO="${GITEA_REPOSITORY#*/}"
AUTH_HEADER="Authorization: token ${GITEA_TOKEN}"
RELEASE_URL="$API/repos/$OWNER/$REPO/releases/tags/$TAG"
RESPONSE="$(mktemp)"
PAYLOAD="$(mktemp)"
# Check whether a release already exists.
STATUS="$(curl -sS \
-H "$AUTH_HEADER" \
-o "$RESPONSE" \
-w '%{http_code}' \
"$RELEASE_URL")"
RELEASE_NAME="${CODE} ${TAG}"
if [[ "$STATUS" == "200" ]]; then
RELEASE_ID="$(jq -er '.id' "$RESPONSE")"
echo "Existing release found. Replacing its assets."
# Update release metadata.
jq -n \
--arg name "$RELEASE_NAME" \
--arg body "Automated OpenCart extension release." \
'{name: $name, body: $body}' > "$PAYLOAD"
curl -fsS -X PATCH \
-H "$AUTH_HEADER" \
-H "Content-Type: application/json" \
--data-binary "@$PAYLOAD" \
"$API/repos/$OWNER/$REPO/releases/$RELEASE_ID" \
>/dev/null
# Delete old assets before uploading new ones.
jq -r '.assets[]?.id' "$RESPONSE" |
while read -r ASSET_ID; do
echo "Deleting old release asset: $ASSET_ID"
curl -fsS -X DELETE \
-H "$AUTH_HEADER" \
"$API/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets/$ASSET_ID" \
>/dev/null
done
elif [[ "$STATUS" == "404" ]]; then
echo "Creating new release: $TAG"
jq -n \
--arg tag "$TAG" \
--arg name "$RELEASE_NAME" \
--arg body "Automated OpenCart extension release." \
--arg commit "$COMMIT_SHA" \
'{
tag_name: $tag,
target_commitish: $commit,
name: $name,
body: $body,
draft: false,
prerelease: false
}' > "$PAYLOAD"
curl -fsS -X POST \
-H "$AUTH_HEADER" \
-H "Content-Type: application/json" \
--data-binary "@$PAYLOAD" \
"$API/repos/$OWNER/$REPO/releases" \
> "$RESPONSE"
RELEASE_ID="$(jq -er '.id' "$RESPONSE")"
else
echo "::error::Unable to retrieve release. HTTP $STATUS"
cat "$RESPONSE"
exit 1
fi
# Upload the new package and checksum.
for ASSET in "dist/$ZIP_NAME" "dist/$ZIP_NAME.sha256"; do
ASSET_NAME="$(basename "$ASSET")"
echo "Uploading: $ASSET_NAME"
curl -fsS \
-X POST \
-H "$AUTH_HEADER" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$ASSET" \
--get \
--data-urlencode "name=$ASSET_NAME" \
"$API/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets" \
>/dev/null
done
# Verify the final release assets.
curl -fsS \
-H "$AUTH_HEADER" \
"$API/repos/$OWNER/$REPO/releases/$RELEASE_ID" \
> "$RESPONSE"
jq -e --arg zip "$ZIP_NAME" '
([.assets[].name] | index($zip) != null) and
([.assets[].name] | index($zip + ".sha256") != null)
' "$RESPONSE" >/dev/null
echo "Release $TAG successfully published."
echo "Package and checksum verified."
rm -f "$RESPONSE" "$PAYLOAD"
+9
View File
@@ -0,0 +1,9 @@
{
"platform": "oc3",
"code": "my_extension"
},
{
"platform": "oc4",
"code": "my_extension",
"minimum_version": "4.0.0"
}
+906 -50
View File
@@ -1,68 +1,924 @@
# OpenCart 3 Module Template
# OpenCart Extension Template
A comprehensive template for developing custom modules and extensions for OpenCart 3.x e-commerce platform.
A reusable template for developing, validating, packaging, and releasing OpenCart extensions through **Gitea Actions**.
## Features
This repository provides a standardized starting point for OpenCart 3 and OpenCart 4 extensions, with automated OCMOD package generation and Git-based release management.
### 🚀 OpenCart 3 Compatibility
- Fully compatible with OpenCart 3.x versions
- Uses OCMOD (OpenCart Modification) system for safe modifications
- No core file changes required
---
### 📦 Module Structure
- **install.xml**: OCMOD installation file with modification definitions
- **upload/**: Directory for module files to be uploaded to OpenCart
- **install.php**: Optional PHP installation script
- **install.sql**: Optional database installation script
## Table of Contents
### 🔄 Automated Releases
- Integrated Gitea Actions workflow for automatic builds
- Generates `.ocmod.zip` packages on push to main branch
- Extracts metadata from `install.xml` for versioning
- Ready-to-install extension packages
- [Overview](#overview)
- [Supported OpenCart Versions](#supported-opencart-versions)
- [Repository Architecture](#repository-architecture)
- [Getting Started](#getting-started)
- [Extension Configuration](#extension-configuration)
- [OpenCart 3 Development](#opencart-3-development)
- [OpenCart 4 Development](#opencart-4-development)
- [Package Generation](#package-generation)
- [Automated Build and Release](#automated-build-and-release)
- [Versioning and Release Management](#versioning-and-release-management)
- [Validation and Quality Checks](#validation-and-quality-checks)
- [Gitea Configuration](#gitea-configuration)
- [Using This Template for New Extensions](#using-this-template-for-new-extensions)
- [Troubleshooting](#troubleshooting)
- [Development Guidelines](#development-guidelines)
### 🛠️ Development Tools
- XML-based modification system
- Template structure for rapid module development
- CI/CD pipeline for quality assurance
- Version management through install.xml
---
## Installation
## Overview
1. Clone this repository
2. Customize the `install.xml` with your module details:
- Set `<name>`, `<code>`, and `<version>`
- Add your modifications in the `<file>` sections
3. Place your module files in the `upload/` directory
4. Add installation scripts if needed (`install.php`, `install.sql`)
5. Push to your repository to trigger automatic release build
The purpose of this template is to standardize the development and distribution of OpenCart extensions.
## Usage
Each extension repository must target **one OpenCart generation only**.
### For Module Developers
1. Use this template as a starting point for new OpenCart modules
2. Define your modifications in `install.xml`
3. Add custom files to `upload/` directory
4. Test locally before deploying
OpenCart 3 and OpenCart 4 have different internal architectures, extension structures, metadata formats, and development conventions. Therefore, a single repository must not attempt to generate both OC3 and OC4 packages.
### For Store Owners
1. Download the generated `.ocmod.zip` from releases
2. Upload via OpenCart's Extension Installer
3. Install and configure the module through admin panel
### Key Features
## Requirements
- Dedicated support for OpenCart 3 and OpenCart 4 repositories.
- Automated extension packaging through Gitea Actions.
- Metadata-driven extension versioning.
- Automatic ZIP package generation.
- PHP syntax validation.
- XML and JSON metadata validation.
- ZIP integrity verification.
- SHA-256 checksum generation.
- Automated Gitea release creation.
- Existing release replacement when publishing the same version.
- Manual build and release execution.
- Consistent package naming conventions.
- OpenCart 3.x
- PHP 7.3 or higher
- MySQL 5.7 or higher
- OCMOD support enabled
### Design Principles
## Author
1. One repository represents one OpenCart target generation.
2. Extension business logic remains independent of the build system.
3. Packaging includes only the files required to install the extension.
4. Optional installation resources are included only when present and supported by the target platform.
5. Releases are generated from validated source code.
6. The extension metadata is the source of truth for its version.
**Mohamed Youssef**
Website: [my-dev.pro](https://my-dev.pro)
Email: Contact through website
---
## Supported OpenCart Versions
The template supports the following targets:
| Platform | Supported versions | Metadata |
|---|---|---|
| OpenCart 3 | 3.0.3.x | `install.xml` |
| OpenCart 4 | 4.0.0 | `install.json` |
| OpenCart 4 | 4.0.1 | `install.json` |
| OpenCart 4 | 4.0.2.x | `install.json` |
| OpenCart 4 | 4.1.x | `install.json` |
**Important:** Declaring a minimum OpenCart version does not automatically guarantee runtime compatibility. Extension code must still be tested against the actual OpenCart versions it claims to support.
### OpenCart 3 vs OpenCart 4
| Feature | OpenCart 3 | OpenCart 4 |
|---|---|---|
| Extension metadata | `install.xml` | `install.json` |
| Main package directory | `upload/` | Root-level extension directories |
| Admin files | `upload/admin/` | `admin/` |
| Catalog files | `upload/catalog/` | `catalog/` |
| System files | `upload/system/` | `system/` |
| OCMOD XML | `install.xml` | Optional `ocmod/` for supported versions |
| Installation resources | Optional `install.php`, `install.sql` | According to the extension's implementation |
Do not mix these structures in one repository.
---
## Repository Architecture
The repository structure depends on the OpenCart target.
### OpenCart 3 Repository
```text
my-extension-oc3/
├── .gitea/
│ └── workflows/
│ └── release.yml
│
├── .oc-extension.json
│
├── install.xml
│
├── upload/
│ ├── admin/
│ │ ├── controller/
│ │ ├── language/
│ │ ├── model/
│ │ └── view/
│ │
│ ├── catalog/
│ │ ├── controller/
│ │ ├── language/
│ │ ├── model/
│ │ └── view/
│ │
│ └── system/
│
├── install.php # Optional
├── install.sql # Optional
│
└── README.md
```
### OpenCart 4 Repository
```text
my-extension-oc4/
├── .gitea/
│ └── workflows/
│ └── release.yml
│
├── .oc-extension.json
│
├── install.json
│
├── admin/
│ ├── controller/
│ ├── language/
│ ├── model/
│ └── view/
│
├── catalog/
│ ├── controller/
│ ├── language/
│ ├── model/
│ └── view/
│
├── system/
│
├── ocmod/ # Optional; for supported OC4 versions
│ └── example.ocmod.xml
│
└── README.md
```
The build workflow packages the relevant installation files without including development-only files or repository configuration.
---
## Getting Started
### 1. Create a Repository
Create a new repository using this template.
Choose the target OpenCart generation before starting development:
- OpenCart 3 extension repository.
- OpenCart 4 extension repository.
Do not use one repository to maintain both implementations.
Recommended naming conventions:
```text
my-extension-oc3
my-extension-oc4
```
The naming convention is optional, but clearly identifying the target platform is recommended.
### 2. Configure the Extension
Create `.oc-extension.json` in the repository root.
For OpenCart 3:
```json
{
"platform": "oc3",
"code": "my_extension"
}
```
For OpenCart 4:
```json
{
"platform": "oc4",
"code": "my_extension",
"minimum_version": "4.0.0"
}
```
The configuration identifies the target platform and extension code used during packaging.
### 3. Add Extension Files
Use the appropriate directory structure for your target platform.
### 4. Configure Metadata
Complete `install.xml` for OC3 or `install.json` for OC4.
### 5. Configure Gitea Actions
Ensure the repository contains the release workflow:
```text
.gitea/workflows/release.yml
```
Configure the required repository secret as described in the Gitea Configuration section.
### 6. Push to Main
Push your changes to the `main` branch.
The workflow will validate and build the extension package.
---
## Extension Configuration
The `.oc-extension.json` file defines the build target.
### Available Configuration Properties
| Property | Required | Description |
|---|---|---|
| `platform` | Yes | Target platform: `oc3` or `oc4` |
| `code` | Yes | Unique extension code |
| `minimum_version` | OC4 | Minimum OpenCart version supported by the extension |
### Extension Code Rules
The extension code must:
- Use lowercase letters.
- Support numbers and underscores.
- Contain no spaces.
- Be consistent with the extension metadata where applicable.
Valid examples:
```text
my_extension
product_tools
advanced_checkout
extension123
```
Invalid examples:
```text
My Extension
my-extension
My_Extension
```
The extension code is used when generating the release package filename.
---
## OpenCart 3 Development
OpenCart 3 extensions use `install.xml` as their OCMOD metadata file.
### Required Files
```text
.oc-extension.json
install.xml
upload/
```
### install.xml Example
```xml
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>My Extension</name>
<code>my_extension</code>
<author>MY-Dev</author>
<link>https://my-dev.pro</link>
<version>1.0.0</version>
<file path="catalog/controller/common/header.php">
<operation error="skip">
<search><![CDATA[
// Search target
]]></search>
<add position="after"><![CDATA[
// Modification code
]]></add>
</operation>
</file>
</modification>
```
Replace the example metadata and modification contents with the actual extension implementation.
### Optional Installation Files
The following files may be included when required:
```text
install.php
install.sql
```
They are optional and are copied into the generated package when present.
### Package Structure
The generated OC3 package should have this structure:
```text
my_extension_v1.0.0.ocmod.zip
│
├── install.xml
├── upload/
│ ├── admin/
│ ├── catalog/
│ └── system/
│
├── install.php # If present
└── install.sql # If present
```
The ZIP must contain `upload/` and `install.xml` at its root.
---
## OpenCart 4 Development
OpenCart 4 uses a different extension architecture and installation metadata format.
### Required Files
```text
.oc-extension.json
install.json
```
At least one appropriate extension directory must be provided.
### install.json Example
```json
{
"name": "My Extension",
"version": "1.0.0",
"author": "MY-Dev",
"link": "https://my-dev.pro"
}
```
### Extension Directories
OpenCart 4 extension files are placed at the package root.
Typical directories include:
```text
admin/
catalog/
system/
```
Only the directories required by the extension need to be included.
### OCMOD Compatibility
OpenCart 4.0.0 and 4.0.1 require special consideration because their OCMOD support differs from later releases.
For extensions targeting these versions, do not assume that XML OCMOD modifications will be applied.
For OpenCart 4.0.2 and later, an optional `ocmod/` directory can contain XML modification files where the target version supports the required functionality.
Example:
```text
ocmod/
└── my_extension.ocmod.xml
```
Configure the minimum version accordingly:
```json
{
"platform": "oc4",
"code": "my_extension",
"minimum_version": "4.0.2"
}
```
### Package Structure
A typical OC4 package:
```text
my_extension_v1.0.0.ocmod.zip
│
├── install.json
├── admin/
├── catalog/
├── system/
└── ocmod/
└── my_extension.ocmod.xml
```
The `ocmod/` directory is optional.
The package should not contain an additional `upload/` directory.
---
## Package Generation
The Gitea Actions workflow generates the installation ZIP automatically.
### Package Naming Convention
The generated package follows this naming pattern:
```text
{extension_code}_v{extension_version}.ocmod.zip
```
Examples:
```text
my_extension_v1.0.0.ocmod.zip
product_tools_v1.2.0.ocmod.zip
advanced_checkout_v2.5.1.ocmod.zip
```
### Checksum File
Each package also receives a SHA-256 checksum file:
```text
my_extension_v1.0.0.ocmod.zip.sha256
```
This can be used to verify that the downloaded package matches the generated artifact.
Verify locally with:
```bash
sha256sum -c my_extension_v1.0.0.ocmod.zip.sha256
```
### Files Excluded from Packages
The release package should contain installation files only.
The following development and repository files must not be included:
- `.git/`
- `.gitea/`
- `.github/`
- `.oc-extension.json`
- `README.md`
- Test directories.
- Development scripts.
- Temporary build files.
- Unrelated documentation.
---
## Automated Build and Release
The workflow is located at:
```text
.gitea/workflows/release.yml
```
It supports three execution methods.
### 1. Push to Main
When changes are pushed to `main`:
1. The repository is checked out.
2. Build dependencies are installed.
3. The target OpenCart platform is identified.
4. Metadata is validated.
5. Extension files are checked.
6. PHP syntax validation is performed.
7. The package is generated.
8. ZIP integrity is verified.
9. SHA-256 checksum is generated.
10. Build artifacts are uploaded.
**A push to `main` does not publish a release.**
### 2. Version Tag
When a version tag is pushed:
```bash
git tag v1.0.0
git push origin v1.0.0
```
The workflow performs the complete build and release process.
The tag must match the version declared in the extension metadata.
For example:
| Metadata version | Required tag |
|---|---|
| `1.0.0` | `v1.0.0` |
| `1.2.0` | `v1.2.0` |
| `2.0.1` | `v2.0.1` |
A mismatch causes the release workflow to fail.
### 3. Manual Execution
The workflow can also be executed manually from the Gitea Actions interface.
Manual execution supports:
- Build and validate without publishing.
- Build and publish a release.
- Replace an existing release when publishing the same version.
The publishing option must be explicitly enabled for a manual run.
---
## Versioning and Release Management
The extension metadata is the source of truth for the extension version.
### Version Sources
| Platform | Version source |
|---|---|
| OC3 | `install.xml` → `modification/version` |
| OC4 | `install.json` → `version` |
Use semantic versioning where possible:
```text
MAJOR.MINOR.PATCH
```
Examples:
```text
1.0.0
1.0.1
1.1.0
2.0.0
```
### Release Naming
The release tag uses:
```text
v{version}
```
The release title uses:
```text
{extension_code} v{version}
```
### Existing Release Replacement
If a release already exists for the same tag, the workflow updates the existing release and replaces its assets.
For example:
1. Publish `v1.0.0`.
2. Fix an issue in the extension.
3. Rebuild the package.
4. Publish `v1.0.0` again.
5. The existing release assets are replaced with the newly generated package and checksum.
This behavior allows correcting a release without creating another version tag.
**Important:** Replacing a release is a destructive operation on its existing assets. Use it only when intentionally republishing the same version.
---
## Validation and Quality Checks
The workflow performs automated checks before publishing.
### Metadata Validation
For OC3:
- `install.xml` must exist.
- XML syntax must be valid.
- Extension code must match `.oc-extension.json`.
- Version must be present and valid.
- Empty OCMOD file paths are rejected.
- Empty search and add operations are rejected.
For OC4:
- `install.json` must exist.
- JSON syntax must be valid.
- Required metadata fields must be populated.
- Version must be present and valid.
- The repository must have a valid OC4 structure.
- OCMOD XML files are checked when included.
### PHP Syntax Validation
PHP files in the generated package are checked using:
```bash
php -l
```
Invalid PHP syntax causes the build to fail.
### ZIP Validation
The generated package is tested using:
```bash
unzip -t package.ocmod.zip
```
### Checksum Generation
The workflow generates a SHA-256 checksum for the final ZIP.
### Validation Limitations
Automated packaging checks do not replace runtime testing.
Before publishing an extension, test it against the actual OpenCart versions and configurations it claims to support.
In particular, validate:
- Installation and uninstallation.
- Admin permissions.
- Database changes.
- Storefront functionality.
- Modification compatibility.
- Upgrade and rollback behavior.
---
## Gitea Configuration
### Required Repository Secret
Configure the following secret in the repository settings:
```text
OC3_EXTENSION_RELEASE_TOKEN
```
The workflow uses this token to communicate with the Gitea API.
The token must have the permissions required to:
- Read repository release information.
- Create releases.
- Update existing releases.
- Delete existing release assets.
- Upload new release assets.
Use the least-privilege token supported by your Gitea installation.
Never store the token directly in the workflow or repository files.
### Gitea Actions Runner
The runner must support:
- Linux execution.
- Bash.
- Git.
- PHP CLI.
- `jq`.
- `curl`.
- `zip`.
- `unzip`.
- `xmllint` / `libxml2-utils`.
The workflow installs the required operating-system dependencies during execution.
### Gitea API
Release management uses the Gitea REST API.
The workflow relies on the repository URL and token provided by the Gitea Actions environment.
Make sure the Gitea instance permits release creation and asset uploads for the configured token.
---
## Using This Template for New Extensions
Recommended workflow for creating a new extension:
1. Create a repository from this template.
2. Decide whether the extension targets OC3 or OC4.
3. Configure `.oc-extension.json`.
4. Remove the unused platform's example files.
5. Add the required extension directories.
6. Complete the platform-specific metadata.
7. Implement the extension functionality.
8. Push the initial implementation to `main`.
9. Review the generated package.
10. Test installation in a clean OpenCart environment.
11. Create a version tag.
12. Verify the published release and checksum.
### Example: First Release
Update the extension metadata to:
```text
1.0.0
```
Commit and push:
```bash
git add .
git commit -m "Initial extension release"
git push origin main
```
Create and push the release tag:
```bash
git tag v1.0.0
git push origin v1.0.0
```
The workflow builds and publishes:
```text
my_extension_v1.0.0.ocmod.zip
my_extension_v1.0.0.ocmod.zip.sha256
```
### Example: Publishing an Update
Update the metadata version:
```text
1.1.0
```
Commit and push the changes:
```bash
git add .
git commit -m "Release version 1.1.0"
git push origin main
```
Publish the new version:
```bash
git tag v1.1.0
git push origin v1.1.0
```
---
## Troubleshooting
### Missing `.oc-extension.json`
**Cause:** The platform configuration file is missing.
**Solution:** Add `.oc-extension.json` and specify the target platform and extension code.
### OC3 Metadata Validation Failed
**Cause:** `install.xml` is missing, invalid, or contains incomplete metadata.
**Solution:** Validate the XML and ensure the code and version are populated.
### OC4 Metadata Validation Failed
**Cause:** `install.json` is missing or contains invalid JSON or missing required metadata.
**Solution:** Validate the JSON and ensure `name`, `version`, `author`, and `link` are populated.
### Platform Mismatch
**Cause:** The repository contains metadata or directory structures belonging to the other OpenCart generation.
**Solution:** Remove the incompatible files and use the correct repository structure.
### PHP Syntax Error
**Cause:** One or more PHP files contain syntax errors.
**Solution:** Run the following locally:
```bash
find upload admin catalog system -type f -name '*.php' \
-exec php -l {} \;
```
Use only the directories relevant to your platform.
### Release Tag Does Not Match Metadata
**Cause:** The Git tag does not match the version declared in the metadata.
**Solution:** Ensure the tag uses the `v` prefix and exactly matches the metadata version.
### Release Publishing Failed
**Possible causes:**
- Missing or invalid Gitea token.
- Insufficient release permissions.
- Gitea API endpoint unavailable.
- Existing release asset deletion failed.
- Asset upload failed.
Review the Actions logs and verify the repository secret and token permissions.
### Package Does Not Install
**Possible causes:**
- Incorrect package directory structure.
- Missing installation metadata.
- Incorrect extension directory names.
- Incompatible OpenCart target version.
- Missing dependencies.
- Incorrect extension implementation.
Inspect the ZIP archive before publishing.
---
## Development Guidelines
### General Rules
- Keep extension code separate from build configuration.
- Do not add platform-specific files to the wrong repository.
- Keep extension metadata synchronized with the release version.
- Do not commit generated ZIP packages or temporary build artifacts.
- Test extensions before publishing releases.
- Use meaningful commit messages.
- Keep the README of each extension repository focused on that extension's installation and usage.
### Template Maintenance
Changes to this template affect new repositories created from it.
Repositories already created from the template do not automatically receive workflow or documentation updates. Existing repositories must be updated separately.
When modifying the release workflow:
1. Test OC3 packaging.
2. Test OC4 packaging.
3. Verify metadata validation.
4. Verify package contents.
5. Verify checksum generation.
6. Verify release creation.
7. Verify replacement of existing release assets.
### Suggested Commit Messages
```text
feat: add new extension functionality
fix: correct extension installation issue
refactor: improve extension architecture
docs: update installation documentation
build: improve release workflow
chore: update development dependencies
```
---
## License
This template is provided as-is for OpenCart module development. Please check individual module licenses for usage terms.
Add the license applicable to your extension repository.
For proprietary or commercial extensions, clearly document the applicable distribution and usage terms.
---
## Maintainer
**MY-Dev**
Website: https://my-dev.pro
This repository is intended to provide a consistent development and release foundation for OpenCart extensions maintained by MY-Dev.