-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (117 loc) · 5.49 KB
/
alpha.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
name: Testing Symfony with MySQL and deploy server
on:
push:
branches: [ "alpha" ]
pull_request:
branches: [ "alpha" ]
permissions:
contents: read
jobs:
validate:
name: Symfony (PHP ${{ matrix.php-versions }})
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: symfony
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
matrix:
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v4
# Docs: https://github.com/shivammathur/setup-php
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql
coverage: xdebug
# Local MySQL service in GitHub hosted environments is disabled by default.
# If you are using it instead of service containers, make sure you start it.
# - name: Start mysql service
# run: sudo systemctl start mysql.service
- name: Copy .env.dist
# run: php -r "file_exists('.env.local') || copy('.env.${{ github.ref_name }}', '.env.local');"
run: php -r "file_exists('.env.local') || copy('.env.dist', '.env.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@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
if: steps.composer-cache.outputs.cache-hit != 'true' # Skip if cache hit
run: composer install --no-progress --prefer-dist --optimize-autoloader
# run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run Migration
run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:schema:update --complete --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env:
DATABASE_URL: mysql://root:[email protected]:${{ job.services.mysql.ports['3306'] }}/symfony
# - name: Install PHPUnit
# run: simple-phpunit install
#
# - name: Run tests
# run: simple-phpunit --coverage-text
deploy:
name: Deploy image
runs-on: ubuntu-latest
needs: validate
steps:
- uses: actions/checkout@v4
- name: Login to registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_LOGIN }}
password: ${{ secrets.DOCKER_PASSWD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: registry.realt.community/symfony-php-api-realt:${{ github.ref_name }}
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/staging.key
chmod 600 ~/.ssh/staging.key
cat >>~/.ssh/config <<END
Host staging
HostName $SSH_HOST
User $SSH_USER
Port $SSH_PORT
IdentityFile ~/.ssh/staging.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_PORT: ${{ secrets.SSH_PORT }}
- name: Update alpha environment
run: |
ssh staging 'export DOCKER_BRANCH=${{ github.ref_name }}
cd /home/realt/docker/api/${DOCKER_BRANCH}-git
git pull origin ${{ github.ref_name }}
docker compose --file docker-compose.${{ github.ref_name }}.yml pull
docker login -u ${{ secrets.DOCKER_LOGIN }} -p ${{ secrets.DOCKER_PASSWD }} ${{ secrets.DOCKER_REGISTRY }}
docker compose --project-name ${{ github.ref_name }}_php-api --file docker-compose.${{ github.ref_name }}.yml up -d'
# Add migration !?