Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions .github/workflows/nx-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: NX Integration Test
#description: Workflow to run NX assisted integration tests for Mage-OS projects.
Comment thread
sprankhub marked this conversation as resolved.
on:
workflow_call:
inputs:
repository:
type: string
description: "Repository"
required: true
pr_head:
type: string
description: "head SHA"
required: true
pr_base:
type: string
description: "pr base SHA"
required: true
workflow_dispatch:
inputs:
repository:
type: string
description: "Repository"
required: true
pr_head:
type: string
description: "head SHA"
required: true
pr_base:
type: string
description: "pr base SHA"
required: true

jobs:
debug:
name: Debug
runs-on: ubuntu-latest
steps:
- name: debug
shell: bash
env:
repository: ${{ inputs.repository }}
pr_head: ${{ inputs.pr_head }}
pr_base: ${{ inputs.pr_base }}
run: |
echo "input was"
echo "repository: ${repository}"
echo "pr_head: ${pr_head}"
echo "pr_base: ${pr_base}"

matrix-calculator:
outputs:
php_versions: ${{ steps.calculate-matrix.outputs.php_versions }}
database_versions: ${{ steps.calculate-matrix.outputs.database_versions }}
search_versions: ${{ steps.calculate-matrix.outputs.search_versions }}
message_queue_versions: ${{ steps.calculate-matrix.outputs.message_queue_versions }}
cache_versions: ${{ steps.calculate-matrix.outputs.cache_versions }}
http_cache_versions: ${{ steps.calculate-matrix.outputs.http_cache_versions }}

runs-on: ubuntu-latest
steps:
- name: Run Matrix Calulator
id: calculate-matrix
uses: mage-os/github-actions/supported-services-matrix-calculator@main
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.pr_head }}

- name: Calculated Result
shell: bash
env:
php_versions: ${{ steps.calculate-matrix.outputs.php_versions }}
database_versions: ${{ steps.calculate-matrix.outputs.database_versions }}
search_versions: ${{ steps.calculate-matrix.outputs.search_versions }}
message_queue_versions: ${{ steps.calculate-matrix.outputs.message_queue_versions }}
cache_versions: ${{ steps.calculate-matrix.outputs.cache_versions }}
http_cache_versions: ${{ steps.calculate-matrix.outputs.http_cache_versions }}
run: |
echo "PHP Versions: $php_versions"
echo "database_versions: $database_versions"
echo "search_versions: $search_versions"
echo "message_queue_versions: $message_queue_versions"
echo "cache_versions: $cache_versions"
echo "http_cache_versions: $http_cache_versions"

nx-project-setup:
runs-on: ubuntu-latest
steps:
- name: Run Nx Project Setup
uses: mage-os/github-actions/nx-integration-tests-setup@main
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.pr_head }}
pr_base: ${{ inputs.pr_base }}

integration-tests:
needs:
- matrix-calculator
- nx-project-setup
strategy:
fail-fast: false
matrix:
php_version: ${{ fromJSON(needs.matrix-calculator.outputs.php_versions) }}
database_version: ${{ fromJSON(needs.matrix-calculator.outputs.database_versions) }}
search_version: ${{ fromJSON(needs.matrix-calculator.outputs.search_versions) }}
message_queue_version: ${{ fromJSON(needs.matrix-calculator.outputs.message_queue_versions) }}
cache_version: ${{ fromJSON(needs.matrix-calculator.outputs.cache_versions) }}
http_cache_version: ${{ fromJSON(needs.matrix-calculator.outputs.http_cache_versions) }}
runs-on: ubuntu-latest
steps:
- name: Project Cache
uses: actions/cache/restore@v3
with:
path: main
key: ${{ runner.os }}-project-${{ inputs.ref }}

# could probably swap this to a docker container in future
- name: Install NX
working-directory: ./main
run: |
npm install -g nx@^15.4

