mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
test(get-magento-version): document and pin what happens in various kinds of installs
This commit is contained in:
@@ -46,4 +46,25 @@ jobs:
|
|||||||
if: steps.magento-version.outputs.project != 'magento/project-community-edition'
|
if: steps.magento-version.outputs.project != 'magento/project-community-edition'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "${{ steps.magento-version.outputs.project }}" && exit 1
|
run: echo "${{ steps.magento-version.outputs.project }}" && exit 1
|
||||||
|
|
||||||
|
get-magento-version-extension:
|
||||||
|
if: "!startsWith(github.head_ref, 'release-please')"
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Create mock extension composer.json
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir -p /tmp/test-extension
|
||||||
|
echo '{"name":"vendor/module","type":"magento2-module","require":{}}' > /tmp/test-extension/composer.json
|
||||||
|
|
||||||
|
- uses: ./get-magento-version
|
||||||
|
id: ext-version
|
||||||
|
with:
|
||||||
|
working-directory: /tmp/test-extension
|
||||||
|
|
||||||
|
- name: Fail if project is not empty
|
||||||
|
if: steps.ext-version.outputs.project != ''
|
||||||
|
shell: bash
|
||||||
|
run: echo "Expected empty project, got '${{ steps.ext-version.outputs.project }}'" && exit 1
|
||||||
|
|||||||
@@ -22,22 +22,7 @@ runs:
|
|||||||
- name: Compute Installed Magento version
|
- name: Compute Installed Magento version
|
||||||
id: get-magento-version
|
id: get-magento-version
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: ${{ inputs.working-directory }}
|
run: bash "${{ github.action_path }}/get-magento-version.sh" "${{ inputs.working-directory }}" >> $GITHUB_OUTPUT
|
||||||
run: |
|
|
||||||
PATTERN="magento/product-(community|enterprise)-edition|mage-os/product-community-edition"
|
|
||||||
|
|
||||||
if [ -f composer.lock ]; then
|
|
||||||
RESULT=$(jq -r --arg p "$PATTERN" '.packages[] | select(.name | test($p)) | "\(.name) \(.version)"' composer.lock | head -1)
|
|
||||||
else
|
|
||||||
RESULT=$(jq -r --arg p "$PATTERN" '.require | to_entries[] | select(.key | test($p)) | "\(.key) \(.value)"' composer.json | head -1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
PRODUCT=$(echo "$RESULT" | awk '{print $1}')
|
|
||||||
VERSION=$(echo "$RESULT" | awk '{print $2}' | sed 's/^v//')
|
|
||||||
PROJECT=$(echo "$PRODUCT" | sed 's/product-/project-/')
|
|
||||||
|
|
||||||
echo "version=\"$VERSION\"" >> $GITHUB_OUTPUT
|
|
||||||
echo "project=$PROJECT" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: "code"
|
icon: "code"
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "magento/product-enterprise-edition",
|
||||||
|
"version": "2.4.7-p1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "vendor/module",
|
||||||
|
"type": "magento2-module",
|
||||||
|
"require": {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "mage-os/product-community-edition",
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"magento/product-community-edition": "2.4.6-p1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "magento/product-community-edition",
|
||||||
|
"version": "2.4.7"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "magento/product-community-edition",
|
||||||
|
"version": "v2.4.6"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"packages-dev": []
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -uo pipefail
|
||||||
|
|
||||||
|
WORKING_DIR="${1:-.}"
|
||||||
|
PATTERN="magento/product-(community|enterprise)-edition|mage-os/product-community-edition"
|
||||||
|
|
||||||
|
cd "$WORKING_DIR"
|
||||||
|
|
||||||
|
if [ -f composer.lock ]; then
|
||||||
|
RESULT=$(jq -r --arg p "$PATTERN" '.packages[] | select(.name | test($p)) | "\(.name) \(.version)"' composer.lock | head -1)
|
||||||
|
elif [ -f composer.json ]; then
|
||||||
|
RESULT=$(jq -r --arg p "$PATTERN" '.require | to_entries[] | select(.key | test($p)) | "\(.key) \(.value)"' composer.json | head -1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
PRODUCT=$(echo "${RESULT:-}" | awk '{print $1}')
|
||||||
|
VERSION=$(echo "${RESULT:-}" | awk '{print $2}' | sed 's/^v//')
|
||||||
|
PROJECT=$(echo "$PRODUCT" | sed 's/product-/project-/')
|
||||||
|
|
||||||
|
echo "version=\"$VERSION\""
|
||||||
|
echo "project=$PROJECT"
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
SCRIPT="$SCRIPT_DIR/get-magento-version.sh"
|
||||||
|
FIXTURES="$SCRIPT_DIR/fixtures"
|
||||||
|
PASS=0
|
||||||
|
FAIL=0
|
||||||
|
|
||||||
|
assert_eq() {
|
||||||
|
local label="$1" expected="$2" actual="$3"
|
||||||
|
if [ "$expected" = "$actual" ]; then
|
||||||
|
echo "PASS: $label"
|
||||||
|
PASS=$((PASS + 1))
|
||||||
|
else
|
||||||
|
echo "FAIL: $label"
|
||||||
|
echo " expected: $expected"
|
||||||
|
echo " actual: $actual"
|
||||||
|
FAIL=$((FAIL + 1))
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
field() {
|
||||||
|
echo "$1" | grep "^${2}=" | cut -d= -f2-
|
||||||
|
}
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/store-lock")
|
||||||
|
assert_eq "store lock: version" '"2.4.7"' "$(field "$OUT" version)"
|
||||||
|
assert_eq "store lock: project" "magento/project-community-edition" "$(field "$OUT" project)"
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/store-v-prefix")
|
||||||
|
assert_eq "store v-prefix: version" '"2.4.6"' "$(field "$OUT" version)"
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/enterprise")
|
||||||
|
assert_eq "enterprise: version" '"2.4.7-p1"' "$(field "$OUT" version)"
|
||||||
|
assert_eq "enterprise: project" "magento/project-enterprise-edition" "$(field "$OUT" project)"
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/mage-os")
|
||||||
|
assert_eq "mage-os: version" '"1.0.0"' "$(field "$OUT" version)"
|
||||||
|
assert_eq "mage-os: project" "mage-os/project-community-edition" "$(field "$OUT" project)"
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/store-json")
|
||||||
|
assert_eq "store json: version" '"2.4.6-p1"' "$(field "$OUT" version)"
|
||||||
|
assert_eq "store json: project" "magento/project-community-edition" "$(field "$OUT" project)"
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/extension")
|
||||||
|
assert_eq "extension: version" '""' "$(field "$OUT" version)"
|
||||||
|
assert_eq "extension: project" "" "$(field "$OUT" project)"
|
||||||
|
|
||||||
|
OUT=$(bash "$SCRIPT" "$FIXTURES/empty")
|
||||||
|
assert_eq "empty dir: version" '""' "$(field "$OUT" version)"
|
||||||
|
assert_eq "empty dir: project" "" "$(field "$OUT" project)"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "$PASS passed, $FAIL failed"
|
||||||
|
[ "$FAIL" -eq 0 ]
|
||||||
Reference in New Issue
Block a user