feat: expose module version
This commit is contained in:
86
.github/workflows/main.yaml
vendored
86
.github/workflows/main.yaml
vendored
@@ -16,6 +16,45 @@ permissions:
|
|||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
version_meta:
|
||||||
|
name: Compute version metadata
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
tag: ${{ steps.meta.outputs.tag }}
|
||||||
|
filename: ${{ steps.meta.outputs.filename }}
|
||||||
|
is_release: ${{ steps.meta.outputs.is_release }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Extract tag and set filename
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
RELEASE_TAG=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
|
||||||
|
|
||||||
|
if [ -n "$RELEASE_TAG" ]; then
|
||||||
|
echo "Это полноценный релиз"
|
||||||
|
TAG="$RELEASE_TAG"
|
||||||
|
FILENAME="oc_telegram_shop_${TAG}.ocmod.zip"
|
||||||
|
IS_RELEASE=true
|
||||||
|
else
|
||||||
|
echo "Это dev-сборка"
|
||||||
|
LAST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
|
||||||
|
[ -z "$LAST_TAG" ] && LAST_TAG="v0.0.0"
|
||||||
|
SHORT_SHA=$(git rev-parse --short=7 HEAD)
|
||||||
|
DATE=$(date +%Y%m%d%H%M)
|
||||||
|
TAG="${LAST_TAG}-dev.${DATE}+${SHORT_SHA}"
|
||||||
|
FILENAME="oc_telegram_shop_${TAG}.ocmod.zip"
|
||||||
|
IS_RELEASE=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
|
||||||
|
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
||||||
|
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
test_frontend:
|
test_frontend:
|
||||||
name: Run Frontend tests
|
name: Run Frontend tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -79,6 +118,7 @@ jobs:
|
|||||||
module-build:
|
module-build:
|
||||||
name: Build module.
|
name: Build module.
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: version_meta
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v6
|
- uses: actions/setup-node@v6
|
||||||
@@ -89,6 +129,12 @@ jobs:
|
|||||||
php-version: '7.4'
|
php-version: '7.4'
|
||||||
tools: composer
|
tools: composer
|
||||||
|
|
||||||
|
- name: Write version.txt
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
MODULE_ROOT="module/oc_telegram_shop/upload/oc_telegram_shop"
|
||||||
|
echo "${{ needs.version_meta.outputs.tag }}" > "${MODULE_ROOT}/version.txt"
|
||||||
|
|
||||||
- name: Build module
|
- name: Build module
|
||||||
run: |
|
run: |
|
||||||
bash scripts/ci/build.sh "${GITHUB_WORKSPACE}"
|
bash scripts/ci/build.sh "${GITHUB_WORKSPACE}"
|
||||||
@@ -102,38 +148,10 @@ jobs:
|
|||||||
|
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [ test_frontend, test_backend, module-build ]
|
needs: [ version_meta, test_frontend, test_backend, module-build ]
|
||||||
if: github.ref == 'refs/heads/master'
|
if: github.ref == 'refs/heads/master'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
fetch-depth: 0 # to fetch tags
|
|
||||||
|
|
||||||
- name: Extract tag and set filename
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
# Проверяем, указывает ли HEAD на тег (релиз)
|
|
||||||
RELEASE_TAG=$(git tag --points-at HEAD | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
|
|
||||||
|
|
||||||
if [ -n "$RELEASE_TAG" ]; then
|
|
||||||
echo "Это полноценный релиз"
|
|
||||||
TAG="$RELEASE_TAG"
|
|
||||||
FILENAME="oc_telegram_shop_${TAG}.ocmod.zip"
|
|
||||||
IS_RELEASE=true
|
|
||||||
else
|
|
||||||
echo "Это dev-сборка"
|
|
||||||
LAST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
|
|
||||||
[ -z "$LAST_TAG" ] && LAST_TAG="v0.0.0"
|
|
||||||
SHORT_SHA=$(git rev-parse --short=7 HEAD)
|
|
||||||
DATE=$(date +%Y%m%d%H%M)
|
|
||||||
TAG="${LAST_TAG}-dev.${DATE}+${SHORT_SHA}"
|
|
||||||
FILENAME="oc_telegram_shop_${TAG}.ocmod.zip"
|
|
||||||
IS_RELEASE=false
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
|
|
||||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
|
||||||
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Download build artifact
|
- name: Download build artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
@@ -142,13 +160,13 @@ jobs:
|
|||||||
path: ./build
|
path: ./build
|
||||||
|
|
||||||
- name: Rename artifact file
|
- name: Rename artifact file
|
||||||
run: mv ./build/oc_telegram_shop.ocmod.zip ./build/${{ steps.meta.outputs.filename }}
|
run: mv ./build/oc_telegram_shop.ocmod.zip ./build/${{ needs.version_meta.outputs.filename }}
|
||||||
|
|
||||||
- name: Delete existing GitHub release and tag
|
- name: Delete existing GitHub release and tag
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
TAG=${{ steps.meta.outputs.tag }}
|
TAG=${{ needs.version_meta.outputs.tag }}
|
||||||
echo "⛔ Deleting existing release and tag (if any): $TAG"
|
echo "⛔ Deleting existing release and tag (if any): $TAG"
|
||||||
gh release delete "$TAG" --cleanup-tag --yes || true
|
gh release delete "$TAG" --cleanup-tag --yes || true
|
||||||
git push origin ":refs/tags/$TAG" || true
|
git push origin ":refs/tags/$TAG" || true
|
||||||
@@ -156,9 +174,9 @@ jobs:
|
|||||||
- name: Create GitHub Release
|
- name: Create GitHub Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
draft: ${{ steps.meta.outputs.is_release == 'false' }}
|
draft: ${{ needs.version_meta.outputs.is_release == 'false' }}
|
||||||
tag_name: ${{ steps.meta.outputs.tag }}
|
tag_name: ${{ needs.version_meta.outputs.tag }}
|
||||||
files: ./build/${{ steps.meta.outputs.filename }}
|
files: ./build/${{ needs.version_meta.outputs.filename }}
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -47,5 +47,6 @@ class JsonResponse extends Response
|
|||||||
header('Access-Control-Allow-Methods: GET, POST');
|
header('Access-Control-Allow-Methods: GET, POST');
|
||||||
header('Access-Control-Allow-Headers: Content-Type, Authorization');
|
header('Access-Control-Allow-Headers: Content-Type, Authorization');
|
||||||
header('Access-Control-Allow-Credentials: true');
|
header('Access-Control-Allow-Credentials: true');
|
||||||
|
header('X-TELECART-VERSION: ' . module_version());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,3 +101,32 @@ if (! function_exists('env')) {
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! function_exists('module_version')) {
|
||||||
|
function module_version(): string
|
||||||
|
{
|
||||||
|
static $version = null;
|
||||||
|
|
||||||
|
if ($version !== null) {
|
||||||
|
return $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionFile = BP_BASE_PATH . '/version.txt';
|
||||||
|
if (is_readable($versionFile)) {
|
||||||
|
$raw = trim((string) file_get_contents($versionFile));
|
||||||
|
if ($raw !== '') {
|
||||||
|
return $version = $raw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$composerFile = BP_BASE_PATH . '/composer.json';
|
||||||
|
if (is_readable($composerFile)) {
|
||||||
|
$composer = json_decode((string) file_get_contents($composerFile), true);
|
||||||
|
if (is_array($composer) && ! empty($composer['version'])) {
|
||||||
|
return $version = (string) $composer['version'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $version = 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class TeleCartPulseService
|
|||||||
|
|
||||||
$botName = $me['username'] ?? 'unknown';
|
$botName = $me['username'] ?? 'unknown';
|
||||||
|
|
||||||
$moduleVersion = $this->getModuleVersion();
|
$moduleVersion = module_version();
|
||||||
|
|
||||||
$payload = [
|
$payload = [
|
||||||
'event' => 'HEARTBEAT',
|
'event' => 'HEARTBEAT',
|
||||||
@@ -184,7 +184,7 @@ class TeleCartPulseService
|
|||||||
'timeout' => env('PULSE_TIMEOUT', 5.0),
|
'timeout' => env('PULSE_TIMEOUT', 5.0),
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'Bearer ' . $this->apiKey,
|
'Authorization' => 'Bearer ' . $this->apiKey,
|
||||||
'X-TELECART-VERSION' => $this->getModuleVersion(),
|
'X-TELECART-VERSION' => module_version(),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -202,35 +202,13 @@ class TeleCartPulseService
|
|||||||
'base_uri' => $baseUri,
|
'base_uri' => $baseUri,
|
||||||
'timeout' => env('PULSE_TIMEOUT', 2.0),
|
'timeout' => env('PULSE_TIMEOUT', 2.0),
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'X-TELECART-VERSION' => $this->getModuleVersion(),
|
'X-TELECART-VERSION' => module_version(),
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$client->post('heartbeat', compact('json'));
|
$client->post('heartbeat', compact('json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getModuleVersion(): string
|
|
||||||
{
|
|
||||||
if ($this->moduleVersion !== null) {
|
|
||||||
return $this->moduleVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
$moduleVersion = 'unknown';
|
|
||||||
$composerPath = __DIR__ . '/../../composer.json';
|
|
||||||
|
|
||||||
if (file_exists($composerPath)) {
|
|
||||||
$composerRaw = @file_get_contents($composerPath);
|
|
||||||
if ($composerRaw !== false) {
|
|
||||||
$composer = json_decode($composerRaw, true);
|
|
||||||
if (is_array($composer) && isset($composer['version'])) {
|
|
||||||
$moduleVersion = (string)$composer['version'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->moduleVersion = $moduleVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function handleOrderCreated(array $data, array $deserialized): void
|
private function handleOrderCreated(array $data, array $deserialized): void
|
||||||
{
|
{
|
||||||
if (isset($deserialized['campaign_id'], $deserialized['tracking_id'])) {
|
if (isset($deserialized['campaign_id'], $deserialized['tracking_id'])) {
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
v2.0.0
|
||||||
Reference in New Issue
Block a user