From f1abf7e5247fb0c30c6135c9785d327fc12033b5 Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:37:25 -0400 Subject: [PATCH 1/8] feat(setup-magento): create unified setup action Adds a unified setup action for stores and extensions, making the CI environment more consistent. --- .../workflows/_internal-setup-magento.yaml | 125 ++++++++++++++++++ setup-magento/README.md | 79 +++++++++++ setup-magento/action.yml | 100 ++++++++++++++ 3 files changed, 304 insertions(+) create mode 100644 .github/workflows/_internal-setup-magento.yaml create mode 100644 setup-magento/README.md create mode 100644 setup-magento/action.yml diff --git a/.github/workflows/_internal-setup-magento.yaml b/.github/workflows/_internal-setup-magento.yaml new file mode 100644 index 00000000..d6af7ca2 --- /dev/null +++ b/.github/workflows/_internal-setup-magento.yaml @@ -0,0 +1,125 @@ +name: Setup Magento Test + +on: + workflow_dispatch: {} + push: + branches: + - main + paths: + - "setup-magento/**" + - ".github/workflows/_internal-setup-magento.yaml" + - "supported-version/**" + - "!(**/*.md)" + pull_request: + branches: + - main + paths: + - "setup-magento/**" + - ".github/workflows/_internal-setup-magento.yaml" + - "supported-version/**" + - "!(**/*.md)" + +env: + PSEUDO_REPO_FOLDER: ../magento_repo + magento_folder: ../magento2 + +jobs: + compute_matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.supported-version.outputs.matrix }} + steps: + - uses: actions/checkout@v3 + - uses: ./supported-version + with: + kind: currently-supported + id: supported-version + - run: echo ${{ steps.supported-version.outputs.matrix }} + + setup-magento-store: + needs: compute_matrix + strategy: + matrix: ${{ fromJSON(needs.compute_matrix.outputs.matrix) }} + fail-fast: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - run: | + PSEUDO_STORE_FULL_PATH=$(realpath "${{ env.PSEUDO_REPO_FOLDER }}") + echo "PSEUDO_STORE_FULL_PATH=$PSEUDO_STORE_FULL_PATH" >> $GITHUB_ENV + name: Generate Full Pseudo Store Path + shell: bash + + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v${{ matrix.composer }} + + - uses: actions/cache@v3 + id: setup-magento-store-cache + with: + key: setup-magento-ci | ${{ runner.os }} | ${{ matrix.magento }} + path: ${{ env.PSEUDO_STORE_FULL_PATH }} + + - run: composer create-project --repository-url="https://mirror.mage-os.org" "${{ matrix.magento }}" "${{ env.PSEUDO_REPO_FOLDER }}" --no-install + name: Create Store to simulate a real Magento store in a real repo. + if: steps.setup-magento-store-cache.outputs.cache-hit != 'true' + + - uses: ./fix-magento-install + name: Fix Magento Out of Box Install Issues + with: + magento_directory: ${{ env.PSEUDO_REPO_FOLDER }} + if: steps.setup-magento-store-cache.outputs.cache-hit != 'true' + + - run: composer install + shell: bash + working-directory: "${{ env.PSEUDO_REPO_FOLDER }}" + if: steps.setup-magento-store-cache.outputs.cache-hit != 'true' + + - run: git init && git config user.email "you@example.com" && git config user.name "Your Name" && git add . && git commit -m "init" && git clean -fdx + working-directory: "${{ env.PSEUDO_REPO_FOLDER }}" + if: steps.setup-magento-store-cache.outputs.cache-hit != 'true' + + - run: cp -R ${{ env.PSEUDO_REPO_FOLDER }} ${{ env.magento_folder }} + shell: bash + + - uses: ./setup-magento + with: + php-version: ${{ matrix.php }} + tools: composer:v${{ matrix.composer }} + mode: store + working-directory: ${{ env.magento_folder }} + + - uses: graycoreio/github-actions-magento2/cache-magento@cache_magento + with: + mode: 'store' + composer_cache_key: '${{ matrix.magento }}' + + - run: composer install + name: Composer install + shell: bash + working-directory: ${{ steps.setup-magento.outputs.path }} + + setup-magento-extension: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: ./setup-magento + with: + php-version: 8.1 + tools: composer:v2 + mode: extension + magento_version: 2.4.5-p1 + + - uses: graycoreio/github-actions-magento2/cache-magento@cache_magento + with: + mode: 'extension' + composer_cache_key: 'magento-2.4.5-p1' + + - run: composer install + name: Composer install + shell: bash + working-directory: ${{ steps.setup-magento.outputs.path }} diff --git a/setup-magento/README.md b/setup-magento/README.md new file mode 100644 index 00000000..4f49f1a9 --- /dev/null +++ b/setup-magento/README.md @@ -0,0 +1,79 @@ +# Magento 2 Package Installation Test Action + +A Github Action that sets Magento up to the point of composer install. + +## Inputs + +See the [action.yml](./action.yml) + +## Usage + +### Stores + +```yml +name: Setup Magento Store + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + setup-magento-store: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./setup-magento + with: + php-version: 8.1 + tools: composer:v2 + mode: store + working-directory: $GITHUB_WORKSPACE + + - run: composer install + name: Composer install + shell: bash + working-directory: ${{ steps.setup-magento.outputs.path }} +``` + +### Extensions + +```yml +name: Setup Magento Store + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + setup-magento-extension: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: ./setup-magento + with: + php-version: 8.1 + tools: composer:v2 + mode: extension + magento_version: 2.4.5-p1 + + - run: composer config repositories.local path $GITHUB_WORKSPACE + name: Add Github Repo for Testing + working-directory: ${{ steps.setup-magento.outputs.path }} + shell: bash + + - run: composer require my/package "@dev" + name: Attempt install + working-directory: ${{ steps.setup-magento.outputs.path }} + shell: bash + env: + COMPOSER_AUTH: ${{ secrets.composer_auth }} +``` diff --git a/setup-magento/action.yml b/setup-magento/action.yml new file mode 100644 index 00000000..ffa67f56 --- /dev/null +++ b/setup-magento/action.yml @@ -0,0 +1,100 @@ +name: "Setup Magento" +author: "Graycore" +description: "This action sets up a Magento instance for further actions like running tests, etc." + +inputs: + php-version: + description: "Setup PHP version." + default: "8.1" + required: true + + tools: + description: "Setup popular tools globally." + required: false + + extensions: + description: "Setup PHP extensions." + required: false + + coverage: + description: "Setup code coverage driver." + required: false + + magento_repository: + required: false + default: "https://mirror.mage-os.org/" + description: "Where to install Magento from" + + magento_version: + required: false + default: '~2.4.5' + description: "The version of Magento to use. This is only relevant if you are testing an extension." + + apply_fixes: + required: false + default: 'false' + description: "Whether or not to apply fixes during setup." + + mode: + required: true + default: 'extension' + description: "The mode for setup, one of: `extension` or `store`." + + working-directory: + required: false + default: "." + description: "The working directory to run the action in." + +outputs: + path: + description: "The absolute path to where Magento was set up." + value: ${{ steps.setup-magento-get-magento-path.outputs.path }} + +runs: + using: "composite" + steps: + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + tools: ${{ inputs.tools }} + coverage: ${{ inputs.coverage }} + extensions: ${{ inputs.coverage }} + + - run: | + MAGENTO_DIRECTORY="" + if [ "${{ inputs.mode }}" = 'extension' ]; then + MAGENTO_DIRECTORY="../magento2" + else + MAGENTO_DIRECTORY="${{ inputs.working_directory }}" + fi + echo "MAGENTO_DIRECTORY=$MAGENTO_DIRECTORY" >> $GITHUB_OUTPUT + id: setup-magento-compute-directory + shell: bash + + - run: | + mkdir -p ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }} + name: Make a directory that may not exist. + shell: bash + if: inputs.mode == 'extension' + + - run: composer create-project --repository-url="${{ inputs.magento_repository }}" "${{ inputs.magento_version }}" ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }} --no-install + working-directory: ${{ inputs.working-directory }} + shell: bash + name: Create Magento ${{ inputs.magento_version }} Project + if: inputs.mode == 'extension' + + - uses: graycoreio/github-actions-magento2/fix-magento-install@fix_magento_action + name: Fix Magento Out of Box Install Issues + with: + magento_directory: ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }} + if: inputs.mode == 'extension' || inputs.apply_fixes == 'true' + + - run: | + echo "path=$(realpath ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }})" >> $GITHUB_OUTPUT + shell: bash + id: setup-magento-get-magento-path + +branding: + icon: "code" + color: "green" From 94f6756c276de65a8924a4390d8aa5829ec486ce Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:39:28 -0400 Subject: [PATCH 2/8] docs --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba97b6bb..88aab8b4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain | ------------------------------------------------------ | ----------------------------------------------------------------------------------------- | | [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package | | [Fix Magento Install](./fix-magento-install/README.md) | A Github Action that fixes Magento before `composer install` | -| [Cache Magento](./cache-magento/README.md) | A Github Action that creates a composer cache for a Magento extension or store. | +| [Cache Magento](./cache-magento/README.md) | A Github Action that creates a composer cache for a Magento extension or store. | +| [Setup Magento](./setup-magento/README.md) | A Github Action that sets up Magento before `composer install` for an extension or store. | | [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 From df50e86d12a2e35893fda60654ce6e3945d43c09 Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:40:04 -0400 Subject: [PATCH 3/8] ci From 98edc00d733963d12a4a72c50cce8c84bb703832 Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:41:39 -0400 Subject: [PATCH 4/8] main --- .github/workflows/_internal-setup-magento.yaml | 4 ++-- setup-magento/action.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/_internal-setup-magento.yaml b/.github/workflows/_internal-setup-magento.yaml index d6af7ca2..023a85bb 100644 --- a/.github/workflows/_internal-setup-magento.yaml +++ b/.github/workflows/_internal-setup-magento.yaml @@ -92,7 +92,7 @@ jobs: mode: store working-directory: ${{ env.magento_folder }} - - uses: graycoreio/github-actions-magento2/cache-magento@cache_magento + - uses: graycoreio/github-actions-magento2/cache-magento@main with: mode: 'store' composer_cache_key: '${{ matrix.magento }}' @@ -114,7 +114,7 @@ jobs: mode: extension magento_version: 2.4.5-p1 - - uses: graycoreio/github-actions-magento2/cache-magento@cache_magento + - uses: graycoreio/github-actions-magento2/cache-magento@main with: mode: 'extension' composer_cache_key: 'magento-2.4.5-p1' diff --git a/setup-magento/action.yml b/setup-magento/action.yml index ffa67f56..ce750a0f 100644 --- a/setup-magento/action.yml +++ b/setup-magento/action.yml @@ -84,7 +84,7 @@ runs: name: Create Magento ${{ inputs.magento_version }} Project if: inputs.mode == 'extension' - - uses: graycoreio/github-actions-magento2/fix-magento-install@fix_magento_action + - uses: graycoreio/github-actions-magento2/fix-magento-install@main name: Fix Magento Out of Box Install Issues with: magento_directory: ${{ steps.setup-magento-compute-directory.outputs.MAGENTO_DIRECTORY }} From 43fce782c524dffadaed9b914cca38c447248682 Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:42:41 -0400 Subject: [PATCH 5/8] main --- .github/workflows/_internal-setup-magento.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/_internal-setup-magento.yaml b/.github/workflows/_internal-setup-magento.yaml index 023a85bb..ab67b44f 100644 --- a/.github/workflows/_internal-setup-magento.yaml +++ b/.github/workflows/_internal-setup-magento.yaml @@ -112,12 +112,12 @@ jobs: php-version: 8.1 tools: composer:v2 mode: extension - magento_version: 2.4.5-p1 + magento_version: magento/project-community-edition:2.4.5-p1 - uses: graycoreio/github-actions-magento2/cache-magento@main with: mode: 'extension' - composer_cache_key: 'magento-2.4.5-p1' + composer_cache_key: 'magento/project-community-edition:2.4.5-p1' - run: composer install name: Composer install From 7eb7d5a25912440df20036ad2cdf8b8cc49e334c Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:45:33 -0400 Subject: [PATCH 6/8] main --- .github/workflows/_internal-setup-magento.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/_internal-setup-magento.yaml b/.github/workflows/_internal-setup-magento.yaml index ab67b44f..0b6cc51c 100644 --- a/.github/workflows/_internal-setup-magento.yaml +++ b/.github/workflows/_internal-setup-magento.yaml @@ -108,6 +108,7 @@ jobs: - uses: actions/checkout@v3 - uses: ./setup-magento + id: setup-magento with: php-version: 8.1 tools: composer:v2 From 6647106e44bcf3a9d032876c9501f6994d89c6f5 Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Sun, 30 Oct 2022 12:46:13 -0400 Subject: [PATCH 7/8] tmp --- .github/workflows/_internal-setup-magento.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/_internal-setup-magento.yaml b/.github/workflows/_internal-setup-magento.yaml index 0b6cc51c..f3746e29 100644 --- a/.github/workflows/_internal-setup-magento.yaml +++ b/.github/workflows/_internal-setup-magento.yaml @@ -86,6 +86,7 @@ jobs: shell: bash - uses: ./setup-magento + id: setup-magento with: php-version: ${{ matrix.php }} tools: composer:v${{ matrix.composer }} From 443bbebab90790d4387538ec545be5d838f7c4ab Mon Sep 17 00:00:00 2001 From: Damien Retzinger Date: Mon, 31 Oct 2022 08:31:52 -0400 Subject: [PATCH 8/8] fix patH --- setup-magento/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup-magento/action.yml b/setup-magento/action.yml index ce750a0f..89d8fd7d 100644 --- a/setup-magento/action.yml +++ b/setup-magento/action.yml @@ -66,7 +66,7 @@ runs: if [ "${{ inputs.mode }}" = 'extension' ]; then MAGENTO_DIRECTORY="../magento2" else - MAGENTO_DIRECTORY="${{ inputs.working_directory }}" + MAGENTO_DIRECTORY="${{ inputs.working-directory }}" fi echo "MAGENTO_DIRECTORY=$MAGENTO_DIRECTORY" >> $GITHUB_OUTPUT id: setup-magento-compute-directory