-
Notifications
You must be signed in to change notification settings - Fork 18
231 lines (196 loc) · 8.15 KB
/
test-deploy.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Test and deploy
on:
push:
pull_request:
types: [opened, reopened, synchronize]
env:
IMAGE_CACHE_DIR: '/tmp/cache/docker-image'
jobs:
build:
name: Build release
runs-on: ubuntu-latest
strategy:
fail-fast: true
outputs:
latest-release: ${{ steps.latest-release.outputs.release }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Get latest release tag
id: latest-release
uses: rez0n/actions-github-release@main
env:
token: ${{ github.token }}
repository: "iisgiua/giuaschool"
type: "stable"
- name: Create cache registry
uses: actions/cache@v4
with:
path: ${{ env.IMAGE_CACHE_DIR }}
key: ${{ runner.os }}-docker-images-${{ github.sha }}
- name: Set up docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build docker image and cache it
run: |
docker build -t gs:test -f tests/docker/Dockerfile .
mkdir -p ${{ env.IMAGE_CACHE_DIR }}
docker save --output ${{ env.IMAGE_CACHE_DIR }}/gs-image.tar gs:test
- name: Create archive for update code
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: |
docker build -t gs:prod --target application_prod -f tests/docker/Dockerfile .
docker run --name gs_update gs:prod tests/docker/update.sh '${{ steps.latest-release.outputs.release }}'
docker cp gs_update:/var/www/giuaschool-update.zip giuaschool-update-${{ steps.latest-release.outputs.release }}.zip
- name: Upload update code
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: update-${{ steps.latest-release.outputs.release }}
name: "Aggiornamento della versione ${{ steps.latest-release.outputs.release }}"
body: "- [Visualizza le modifiche successive al rilascio della versione ${{ steps.latest-release.outputs.release }}](https://iisgiua.github.io/giuaschool-docs/latest-build.html)"
draft: false
prerelease: true
artifacts: giuaschool-update-${{ steps.latest-release.outputs.release }}.zip
allowUpdates: true
artifactErrorsFailBuild: true
replacesArtifacts: true
test-phpunit:
name: PhpUnit tests
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Create cache registry
uses: actions/cache@v4
with:
path: ${{ env.IMAGE_CACHE_DIR }}
key: ${{ runner.os }}-docker-images-${{ github.sha }}
- name: Docker load
run: |
docker load --input ${{ env.IMAGE_CACHE_DIR }}/gs-image.tar
- name: Run phpunit tests
run: |
docker run --name gs_test --add-host=giuaschool_test:127.0.0.1 --add-host=chrome_headless:127.0.0.1 gs:test tests/docker/test-phpunit.sh
docker cp gs_test:/var/www/giuaschool/clover.xml clover.xml
- name: Codacy coverage report
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: codacy/codacy-coverage-reporter-action@master
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: clover.xml
feature-matrix:
name: Create feature matrix
runs-on: ubuntu-latest
strategy:
fail-fast: true
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set matrix of features
id: set-matrix
run: echo "matrix=$(ls tests/features/*.feature | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
test-behat:
name: Behat tests
needs: [build, feature-matrix]
runs-on: ubuntu-latest
strategy:
matrix:
feature: ${{ fromJson(needs.feature-matrix.outputs.matrix) }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Create cache registry
uses: actions/cache@v4
with:
path: ${{ env.IMAGE_CACHE_DIR }}
key: ${{ runner.os }}-docker-images-${{ github.sha }}
- name: Set swap space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 5
- name: Docker load
run: |
docker load --input ${{ env.IMAGE_CACHE_DIR }}/gs-image.tar
- name: Run behat tests
run: |
docker run --add-host=giuaschool_test:127.0.0.1 --add-host=chrome_headless:127.0.0.1 gs:test tests/docker/test-behat.sh ${{ matrix.feature }}
test-update:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
needs: build
name: Test update procedure
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Test update procedure
run: |
TAG="${{ needs.build.outputs.latest-release }}"
docker build --build-arg VERSION=${TAG:1} --build-arg NEWVERSION="${TAG:1}" --build-arg NEWBUILD="build" -t gs:test -f tests/docker/TestUpdateDockerfile .
docker run --add-host=giuaschool_test:127.0.0.1 --add-host=chrome_headless:127.0.0.1 gs:test
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
needs: [test-phpunit, test-behat, test-update]
name: Deploy release
runs-on: ubuntu-latest
strategy:
fail-fast: true
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Generate changelog from latest release
id: changelog
uses: metcalfc/changelog-generator@v4.3.1
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Generate changelog page
run: |
mkdir docs
echo "tag: ${{ github.sha }}" > docs/build.yml
echo "---" > docs/latest-build.md
echo "layout: default" >> docs/latest-build.md
echo "title: Ultimo aggiornamento" >> docs/latest-build.md
echo "nav_order: 11" >> docs/latest-build.md
echo "---" >> docs/latest-build.md
echo "" >> docs/latest-build.md
echo "# Ultimo aggiornamento" >> docs/latest-build.md
echo "{: .text-center .fw-400 .pb-5}" >> docs/latest-build.md
echo "" >> docs/latest-build.md
echo "_Le modifiche seguenti non sono ancora validate né definitive:<br>se ne sconsiglia l'installazione se non in ambiente di test_" >> docs/latest-build.md
echo "{: .text-center .pb-5}" >> docs/latest-build.md
echo "" >> docs/latest-build.md
echo "Data e ora dell'ultimo aggiornamento: `TZ='Europe/Rome' date +'%d/%m/%Y %H:%M'`" >> docs/latest-build.md
echo "" >> docs/latest-build.md
echo "Lista delle modifiche effettuate dopo il rilascio della Versione {{ site.data.version.tag }}:" >> docs/latest-build.md
echo "" >> docs/latest-build.md
echo "${{ steps.changelog.outputs.changelog }}" >> docs/latest-build.md
- name: Add changelog page to documentation
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source_file: 'docs/latest-build.md'
destination_repo: 'iisgiua/giuaschool-docs'
destination_branch: 'master'
user_name: ${{ github.actor }}
user_email: '${{ github.actor }}@users.noreply.github.com'
commit_message: 'Add changelog page to documentation'
- name: Add build tag to documentation
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source_file: 'docs/build.yml'
destination_repo: 'iisgiua/giuaschool-docs'
destination_branch: 'master'
destination_folder: '_data'
user_name: ${{ github.actor }}
user_email: '${{ github.actor }}@users.noreply.github.com'
commit_message: 'Add build tag to documentation'