-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (158 loc) · 7.76 KB
/
build.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
name: Installer builder
on:
push:
branches:
- master
paths-ignore:
- '**/README.md'
- '**/LICENSE'
pull_request:
branches:
- '**'
paths-ignore:
- '**/README.md'
- '**/LICENSE'
workflow_dispatch:
schedule:
- cron: '0 3 * * 1' # Once a week at 03:00 on Monday
env:
REGISTRY: ghcr.io
IMAGE_NAME: phpsword/installer
LATEST_PHP_VERSION: '8.1'
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.1', '8.2', '8.3' ]
steps:
- uses: actions/checkout@v4
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, redis
tools: composer:v2, symfony
coverage: none
- name: Install project
run: |
rm LICENSE
rm README.md
git config --global user.email "no-reply@getsword.com"
git config --global user.name "Sword"
symfony new newproject --webapp
cd newproject
cp -Rp . ../
cd ..
rm -rf newproject
rm -f composer.lock docker-compose* compose.yaml compose.override.yaml
echo "APP_NAME=sword" >> .env
echo "PROJECT_DIR=${PWD##*/}" >> .env
echo "MAILER_DSN=smtp://mailer:25" >> .env
composer config --no-interaction minimum-stability dev
composer config --no-interaction prefer-stable true
composer config --no-interaction repositories.0 '{"type": "composer", "url": "https://wpackagist.org", "only": ["wpackagist-plugin/*", "wpackagist-theme/*"]}'
composer config --no-interaction allow-plugins.composer/installers true
composer config --no-interaction allow-plugins.composer/package-versions-deprecated true
composer config --no-interaction allow-plugins.johnpbloch/wordpress-core-installer true
composer config --no-interaction allow-plugins.ergebnis/composer-normalize true
composer config --no-interaction --json extra.installer-paths.wp/content/plugins/{\$name}/ '["type:wordpress-plugin"]'
composer config --no-interaction --json extra.installer-paths.wp/content/themes/{\$name}/ '["type:wordpress-theme"]'
composer config --no-interaction extra.symfony.allow-contrib true
composer config --no-interaction extra.wordpress-install-dir "wp/core"
composer require --no-interaction phpsword/sword-bundle johnpbloch/wordpress wpackagist-plugin/akismet wpackagist-theme/twentytwentyfour --prefer-stable
composer require --no-interaction --dev ergebnis/composer-normalize roave/security-advisories:dev-latest
composer normalize --no-interaction
rm bin/console
cp vendor/phpsword/sword-bundle/install/docker-compose.yml docker-compose.yml
cp vendor/phpsword/sword-bundle/install/docker-compose.prod.yml docker-compose.prod.yml
cp vendor/phpsword/sword-bundle/install/bin/console bin/console
sed -i "s/PHP_VERSION: 8.1-dev/PHP_VERSION: ${{ matrix.php }}-dev/" docker-compose.yml
sed -i "s/PHP_VERSION: 8.1/PHP_VERSION: ${{ matrix.php }}/" docker-compose.prod.yml
php_version=$(echo ${{ matrix.php }} | tr -d '.')
sed -i "s@/etc/php81/conf.d@/etc/php$php_version/conf.d@" docker-compose.yml
- name: "Check file existence"
uses: andstor/file-existence-action@v3
with:
files: "docker-compose.yml, docker/"
fail: true
- name: Build Docker image
run: docker build --no-cache -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php-${{ matrix.php }} -f ./build/Dockerfile .
- name: Save Docker image as artifact
run: docker save -o /tmp/installer-${{ matrix.php }}.tar ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php-${{ matrix.php }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: installer-${{ matrix.php }}
path: /tmp/installer-${{ matrix.php }}.tar
test:
name: Test
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.1', '8.2', '8.3' ]
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: installer-${{ matrix.php }}
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/installer-${{ matrix.php }}.tar
docker image ls -a
- name: Create a new project
run: |
docker run --rm -t -e HOST_PWD="$PWD" \
-v "$PWD":/app -v /var/run/docker.sock:/var/run/docker.sock \
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php-${{ matrix.php }} testproject -v
sleep 20
- name: Show containers logs
run: |
cd testproject
docker compose logs --tail 20 php
docker compose logs --tail 20 nginx
docker compose logs --tail 20 mysql
docker compose logs --tail 20 traefik
- name: Check that website is up and running
run: |
wget --no-check-certificate -O- https://testproject.localhost/
url=$(curl https://testproject.localhost -k -s -L -I -o /dev/null -w '%{url_effective}')
echo $url
[ "$url" = "https://testproject.localhost/wp-admin/install.php" ]
- name: Check PHP version
run: cd testproject && docker compose exec php php -v | grep "PHP ${{ matrix.php }}"
deploy:
name: Deploy
needs: [build, test]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
strategy:
matrix:
php: [ '8.1', '8.2', '8.3' ]
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: installer-${{ matrix.php }}
path: /tmp
- name: Load Docker image
run: |
docker load --input /tmp/installer-${{ matrix.php }}.tar
docker image ls -a
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker image
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php-${{ matrix.php }}
- name: Push latest Docker tag
if: ${{ matrix.php == env.LATEST_PHP_VERSION }}
run: |
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:php-${{ matrix.php }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest