-
Notifications
You must be signed in to change notification settings - Fork 8
202 lines (167 loc) · 5.86 KB
/
api-contentauthor.yaml
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: "API - Content Author"
on:
push:
paths:
- "sourcecode/apis/contentauthor/**"
- ".github/workflows/api-contentauthor.yaml"
workflow_call:
inputs:
versionToRelease:
description: 'A version to release'
required: true
type: string
secrets:
AWS_DOCKER_REGISTRY_ACCESS_KEY_ID:
required: true
AWS_DOCKER_REGISTRY_SECRET_ACCESS_KEY:
required: true
defaults:
run:
working-directory: sourcecode/apis/contentauthor
env:
shouldPublishImage: ${{ inputs.versionToRelease && '1' || '0' }}
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
composer-validate:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Validate
run: composer validate
php-cs-fixer:
if: github.ref != 'refs/heads/master'
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.CERPUSBOT_SECRET }}
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Manage php-cs-fixer cache
uses: actions/cache@v3
with:
path: .php-cs-fixer.cache
key: ${{ runner.OS }}-${{ github.repository }}-phpcsfixer-${{ github.sha }}
restore-keys: ${{ runner.OS }}-${{ github.repository }}-phpcsfixer-
- name: Get Composer cache dir
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: composer-${{ hashFiles('**/composer.json') }}
- name: Install dependencies
run: composer install --working-dir=tools/php-cs-fixer --no-progress --prefer-dist
- name: Run php-cs-fixer
run: tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --show-progress=none
- name: Commit fixed code
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Run php-cs-fixer
phpstan:
if: ${{ always() }}
needs: [php-cs-fixer]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: oauth, sockets, zip
coverage: pcov
- name: Get Composer cache dir
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: composer-${{ hashFiles('**/composer.json') }}
- name: Install dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run PHPStan
run: vendor/bin/phpstan analyse --memory-limit=512M
test_and_release:
if: ${{ always() }}
needs: [php-cs-fixer]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build test image
uses: docker/build-push-action@v4
with:
tags: "contentauthor-test:latest"
outputs: "type=docker"
context: sourcecode/apis/contentauthor
target: test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run tests
run: |
docker run -v "$(pwd):/reports" contentauthor-test \
vendor/bin/phpunit --coverage-clover /reports/coverage.xml
- name: Upload coverage to Codecov
if: env.shouldPublishImage != '1'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: sourcecode/apis/contentauthor/coverage.xml
fail_ci_if_error: true
- name: Configure AWS Credentials
if: env.shouldPublishImage == '1'
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_DOCKER_REGISTRY_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_DOCKER_REGISTRY_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
role-duration-seconds: 3600
role-session-name: GithubCerpusPushImage
- name: Login to AWS docker registry
if: env.shouldPublishImage == '1'
shell: bash
run: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
- name: Build and push web container
if: env.shouldPublishImage == '1'
uses: docker/build-push-action@v4
with:
push: true
tags: public.ecr.aws/f0t8l9h1/api-contentauthor-app:${{ inputs.versionToRelease }}
context: sourcecode/apis/contentauthor
target: web
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push production container
if: env.shouldPublishImage == '1'
uses: docker/build-push-action@v4
with:
push: true
tags: public.ecr.aws/f0t8l9h1/api-contentauthor-phpfpm:${{ inputs.versionToRelease }}
context: sourcecode/apis/contentauthor
target: prod
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push startup container
if: env.shouldPublishImage == '1'
uses: docker/build-push-action@v4
with:
push: true
tags: public.ecr.aws/f0t8l9h1/api-contentauthor-deploy:${{ inputs.versionToRelease }}
context: sourcecode/apis/contentauthor
target: startup
cache-from: type=gha
cache-to: type=gha,mode=max