- name: Print Affected
working-directory: ./main
run: |
AFFECTED_OUTPUT=/tmp/affect.json
nx print-affected --head=HEAD --base=remotes/origin/${{ inputs.pr_base }} > ${AFFECTED_OUTPUT}
cat ${AFFECTED_OUTPUT}
echo "Affected Projects: $(jq .projects ${AFFECTED_OUTPUT})"

- name: Setup Warden Environment
uses: mage-os/github-actions/warden/setup-environment@main
with:
php_version: ${{ matrix.php_version }}
database: ${{ matrix.database_version }}
search: ${{ matrix.search_version }}
rabbitmq: ${{ matrix.message_queue_version }}
redis: ${{ matrix.cache_version }}
varnish: ${{ matrix.http_cache_version }}
base_directory: "./main"

- name: Setup config for Integration tests
uses: mage-os/github-actions/warden/integration-tests@main
with:
search: ${{ matrix.search_version }}
rabbitmq: ${{ matrix.message_queue_version }}
redis: ${{ matrix.cache_version }}
run_memory_test: 0
run_magento_integration_tests: 0
run_magento_integration_tests_real_suite: 0
base_directory: "./main"

- name: Run Integration Tests (Real)
working-directory: ./main
run: |
export WARDEN="$(dirname $(pwd))/warden/bin/warden"
nx affected --target=test:integration --head=HEAD --base=remotes/origin/${{ inputs.pr_base }}
118 changes: 118 additions & 0 deletions nx-integration-tests-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: "Nx Integration Tests Setup"
author: "Mage-OS"
description: "Setup and cache Nx project, this can then be reused with all service combinations."

inputs:
repository:
type: string
description: "Repository"
required: true
ref:
type: string
description: "head SHA"
required: true
pr_base:
type: string
description: "pr base SHA"
required: true


runs:
using: "composite"
steps:
- name: Checkout PR commit
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
path: main
# Need to do this otherwise Nx cant determine diff
fetch-depth: 0

- name: Fetch base
working-directory: ./main
shell: bash
run: git fetch origin ${{ inputs.pr_base }}

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- id: get-composer-and-php-version
name: Get Composer & PHP Version
working-directory: ./main
shell: bash
run: |
echo "php_version=$(jq -c .services.php[0] supported-services.json)" >> "$GITHUB_OUTPUT"
echo "composer_version=$(jq -rc .services.composer[0] supported-services.json)" >> "$GITHUB_OUTPUT"
- name: Composer Install
uses: php-actions/composer@v6
with:
version: ${{ steps.get-composer-and-php-version.outputs.composer_version }}
php_version: ${{ steps.get-composer-and-php-version.outputs.php_version }}
args: "--ignore-platform-reqs --optimize-autoloader"
working_dir: main

# could probably swap this to a docker container in future
- name: Install NX
working-directory: ./main
shell: bash
run: |
npm install -g nx@^15.4

# should be able to cache this in future also
- name: Checkout Nx Repo
uses: actions/checkout@v4
with:
repository: adamzero1/nx-for-php
Comment thread
sprankhub marked this conversation as resolved.
ref: docker-wrapper-2
path: nx

- name: Copy in NX files
working-directory: ./main
shell: bash
run: |
NXDIR="../nx"
cp -r ${NXDIR}/nx ./
cp ${NXDIR}/nx.json ./
cp ${NXDIR}/package.json ./
cp ${NXDIR}/package-lock.json ./

- name: Install NPM Deps
working-directory: ./main
shell: bash
run: |
npm ci

- name: Generate Nx Workspace
working-directory: ./main
shell: bash
run: |
npm run generate-workspace -- --commands=test:unit,test:integration \
--test:unit='if [ -d {{ MODULE_PATH }}Test/Unit ]; then ${WARDEN} env exec -T php-fpm ./vendor/bin/phpunit -c dev/tests/unit/phpunit.xml {{ MODULE_PATH }}Test/Unit; else echo "{{ MODULE_NAME }} has no unit test; fi' \
--test:integration='${WARDEN} env exec -T --workdir /var/www/html/dev/tests/integration php-fpm ../../../vendor/bin/phpunit --configuration phpunit.xml.dist --testsuite '"'"'Magento Integration Tests Real Suite'"'"' --filter='"'"'/Magento/{{ MODULE_DIRECTORY }}/|Magento\\{{ MODULE_DIRECTORY }}'"'"' --log-junit=../../../phpunit-output/junit/{{ MODULE_DIRECTORY }}.xml --coverage-html=../../../phpunit-output/coverage-html/{{ MODULE_DIRECTORY }}'

