-
Notifications
You must be signed in to change notification settings - Fork 2
93 lines (86 loc) · 3.22 KB
/
Copy pathci-custom.yml
File metadata and controls
93 lines (86 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: CI — lint, test, build, container
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 .