mirror of
https://github.com/graycoreio/github-actions-magento2.git
synced 2026-06-08 19:46:41 +00:00
feat(get-magento-version): pull version from lockfile if it exists (#242)
Additionally, this exposes a new `output` called project which tells you which project was used.
This commit is contained in:
@@ -37,8 +37,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
working-directory: ../magento2
|
working-directory: ../magento2
|
||||||
|
|
||||||
- name: Fail if key does not match
|
- name: Fail if version does not match
|
||||||
if: steps.magento-version.outputs.version != '"2.4.5-p1"'
|
if: steps.magento-version.outputs.version != '"2.4.5-p1"'
|
||||||
shell: bash
|
shell: bash
|
||||||
run: echo "${{ steps.magento-version.outputs.version }}" && exit 1
|
run: echo "${{ steps.magento-version.outputs.version }}" && exit 1
|
||||||
|
|
||||||
|
- name: Fail if project does not match
|
||||||
|
if: steps.magento-version.outputs.project != 'magento/project-community-edition'
|
||||||
|
shell: bash
|
||||||
|
run: echo "${{ steps.magento-version.outputs.project }}" && exit 1
|
||||||
|
|
||||||
@@ -2,29 +2,42 @@ name: "Get Magento Version"
|
|||||||
author: "Graycore"
|
author: "Graycore"
|
||||||
description: " A Github Action that determines the currently installed version of Magento"
|
description: " A Github Action that determines the currently installed version of Magento"
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
working-directory:
|
working-directory:
|
||||||
default: $GITHUB_WORKSPACE
|
default: $GITHUB_WORKSPACE
|
||||||
description: "The current working directory of the action"
|
description: "The current working directory of the action"
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
version: # id of output
|
version:
|
||||||
description: 'The determined version of Magento'
|
description: 'The resolved Magento version (e.g. 2.4.6-p14)'
|
||||||
value: ${{ steps.get-magento-version.outputs.version }}
|
value: ${{ steps.get-magento-version.outputs.version }}
|
||||||
|
project:
|
||||||
|
description: 'The Magento project package name (e.g. magento/project-community-edition)'
|
||||||
|
value: ${{ steps.get-magento-version.outputs.project }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- run: |
|
- name: Compute Installed Magento version
|
||||||
echo "version=$(cat composer.json | jq '.require
|
|
||||||
| with_entries( select(.key == "magento/product-community-edition" or .key == "magento/product-enterprise-edition") )
|
|
||||||
| to_entries
|
|
||||||
| .[0].value')" >> $GITHUB_OUTPUT
|
|
||||||
shell: bash
|
|
||||||
working-directory: ${{ inputs.working-directory }}
|
|
||||||
name: Compute Installed Magento version
|
|
||||||
id: get-magento-version
|
id: get-magento-version
|
||||||
|
shell: bash
|
||||||
|
working-directory: ${{ inputs.working-directory }}
|
||||||
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user