Skip to content

Commit

Permalink
refactor Sylius#14710 Refactor CI (jakubtobiasz)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13 <!-- see the comment below -->                  |
| Bug fix?        | no                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no <!-- don't forget to update the UPGRADE-*.md file --> |
| Related tickets | n/a                      |
| License         | MIT                                                          |

Finally, I can present you our brand-new CI pipeline.

Core features:
✅ Number of jobs had been reduced from ~230 to ~45 – thanks to this change we save a bit of time on picking a next job by a worker, as we can run only 30 concurrent runs
✅ Workflow-level cache – Previously, cache was reused when was matching the key. To make sure the dependencies are always up-to-date, we cache dependencies on `Static check` run and re-use it across the same workflow run.
✅ Better jobs view – I've split the previous workflow into smaller pieces, so we achieved better overview. Preview:
<img width="1493" alt="CleanShot 2023-01-12 at 15 54 32@2x" src="https://user-images.githubusercontent.com/80641364/212099697-aa0e17ec-c397-446a-bb0a-5a9ba0295dee.png">
✅ Easier to maintain – smaller files allow modifying workflow easier.
✅ Faster feedback – sometimes when any of static checks failed we still have been running the whole test suite (e2e, packages, etc.). Now if any of static check fails, then no further test will be run.

I believe it's a great entry point for further optimizations 💃🏼!

Commits
-------

e2edcb2 Refactor CI
  • Loading branch information
GSadee authored Jan 18, 2023
2 parents 4ea270c + e2edcb2 commit a3e6aeb
Show file tree
Hide file tree
Showing 15 changed files with 839 additions and 1,487 deletions.
1,256 changes: 0 additions & 1,256 deletions .github/workflows/application.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Continuous Integration

on:
pull_request:
paths-ignore:
- "adr/**"
- "docs/**"
- "*.md"
schedule:
-
cron: "0 1 * * 6" # Run at 1am every Saturday
workflow_dispatch: ~
push: ~

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
static-checks:
name: Static checks
uses: ./.github/workflows/ci_static-checks.yml
e2e-mariadb:
name: End-to-end tests (MariaDB)
needs: static-checks
uses: ./.github/workflows/ci_e2e-mariadb.yml
e2e-mysql:
name: End-to-end tests (MySQL)
needs: static-checks
uses: ./.github/workflows/ci_e2e-mysql.yml
e2e-pgsql:
name: End-to-end tests (PostgreSQL)
needs: static-checks
uses: ./.github/workflows/ci_e2e-pgsql.yml
e2e-customs:
name: End-to-end tests (Customs)
needs: static-checks
uses: ./.github/workflows/ci_e2e-customs.yml
packages:
name: Packages
needs: static-checks
uses: ./.github/workflows/ci_packages.yml
notify-about-build-failure:
name: "Notify about build failure"
needs: [static-checks, e2e-mariadb, e2e-mysql, e2e-pgsql, e2e-customs]
if: failure() && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'release')
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: "Process data"
id: process-data
shell: bash
run: |
echo "branch=$(echo ${{ github.ref }} | sed 's/refs\/heads\///g' | sed 's/refs\/tags\///g')" >> $GITHUB_OUTPUT
echo "sha=$(echo ${{ github.sha }} | cut -c 1-12)" >> $GITHUB_OUTPUT
- name: "Notify on Slack"
uses: edge/simple-slack-notify@master
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: env.SLACK_WEBHOOK_URL != null
with:
channel: "#builds"
username: "GitHub Actions"
text: |
*<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | ${{ github.workflow }} #${{ github.run_number }} build on ${{ github.repository }} repository has failed for ${{ steps.process-data.outputs.branch }} branch.>*
${{ needs.static-checks.result == 'success' && ':+1:' || ':x:' }} Static Checks
${{ needs.e2e-mariadb.result == 'success' && ':+1:' || ':x:' }} End-to-End (MariaDB)
${{ needs.e2e-mysql.result == 'success' && ':+1:' || ':x:' }} End-to-End (MySQL)
${{ needs.e2e-pgsql.result == 'success' && ':+1:' || ':x:' }} End-to-End (PostgreSQL)
${{ needs.e2e-customs.result == 'success' && ':+1:' || ':x:' }} End-to-End (Customs)
_ _ _ _ _ _ _
color: "danger"
fields: |
[
{ "title": "Repository", "value": "<https://github.com/${{ github.repository }} | ${{ github.repository }}>", "short": true },
{ "title": "Action", "value": "<https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | ${{ github.workflow }} #${{ github.run_number }}>", "short": true },
{ "title": "Reference", "value": "<https://github.com/${{ github.repository }}/tree/${{ steps.process-data.outputs.branch }} | ${{ steps.process-data.outputs.branch }}>", "short": true },
{ "title": "Commit", "value": "<https://github.com/${{ github.repository }}/commit/${{ github.sha }} | ${{ steps.process-data.outputs.sha }}>", "short": true },
{ "title": "Event", "value": "${{ github.event_name }}", "short": true }
]
64 changes: 64 additions & 0 deletions .github/workflows/ci_e2e-customs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: End-to-End (Customs)

