diff --git a/.github/workflows/_internal_init_magento.yaml b/.github/workflows/_internal_init_magento.yaml new file mode 100644 index 00000000..398a690a --- /dev/null +++ b/.github/workflows/_internal_init_magento.yaml @@ -0,0 +1,65 @@ +name: Init Magento Test + +on: + workflow_dispatch: {} + push: + branches: + - main + paths: + - "init-magento/**" + - ".github/workflows/_internal_init_magento.yaml" + - "supported-version/**" + - "!(**/*.md)" + pull_request: + branches: + - main + paths: + - "init-magento/**" + - ".github/workflows/_internal_init_magento.yaml" + - "supported-version/**" + - "!(**/*.md)" + +env: + 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: all + id: supported-version + - run: echo ${{ steps.supported-version.outputs.matrix }} + + init-test: + needs: compute_matrix + strategy: + matrix: ${{ fromJSON(needs.compute_matrix.outputs.matrix) }} + fail-fast: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v${{ matrix.composer }} + coverage: none + + - run: composer create-project --repository-url="https://mirror.mage-os.org" "${{ matrix.magento }}" ${{ env.magento_folder }} --no-install + shell: bash + name: Create Magento ${{ matrix.magento }} Project + + - uses: ./init-magento + name: Init Magento + with: + magento_directory: ${{ env.magento_folder }} + + - run: composer install + shell: bash + working-directory: ${{ env.magento_folder }} diff --git a/README.md b/README.md index 672d6d3d..d7e46ab9 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,16 @@ Opinionated Github Actions and Workflows to make building, testing, and maintain ## Workflows -| Workflow Name | Description | -| -------------------------------------------------------- | ---------------------------------------------------------------------- | +| Workflow Name | Description | +| ------------------------------------------------------------- | ---------------------------------------------------------------------- | | [Integration Test](./.github/workflows/integration-README.md) | A Github Workflow that runs the Integration Tests of a Magento Package | ## Actions -| Action Name | Description | -| ------------------------------------------------ | ------------------------------------------------------------------ | -| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package | -| [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 +| Action Name | Description | +| ------------------------------------------------------ | ----------------------------------------------------------------------------------------- | +| [Init Magento](./init-magento/README.md) | A Github Action that initializes a Magento project up until `composer install` | +| [Unit Test](./unit-test/README.md) | A Github Action that runs the Unit Tests a Magento Package | +| [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/init-magento/README.md b/init-magento/README.md new file mode 100644 index 00000000..6876d6d2 --- /dev/null +++ b/init-magento/README.md @@ -0,0 +1,104 @@ +# Init Magento + +A Github Action that initializes a Magento project up until `composer install`. This is extremely useful for getting Magento installations to a "common" point for further operations like Unit Tests, Installation Tests, and Integration Tests. + +This action will: + +- Apply "CI" hotfixes which interfere with common CI pipeline operations. +- Create, store, and pull a common composer cache for re-use across other actions. + +## Inputs + +See the [action.yml](./action.yml) + + +### Usage for an extension + +```yml +name: Do Something with Magento + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + magento_directory: ../magento2 + +jobs: + compute_matrix: + runs-on: ubuntu-latest + steps: + steps: + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + tools: composer:v2 + + - run: composer create-project --repository-url="https://repo.magento.com" "v2.4.5-p1" ${{ env.magento_directory }} --no-install + shell: bash + env: + COMPOSER_AUTH: ${{ env.COMPOSER_AUTH }} + name: Create Magento Project + + - uses: graycoreio/github-actions-magento2/init-magento@main + name: "Initialize Magento" + with: + magento_directory: ${{ env.magento_directory }} + + - run: composer config repositories.local path $GITHUB_WORKSPACE + name: Add Github Repo for Testing + working-directory: ${{ env.magento_directory }} + shell: bash + + - run: composer require my/package "@dev" --no-update && composer install + name: Require and attempt install + working-directory: ${{ env.magento_directory }} + shell: bash + env: + COMPOSER_AUTH: ${{ env.COMPOSER_AUTH }} +``` + +### Usage for a Magento 2 Project + +```yml +name: Do Something with Magento + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + magento_directory: ./ + +jobs: + compute_matrix: + runs-on: ubuntu-latest + steps: + steps: + - name: Set PHP Version + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + tools: composer:v2 + + - uses: graycoreio/github-actions-magento2/init-magento@main + name: "Initialize Magento" + with: + magento_directory: ${{ env.magento_directory }} + + - run: composer install + working-directory: ${{ env.magento_directory }} + shell: bash + env: + COMPOSER_AUTH: ${{ env.COMPOSER_AUTH }} +``` + diff --git a/init-magento/action.yml b/init-magento/action.yml new file mode 100644 index 00000000..e6dc2d51 --- /dev/null +++ b/init-magento/action.yml @@ -0,0 +1,84 @@ +name: "Init Magento" +author: "Graycore" +description: " A Github Action that initializes Magento up until (but not including) `composer install`" +inputs: + magento_directory: + required: true + description: "The folder where Magento will be installed" + + apply_fixes: + required: false + default: 'true' + description: 'Whether or not to automatically apply fixes from the community to common CI problems.' + + composer_cache_key: + required: false + default: '__graycore' + description: A key to version the composer cache. Can be incremented if you need to bust the cache. + +runs: + using: "composite" + steps: + - uses: graycoreio/github-actions-magento2/get-magento-version@main + id: init-magento-get-magento-version + with: + working-directory: ${{ inputs.magento_directory }} + + - run: echo "::set-output name=version::$(php -v | awk 'NR==1{print $2}')" + shell: bash + id: init-magento-get-php-version + + - run: echo "::set-output name=version::$(composer --version | awk '{print $3}')" + shell: bash + name: Compute Composer Version + id: init-magento-get-composer-version + + - name: Get Composer Cache Directory + shell: bash + working-directory: ${{ inputs.magento_directory }} + id: init-magento-composer-cache + run: | + echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: "Cache Composer Packages" + uses: actions/cache@v3 + with: + key: "composer | v5 | ${{ inputs.composer_cache_key }} | ${{ steps.init-magento-get-composer-version.outputs.version }} | ${{ steps.init-magento-get-magento-version.outputs.version }} | ${{ steps.init-magento-get-php-version.outputs.version }}" + restore-keys: | + composer | v5 | ${{ inputs.composer_cache_key }} | + path: ${{ steps.init-magento-composer-cache.outputs.dir }} + + - run: composer require monolog/monolog:"<2.7.0" --no-update + shell: bash + name: Fixup Monolog (https://github.com/magento/magento2/pull/35596) + working-directory: ${{ inputs.magento_directory }} + if: | + steps.init-magento-get-magento-version.outputs.version == '"2.4.4"' && inputs.apply_fixes == 'true' + + - run: composer require "dotmailer/dotmailer-magento2-extension-package:4.6.0-p2 as 4.6.0" --no-update + shell: bash + name: Fixup Dotmailer (https://devdocs.magento.com/guides/v2.4/release-notes/release-notes-2-4-0-commerce.html#dotdigital-1) + working-directory: ${{ inputs.magento_directory }} + if: | + steps.init-magento-get-magento-version.outputs.version == '"2.4.0"' && inputs.apply_fixes == 'true' + + - run: | + composer config --no-interaction allow-plugins.dealerdirect/phpcodesniffer-composer-installer true + composer config --no-interaction allow-plugins.laminas/laminas-dependency-plugin true + composer config --no-interaction allow-plugins.magento/* true + name: Fixup Composer Plugins + shell: bash + working-directory: ${{ inputs.magento_directory }} + if: | + !startsWith(steps.init-magento-get-composer-version.outputs.version, 1) && inputs.apply_fixes == 'true' + + - run: | + composer global require hirak/prestissimo + name: Install composer plugin for parallel downloads + shell: bash + working-directory: ${{ inputs.magento_directory }} + if: ${{ startsWith(steps.init-magento-get-composer-version.outputs.version, '1') }} + +branding: + icon: "code" + color: "green"