Skip to content

Website for Robust -> robust.lychen.fr #47

Website for Robust -> robust.lychen.fr

Website for Robust -> robust.lychen.fr #47

Workflow file for this run

name: Tests Symfony projects
env:
REGISTRY: ghcr.io/alpsify/lychen/test
on:
pull_request:
workflow_dispatch: {} # Permet d’exécuter manuellement les jobs de déploiement
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
define-matrix:
name: 'Gather affected projects'
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.projects.outputs.projects }}
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
- name: Define Projects
id: projects
run: |
echo "projects=$(moon query projects --tags symfony --affected --downstream deep | awk 'NR % 2 == 1 {print "\"" $1 "\""}' | paste -sd, - | sed 's/^/\[/; s/$/\]/')" >> "$GITHUB_OUTPUT"
- run: echo ${{ steps.projects.outputs.projects }}
build-and-push-test-image:
if: ${{ needs.define-matrix.outputs.projects != '[]' && needs.define-matrix.outputs.projects != '' }}
name: '${{ matrix.projects }} | Build docker test image'
needs: define-matrix
continue-on-error: true
strategy:
fail-fast: false
matrix:
projects: ${{ fromJSON(needs.define-matrix.outputs.projects) }}
outputs:
matrix_test_image_name: ${{ steps.set-image.outputs.matrix_test_image_name }}
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
with:
auto-install: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate IMAGE_NAME
id: set-image
run: |
# Set for current job
echo "TEST_IMAGE_NAME=${{ env.REGISTRY }}/${{ matrix.projects }}" >> $GITHUB_ENV
# Set for other jobs
echo "matrix_test_image_name=${{ env.REGISTRY }}/${{ matrix.projects }}" >> $GITHUB_OUTPUT
- name: Pull test image if exists
run: docker pull ${{ env.TEST_IMAGE_NAME }}:latest || true
#- name: Copy libs PHP inside project
# run: moon ci ${{ matrix.projects }}:ci-copy-packages
- name: Build docker test image
run: moon ci ${{ matrix.projects }}:ci-test-build-docker-image
- name: Push docker test image
run: |
docker push ${{ env.TEST_IMAGE_NAME }}:${{ github.sha }}
docker push ${{ env.TEST_IMAGE_NAME }}:latest
install-vendors:
name: '${{ matrix.projects }} | Install vendors'
runs-on: ubuntu-latest
needs:
- define-matrix
- build-and-push-test-image
strategy:
fail-fast: false
matrix:
projects: ${{ fromJSON(needs.define-matrix.outputs.projects) }}
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set IMAGE_NAME for this project
run: echo "TEST_IMAGE_NAME=${{ needs.build-and-push-test-image.outputs.matrix_test_image_name }}" >> $GITHUB_ENV
- name: Set project paths
id: project-paths
run: |
# Get project path from moon
PROJECT_PATH=$(moon project ${{ matrix.projects }} --json | jq -r '.source')
# Set cache paths for all dependency folders
echo "cache_paths<<EOF" >> $GITHUB_OUTPUT
echo "$PROJECT_PATH/vendor" >> $GITHUB_OUTPUT
echo "$PROJECT_PATH/tools/vendor" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "project_path=$PROJECT_PATH" >> $GITHUB_OUTPUT
- name: Install vendors
run: moon ci ${{ matrix.projects }}:ci-install-vendors
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.project-paths.outputs.cache_paths }}
key: ${{ runner.os }}-${{ matrix.projects }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.projects }}-
- name: Upload vendor directories
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.projects }}-vendors
path: |
${{ steps.project-paths.outputs.project_path }}/vendor
${{ steps.project-paths.outputs.project_path }}/tools/vendor
lint-php:
name: '${{ matrix.projects }} | Lint PHP files'
needs:
- define-matrix
- build-and-push-test-image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{ fromJSON(needs.define-matrix.outputs.projects) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
- name: Set IMAGE_NAME for this project
run: echo "TEST_IMAGE_NAME=${{ needs.build-and-push-test-image.outputs.matrix_test_image_name }}" >> $GITHUB_ENV
- name: Install tools
run: moon ci ${{ matrix.projects }}:ci-install-tools
- name: Lint src folder
run: moon ci ${{ matrix.projects }}:ci-php-cs-fixer-src
- name: Lint test folder
run: moon ci ${{ matrix.projects }}:ci-php-cs-fixer-test
check-vulnerabilities:
name: '${{ matrix.projects }} | Check packages vulnerabilities'
needs:
- define-matrix
- build-and-push-test-image
- install-vendors
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{ fromJSON(needs.define-matrix.outputs.projects) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
- name: Set IMAGE_NAME for this project
run: echo "TEST_IMAGE_NAME=${{ needs.build-and-push-test-image.outputs.matrix_test_image_name }}" >> $GITHUB_ENV
- name: Check vulnerabilities
run: moon ci ${{ matrix.projects }}:ci-check-vulnerabilities
validate-db-schema:
name: '${{ matrix.projects }} | Validate DB schema'
needs:
- define-matrix
- build-and-push-test-image
- install-vendors
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{ fromJSON(needs.define-matrix.outputs.projects) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
- name: Get project path
id: project-paths
run: |
PROJECT_PATH=$(moon project ${{ matrix.projects }} --json | jq -r '.source')
echo "project_path=$PROJECT_PATH" >> $GITHUB_OUTPUT
- name: Download vendor directories
uses: actions/download-artifact@v4
with:
name: ${{ matrix.projects }}-vendors
path: ${{ steps.project-paths.outputs.project_path }}
- name: Set IMAGE_NAME for this project
run: echo "TEST_IMAGE_NAME=${{ needs.build-and-push-test-image.outputs.matrix_test_image_name }}" >> $GITHUB_ENV
- name: Validate DB
run: moon ci ${{ matrix.projects }}:ci-validate-db-schema
phpunit:
name: '${{ matrix.projects }} | PHPUnit'
needs:
- define-matrix
- build-and-push-test-image
- install-vendors
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
projects: ${{ fromJSON(needs.define-matrix.outputs.projects) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set IMAGE_NAME for this project
run: echo "TEST_IMAGE_NAME=${{ needs.build-and-push-test-image.outputs.matrix_test_image_name }}" >> $GITHUB_ENV
- name: Set up Moon Toolchain
uses: 'moonrepo/setup-toolchain@v0'
- name: Get project path
id: project-paths
run: |
PROJECT_PATH=$(moon project ${{ matrix.projects }} --json | jq -r '.source')
echo "project_path=$PROJECT_PATH" >> $GITHUB_OUTPUT
- name: Download vendor directories
uses: actions/download-artifact@v4
with:
name: ${{ matrix.projects }}-vendors
path: ${{ steps.project-paths.outputs.project_path }}
- name: Check folder
run: ls -als projects/tera/api
- name: Security tests
run: moon ${{ matrix.projects }}:ci-test-phpunit -- tests/Security
- name: Functional tests
run: moon ${{ matrix.projects }}:ci-test-phpunit -- tests/Functional