- name: Print Affected
working-directory: ./main
shell: bash
run: |
AFFECTED_OUTPUT=/tmp/affect.json
nx print-affected --head=HEAD --base=remotes/origin/${{ inputs.pr_base }} > ${AFFECTED_OUTPUT}
echo "Affected Projects: $(jq .projects ${AFFECTED_OUTPUT})"

# just to get some timings
- name: Print Affected2
working-directory: ./main
shell: bash
run: |
AFFECTED_OUTPUT=/tmp/affect.json
nx print-affected --head=HEAD --base=remotes/origin/${{ inputs.pr_base }} > ${AFFECTED_OUTPUT}
echo "Affected Projects: $(jq .projects ${AFFECTED_OUTPUT})"

- name: Project Cache
uses: actions/cache/save@v3
with:
path: main
key: ${{ runner.os }}-project-${{ inputs.ref }}
63 changes: 63 additions & 0 deletions supported-services-matrix-calculator/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Supported Services Matrix Calculator"
author: "Mage-OS"
description: "Calulate a matrix of all supported services (based off supported-services.json)"

inputs:
repository:
type: string
description: "Repository"
required: true
ref:
type: string
description: "head SHA"
required: true

outputs:
php_versions:
description: The applicable PHP versions
value: ${{ steps.set-matrix.outputs.php_versions }}
database_versions:
description: The applicable DB versions
value: ${{ steps.set-matrix.outputs.database_versions }}
search_versions:
description: The applicable Search versions
value: ${{ steps.set-matrix.outputs.search_versions }}
message_queue_versions:
description: The applicable Message Queue versions
value: ${{ steps.set-matrix.outputs.message_queue_versions }}
cache_versions:
description: The applicable Cache versions
value: ${{ steps.set-matrix.outputs.cache_versions }}
http_cache_versions:
description: The applicable HTTP Cache versions
value: ${{ steps.set-matrix.outputs.http_cache_versions }}

runs:
using: "composite"
steps:
- name: Checkout PR commit
uses: actions/checkout@v3
Comment thread
adamzero1 marked this conversation as resolved.
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}

- id: set-matrix
name: Calculate Matrix
shell: bash
run: |
echo "php_versions=$(jq -c .services.php supported-services.json)" >> "$GITHUB_OUTPUT"
echo "database_versions=$(jq -c .services.database supported-services.json)" >> "$GITHUB_OUTPUT"
echo "search_versions=$(jq -c .services.search supported-services.json)" >> "$GITHUB_OUTPUT"
echo "message_queue_versions=$(jq -c .services.message_queue supported-services.json)" >> "$GITHUB_OUTPUT"
echo "cache_versions=$(jq -c .services.cache supported-services.json)" >> "$GITHUB_OUTPUT"
echo "http_cache_versions=$(jq -c .services.http_cache supported-services.json)" >> "$GITHUB_OUTPUT"

- name: Debug output
shell: bash
run: |
echo "PHP Versions: ${{ steps.set-matrix.outputs.php_versions }}"
echo "database Versions: ${{ steps.set-matrix.outputs.database_versions }}"
echo "search Versions: ${{ steps.set-matrix.outputs.search_versions }}"
echo "message_queue Versions: ${{ steps.set-matrix.outputs.message_queue_versions }}"
echo "cache Versions: ${{ steps.set-matrix.outputs.cache_versions }}"
echo "http_cache Versions: ${{ steps.set-matrix.outputs.http_cache_versions }}"