Merge pull request #276 from REChain-Network-Solutions/dependabot/npm… #542
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI — lint, test, build, container | ||
|
Check failure on line 1 in .github/workflows/ci-custom.yml
|
||
| on: | ||
| push: | ||
| branches: [ main, develop ] | ||
| pull_request: | ||
| branches: [ main, develop ] | ||
| env: | ||
| PHP_VERSION: '8.1' | ||
| jobs: | ||
| prepare: | ||
| name: Prepare environment | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| has_frontend: ${{ steps.check_frontend.outputs.has_frontend }} | ||
| has_backend: ${{ steps.check_backend.outputs.has_backend }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - id: check_frontend | ||
| run: | | ||
| if [ -f package.json ] && [ -d app ]; then echo "::set-output name=has_frontend::true"; else echo "::set-output name=has_frontend::false"; fi | ||
| - id: check_backend | ||
| run: | | ||
| if [ -f composer.json ]; then echo "::set-output name=has_backend::true"; else echo "::set-output name=has_backend::false"; fi | ||
| lint_and_test: | ||
| name: Lint & Test (conditional) | ||
| needs: prepare | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| # Frontend JS/TS lint & tests | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '18' | ||
| - name: Frontend install & lint & test (if present) | ||
| if: needs.prepare.outputs.has_frontend == 'true' | ||
| working-directory: ./app | ||
| run: | | ||
| npm ci | ||
| npm run lint --if-present | ||
| npm test --if-present | ||
| # Backend PHP / Laravel | ||
| - name: Set up PHP and Composer | ||
| if: needs.prepare.outputs.has_backend == 'true' | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ env.PHP_VERSION }} | ||
| extensions: mbstring, pdo, pgsql | ||
| tools: composer:v2 | ||
| - name: Install backend deps (composer) | ||
| if: needs.prepare.outputs.has_backend == 'true' | ||
| run: | | ||
| composer install --no-interaction --prefer-dist --optimize-autoloader | ||
| - name: Run PHP linters (Pint) if configured | ||
| if: needs.prepare.outputs.has_backend == 'true' && steps.check_backend.outputs.has_backend == 'true' | ||
| run: | | ||
| if [ -f pint.json ] || [ -f phpstan.neon ]; then vendor/bin/pint || true; fi | ||
| - name: Run PHP unit tests (phpunit) | ||
| if: needs.prepare.outputs.has_backend == 'true' | ||
| env: | ||
| DB_CONNECTION: sqlite | ||
| run: | | ||
| if [ -f phpunit.xml ]; then vendor/bin/phpunit --configuration phpunit.xml || true; fi | ||
| build_containers: | ||
| name: Build container images | ||
| runs-on: ubuntu-latest | ||
| needs: lint_and_test | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
| - name: Login to registry (if secrets set) | ||
| if: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
| password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
| - name: Build image (local tag) | ||
| run: | | ||
| IMAGE_TAG=rechain/aiplatform:ci-${{ github.sha }} | ||
| docker buildx build --platform linux/amd64 -t ${IMAGE_TAG} --load . | ||
| - name: Push image (optional) | ||
| if: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN | ||
| run: | | ||
| IMAGE_TAG=rechain/aiplatform:${{ github.sha }} | ||
| docker buildx build --platform linux/amd64 -t ${IMAGE_TAG} --push . | ||