-
Notifications
You must be signed in to change notification settings - Fork 506
163 lines (133 loc) · 4.01 KB
/
test-and-ship.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Test & Ship
on:
- push
- pull_request
env:
MYSQL_ROOT_PASSWORD: root
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
COMPOSER_PROCESS_TIMEOUT: 0
strategy:
matrix:
php_version:
- 7.3
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
tools: composer:2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Setup environment
run: |
set -e;
cp .env.testing .env ;
. .env ;
. docker/utils.sh ;
wait_for_mysql ;
cat > $HOME/.my.cnf <<EOF
[client]
host=${DB_HOST}
port=${DB_PORT}
database=mysql
user=root
password=${MYSQL_ROOT_PASSWORD}
EOF
mysql -e "SELECT version();" ;
mysql -e "SET GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'" ;
- name: Install dependencies
run: |
set -e ;
composer install --no-interaction --prefer-dist
- name: Check linting
run: |
set -e;
composer lint
- name: Prepare tests
run: |
set -e;
composer pre-test;
mysql -e 'SET @@GLOBAL.wait_timeout=1800';
- name: Run tests
run: |
set -e;
( cd httpdocs/; php -S localhost:8000 -t . index.php &)
composer test ;
services:
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: ushahidi
MYSQL_USER: ushahidi
MYSQL_PASSWORD: ushahidi
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
ports:
- 3306:3306
options: --health-cmd "mysqladmin ping -h localhost"
--health-interval 10s --health-timeout 5s
--health-retries 60
ship:
needs: [ test ]
if: github.event_name == 'push' # not on PRs
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ECR_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_ECR_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Login to AWS Container Registry
uses: docker/login-action@v1
with:
registry: 513259414768.dkr.ecr.eu-west-1.amazonaws.com
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: |
513259414768.dkr.ecr.eu-west-1.amazonaws.com/platform
ghcr.io/ushahidi/platform
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=sha
- name: Build and push to Amazon ECR
uses: docker/build-push-action@v2
with:
pull: true
push: ${{ github.event_name != 'pull_request' }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
build-args: |
GIT_COMMIT_ID=${{ github.sha }}
GIT_BUILD_REF=${{ github.head_ref }}
cache-from: type=gha
cache-to: type=gha,mode=max