on:
workflow_dispatch: ~
workflow_call: ~

jobs:
behat-no-js-unstable-symfony:
runs-on: ubuntu-latest
name: "Test Application without JS (PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} [Unstable], MySQL ${{ matrix.mysql }}, Twig ${{ matrix.twig }}, DBAL ${{ matrix.dbal }}.x, API Platform ${{ matrix.api-platform }})"
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
php: [ "8.1" ]
symfony: [ "^6.2" ]
mysql: [ "8.0" ]

env:
APP_ENV: test_cached
DATABASE_URL: "mysql://root:[email protected]/sylius?charset=utf8mb4&serverVersion=${{ matrix.mysql }}"

steps:
-
uses: actions/checkout@v3

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: "Restore dependencies"
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"
restore-keys: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"

- name: Change minimum-stability to beta
run: composer config minimum-stability beta

- name: Build application
uses: jakubtobiasz/[email protected]
with:
build_type: "sylius"
cache_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"
cache_restore_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"
e2e: "yes"
database_version: ${{ matrix.mysql }}
php_version: ${{ matrix.php }}
symfony_version: ${{ matrix.symfony }}

- name: Run PHPUnit
run: vendor/bin/phpunit --colors=always

- name: Run non-JS Behat
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="~@javascript&&~@todo&&~@cli&&~@no-postgres" || vendor/bin/behat --strict --no-interaction -vvv -f progress --tags="~@javascript&&~@todo&&~@cli&&~@no-postgres" --rerun

- name: Upload Behat logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: "Behat logs (non-JS, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}) [Unstable], MySQL ${{ matrix.mysql }})"
path: etc/build/
if-no-files-found: ignore
70 changes: 70 additions & 0 deletions .github/workflows/ci_e2e-mariadb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: End-to-End (MariaDB)

on:
workflow_dispatch: ~
workflow_call: ~

jobs:
behat-no-js:
runs-on: ubuntu-latest
name: "Test Application without JS (PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}), Twig ${{ matrix.twig }}, DBAL ${{ matrix.dbal }}.x, API Platform ${{ matrix.api-platform }})"
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
php: ["8.0"]
symfony: ["^5.4", "^6.0"]
mariadb: ["10.4.10"]
dbal: ["^2.7", "^3.0"]

env:
APP_ENV: test_cached
DATABASE_URL: "mysql://root:[email protected]/sylius?charset=utf8mb4&serverVersion=mariadb-${{ matrix.mariadb }}"

steps:
-
uses: actions/checkout@v3

- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: "Restore dependencies"
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"
restore-keys: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"

- name: Restrict packages
if: matrix.dbal == '^2.7'
run: composer require --no-update --no-scripts --no-interaction "doctrine/dbal:${{ matrix.dbal }}"

- name: Build application
uses: jakubtobiasz/[email protected]
with:
build_type: "sylius"
cache_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"
cache_restore_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-"
e2e: "yes"
database: "mariadb"
database_version: ${{ matrix.mariadb }}
php_version: ${{ matrix.php }}
symfony_version: ${{ matrix.symfony }}

- name: Run PHPUnit
run: vendor/bin/phpunit --colors=always

- name: Run CLI Behat
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@cli&&~@todo" || vendor/bin/behat --strict --no-interaction -vvv -f progress --tags="@cli&&~@todo" --rerun

- name: Run non-JS Behat
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="~@javascript&&~@todo&&~@cli&&~@no-postgres" || vendor/bin/behat --strict --no-interaction -vvv -f progress --tags="~@javascript&&~@todo&&~@cli&&~@no-postgres" --rerun

- name: Upload Behat logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: "Behat logs (non-JS, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MariaDB ${{ matrix.mariadb }}), DBAL ${{ matrix.dbal }}"
path: etc/build/
if-no-files-found: ignore
Loading

0 comments on commit a3e6aeb

Please sign in to comment.