diff --git a/.github/workflows/_internal-setup-magento.yaml b/.github/workflows/_internal-setup-magento.yaml new file mode 100644 index 00000000..f3746e29 --- /dev/null +++ b/.github/workflows/_internal-setup-magento.yaml @@ -0,0 +1,127 @@ +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 + id: 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@main + 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 + id: setup-magento + with: + php-version: 8.1 + tools: composer:v2 + mode: extension + 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/project-community-edition:2.4.5-p1' + + - run: composer install + name: Composer install + shell: bash + working-directory: ${{ steps.setup-magento.outputs.path }} 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 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..89d8fd7d --- /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@main + 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"