-
Notifications
You must be signed in to change notification settings - Fork 3
143 lines (138 loc) · 6.06 KB
/
github-actions.yml
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# https://github.com/shivammathur/setup-php
name: Tests
on: [push]
permissions:
contents: read
jobs:
build-docker-image:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/preprod' || github.ref == 'refs/heads/prod' || github.ref == 'refs/heads/feat/v2'
runs-on: ubuntu-latest
needs: tests
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REGISTRY: docker.pkg.github.com
DOCKER_REPOSITORY: docker.io
DOCKER_IMAGE_PHP: hozanaci/openchurch-backend
DOCKER_IMAGE_PYTHON: hozanaci/openchurch-sync
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Debug branch info
run: |
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Git ref: ${{ github.ref }}"
- name: Create version.json file
run: |
echo "{ \"version\": \"$(git rev-parse --short HEAD)\", \"build\": \"$(date)\", \"branch\": \"$(git rev-parse --abbrev-ref HEAD)\", \"tag\": \"$(git name-rev --tags --name-only $(git rev-parse HEAD))\" } " > public/version.json
- name: Build and push the image to DockerHub
run: |
echo "$DOCKER_PASSWORD" | docker login $DOCKER_REPOSITORY -u $DOCKER_USERNAME --password-stdin
docker build -t $DOCKER_IMAGE_PHP:$(git rev-parse --short HEAD) -f docker/php/Dockerfile .
docker push $DOCKER_IMAGE_PHP:$(git rev-parse --short HEAD)
docker build -t $DOCKER_IMAGE_PYTHON:$(git rev-parse --short HEAD) -f docker/python/Dockerfile .
docker push $DOCKER_IMAGE_PYTHON:$(git rev-parse --short HEAD)
publish-docker-image:
runs-on: ubuntu-latest
needs: build-docker-image
if: github.ref == 'refs/heads/preprod' || github.ref == 'refs/heads/prod' || github.ref == 'refs/heads/feat/v2'
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_REGISTRY: docker.pkg.github.com
DOCKER_REPOSITORY: docker.io
DOCKER_IMAGE_PHP: hozanaci/openchurch-backend
DOCKER_IMAGE_PYTHON: hozanaci/openchurch-sync
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Publish latest tag for docker image to DockerHub
run: |
echo "$DOCKER_PASSWORD" | docker login $DOCKER_REPOSITORY -u $DOCKER_USERNAME --password-stdin
docker pull $DOCKER_IMAGE_PHP:$(git rev-parse --short HEAD)
docker tag $DOCKER_IMAGE_PHP:$(git rev-parse --short HEAD) $DOCKER_IMAGE_PHP:$(git rev-parse --abbrev-ref HEAD)
docker push $DOCKER_IMAGE_PHP:$(git rev-parse --abbrev-ref HEAD)
docker tag $DOCKER_IMAGE_PYTHON:$(git rev-parse --short HEAD) $DOCKER_IMAGE_PYTHON:$(git rev-parse --abbrev-ref HEAD)
docker push $DOCKER_IMAGE_PYTHON:$(git rev-parse --abbrev-ref HEAD)
tests:
env:
HOST_API: api.openchurch.local/api
runs-on: ubuntu-latest
# Docs: https://docs.github.com/en/actions/using-containerized-services
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: symfony
MYSQL_DATABASE: openchurch_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 --name=mysql
elasticsearch:
image: elasticsearch:8.16.0
ports:
- 9200:9200
env:
ELASTIC_PASSWORD: admin
discovery.type: single-node
xpack.security.enabled: true
bootstrap.memory_lock: true
ES_JAVA_OPTS: -Xms512m -Xmx512m
options: --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
tools: phpunit-bridge
extensions: mbstring, xml, ctype, intl, iconv, json, mysql
ini-values: date.timezone=Europe/Paris
- uses: actions/checkout@v4
- name: Create .env.test.local
run: echo -e "DB_NAME_SUFFIX=\\nELASTICSEARCH_IRI=http://elastic:[email protected]:${{ job.services.elasticsearch.ports['9200'] }}" > .env.test.local
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run migrations
run: |
php bin/console doctrine:migrations:migrate --no-interaction || echo "No migrations found or migration failed"
env:
DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/openchurch_test
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
env:
DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/openchurch_test
- name: phpstan
if: always()
run: composer phpstan
- name: composer validate
if: always()
run: composer validate --strict
- name: lint:container
if: always()
run: php bin/console lint:container
- name: lint:yaml
if: always()
run: php bin/console lint:yaml config src
- name: doctrine:schema:validate
if: always()
run: php bin/console doctrine:schema:validate -vvv
env:
DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/openchurch_test
- name: Archive logs as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: logs
path: |
var/log/test.log
.env.test.local