-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
245 lines (206 loc) · 6.77 KB
/
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Deploy
on:
pull_request:
types: [opened, synchronize, reopened]
branches-ignore: ['l10n_main*']
release:
types: [created]
workflow_run:
workflows: ['Compress images']
types: [completed]
workflow_dispatch:
env:
php-version: '8.1'
node-version: 18
concurrency:
group: Deploy ${{ github.ref }}
cancel-in-progress: true
jobs:
#############
# Build
#############
build:
runs-on: ubuntu-latest
name: Build assets
outputs:
version: ${{ steps.version.outputs.version }}
release: ${{ steps.version.outputs.release }}
strategy:
fail-fast: false
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup PHP ${{ env.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.php-version }}
extensions: redis
coverage: none
- name: Check PHP Version
run: php -v
- name: Check Composer Version
run: composer -V
- name: Check PHP Extensions
run: php -m
# Composer
- name: Validate composer.json and composer.lock
run: composer validate
- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer files
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ env.php-version }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ env.php-version }}-${{ hashFiles('**/composer.lock') }}
${{ runner.os }}-composer-${{ env.php-version }}
${{ runner.os }}-composer-
- name: Install composer dependencies
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
# Yarn
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
- name: Get yarn cache directory path
id: yarn-cache
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Cache yarn files
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-yarn-
- name: Install yarn dependencies
run: yarn inst
- name: Lint files
run: yarn run lint:fix
- name: Check if there is any file update needed
id: check
run: |
status=$(git status --porcelain)
if [ -z "$status" ]; then
echo "Nothing to push, already up to date."
else
echo -e "Waiting modifications:\n$status"
echo "::error::Resources are not up to date. Please rebuild with: 'yarn run lint:all' and 'yarn run prod'."
exit -1
fi
- name: Get version
id: version
run: |
echo "version=$(git describe --abbrev=0 --tags | sed 's/^v//')" >> $GITHUB_OUTPUT
echo "release=$(git describe --abbrev=0 --tags --exact-match $GITHUB_SHA 2>/dev/null || git log --pretty="%h" -n1 $GITHUB_SHA)" >> $GITHUB_OUTPUT
- name: Prepare environment
run: |
{ \
echo "MIX_PROD_SOURCE_MAPS=true"; \
echo "MIX_SENTRY_RELEASE=${{ steps.version.outputs.release }}"; \
} | tee .env
- name: Build assets
run: yarn run production
- name: Store assets
uses: actions/upload-artifact@v3
with:
name: assets
path: |
public/mix-manifest.json
public/js
public/css
public/fonts
!public/**/*.map
- name: Store source maps
uses: actions/upload-artifact@v3
with:
name: sourcemaps
path: |
public/**/*.map
######################
# Deploy on fortrabbit
######################
deploy:
runs-on: ubuntu-latest
name: Deploy
needs: build
if: github.event_name != 'pull_request'
environment: fortrabbit
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Download assets
uses: actions/download-artifact@v3
with:
name: assets
path: public
- name: Configure Git
run: |
git config user.email $GIT_EMAIL
git config user.name $GIT_USERNAME
env:
GIT_EMAIL: ${{ secrets.GIT_EMAIL }}
GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
- name: Create release files
run: |
echo ${{ needs.build.outputs.version }} > config/.version
echo ${{ needs.build.outputs.release }} > config/.release
echo $GITHUB_SHA > config/.commit
- name: Update .htaccess
run: cp -f scripts/.htaccess_production public/.htaccess
- name: Commit everything
run: |
git add -A --force public config
git commit -m "Build $($CURRENT_DATE_TIME)"
env:
CURRENT_DATE_TIME: "date +%Y-%m-%d:%H-%M"
- name: Deploy
run: |
git remote add deploy $REPO_URL
git push deploy main:master --force
env:
# This avoids a failure when the client does not know the SSH Host already
GIT_SSH_COMMAND: "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
REPO_URL: ${{ secrets.REPO_URL }}
############################
# Create a release on sentry
############################
sentry:
runs-on: ubuntu-latest
name: Sentry release
needs: build
if: github.event_name != 'pull_request'
environment: sentry
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download assets
uses: actions/download-artifact@v3
with:
name: assets
path: public
- name: Download source maps
uses: actions/download-artifact@v3
with:
name: sourcemaps
path: public
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: ${{ secrets.SENTRY_ENVIRONMENT }}
sourcemaps: public/js/app.js public/js/app.js.map
version: ${{ needs.build.outputs.release }}
url_prefix: ~/js