diff --git a/.github/workflows/_internal-get-magento-version.yaml b/.github/workflows/_internal-get-magento-version.yaml new file mode 100644 index 0000000..9998020 --- /dev/null +++ b/.github/workflows/_internal-get-magento-version.yaml @@ -0,0 +1,43 @@ +name: Get Magento Version + +on: + push: + branches: + - main + paths: + - ".github/workflows/_internal-get-magento-version.yaml" + - "get-magento-version/**" + - "!(**/*.md)" + pull_request: + branches: + - main + paths: + - ".github/workflows/_internal-get-magento-version.yaml" + - "get-magento-version/**" + - "!(**/*.md)" + +jobs: + get-magento-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + tools: composer:v2.4.2 + + - run: composer create-project --repository-url="https://mirror.mage-os.org" "magento/project-community-edition:2.4.5-p1" ../magento2 --no-install + shell: bash + name: Create Magento ${{ matrix.magento }} Project + + - uses: ./get-magento-version + id: magento-version + with: + working-directory: ../magento2 + + - name: Fail if key does not match + if: steps.magento-version.outputs.version != '"2.4.5-p1"' + shell: bash + run: echo "${{ steps.magento-version.outputs.version }}" && exit 1 + \ No newline at end of file diff --git a/README.md b/README.md index 7a73d91..672d6d3 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,6 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain | Action Name | Description | | ------------------------------------------------ | ------------------------------------------------------------------ | | [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package | -| [Installation Test](installation-test/README.md) | A Github Action that tests the installability of a Magento Package | -| [Supported Version](supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 | \ No newline at end of file +| [Get Magento Version](./get-magento-version/README.md) | A Github Action that computes the installed Magento version. | +| [Installation Test](./installation-test/README.md) | A Github Action that tests the installability of a Magento Package | +| [Supported Version](./supported-version/README.md) | A Github Action that computes the currently supported Github Actions Matrix for Magento 2 | \ No newline at end of file diff --git a/get-magento-version/README.md b/get-magento-version/README.md new file mode 100644 index 0000000..b8adc8d --- /dev/null +++ b/get-magento-version/README.md @@ -0,0 +1,32 @@ +# "Get Magento Version" Action + +A Github Action that computes an installed Magento version. + +## Inputs + +See the [action.yml](./action.yml) + +## Usage + +```yml +name: Get Magento Version + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + version: + runs-on: ubuntu-latest + name: A job to compute an installed Magento version. + steps: + - uses: actions/checkout@v3 + - uses: graycoreio/github-actions-magento2/get-magento-version@main + id: get-magento-version + - run: echo version ${{ steps.get-magento-version.outputs.version }} + shell: bash +``` diff --git a/get-magento-version/action.yml b/get-magento-version/action.yml new file mode 100644 index 0000000..dc46446 --- /dev/null +++ b/get-magento-version/action.yml @@ -0,0 +1,31 @@ +name: "Get Magento Version" +author: "Graycore" +description: " A Github Action that determines the currently installed version of Magento" + +inputs: + working-directory: + default: $GITHUB_WORKSPACE + description: "The current working directory of the action" + required: false + +outputs: + version: # id of output + description: 'The determined version of Magento' + value: ${{ steps.get-magento-version.outputs.version }} + +runs: + using: "composite" + steps: + - run: | + echo "::set-output name=version::$(cat composer.json | jq '.require + | with_entries( select(.key == "magento/product-community-edition" or .key == "magento/product-enterprise-edition") ) + | to_entries + | .[0].value')" + shell: bash + working-directory: ${{ inputs.working-directory }} + name: Compute Installed Magento version + id: get-magento-version + +branding: + icon: "code" + color: "green"