-
Notifications
You must be signed in to change notification settings - Fork 7
186 lines (160 loc) · 6.21 KB
/
main.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
name: CI
on:
pull_request:
push:
branches:
- master # triggers on pushes that contain changes in master
- develop
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout@v2
with:
path: 'kiwi'
- name: Set PHP version
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Move public for build
if: github.ref == 'refs/heads/master'
run: |
egrep -lRZ 'public/' kiwi | xargs -0 -l sed -i -e 's/public\//..\/public_html\/kiwi\//g'
sed -i -e 's/\/vendor\/autoload_runtime.php/\/..\/kiwi\/vendor\/autoload_runtime.php/g' kiwi/public/index.php
sed -i -e 's/\"extra\": {/\"extra\": {\n \"public-dir\": \"..\/public_html\/kiwi\",/g' kiwi/composer.json
mkdir public_html
mv kiwi/public public_html/kiwi
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-dev --optimize-autoloader
working-directory: kiwi
env:
APP_DEBUG: 0
APP_ENV: prod
- name: Install JS dependencies
run: yarn install
working-directory: kiwi
- name: Build JS dependencies
run: yarn build
working-directory: kiwi
- name: Extract platform requirements composer.lock
if: github.ref == 'refs/heads/master'
run: "composer check-platform-reqs --working-dir ./kiwi --lock --no-dev --no-ansi 2>&1 | sed '1,1d' | tr '\n' ',' | sed 's/.$//' | jq -R 'split(\",\") | map(. | gsub(\" +\"; \" \") | split(\" \") | { key: .[0], value: .[1] }) | from_entries' > requirements.json"
- name: Upload requirements file
uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/master'
with:
name: requirements
path: requirements.json
- name: Cleanup build
if: github.ref == 'refs/heads/master'
run: |
rm kiwi/{,.[!.],..?}* 2> /dev/null || true
rm -rf kiwi/.git
rm -rf kiwi/.github
rm -rf kiwi/.hooks
rm -rf kiwi/assets
rm -rf kiwi/bin
rm -rf kiwi/node_modules
rm -rf kiwi/tests
rm -rf kiwi/var
- name: Generate sample environment settings for build
if: github.ref == 'refs/heads/master'
run: |
cat > kiwi/.env.local.php.sample << EOL
<?php
return array (
'APP_DEBUG' => '0',
'APP_ENV' => 'prod',
'APP_SECRET' => '6fake_app_secrit_dont_look4',
'USERPROVIDER_KEY' => 'ThisIsNotSoSecret',
'DATABASE_URL' => 'mysql://db_user:db_pass@127.0.0.1:3306/db',
'MAILER_URL' => 'null://null',
'DEFAULT_FROM' => 'foo@bar.com',
);
EOL
- name: Compress build
if: github.ref == 'refs/heads/master'
run: zip -qq -r prod.zip kiwi public_html
- name: Upload build
uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/master'
with:
name: prod
path: prod.zip
release:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Get current date
uses: actions/github-script@0.3.0
id: author-date
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const commit_details = await github.git.getCommit({owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha});
const d = new Date(commit_details.data.author.date)
function pad(s) { return (s < 10) ? '0' + s : s; }
return [d.getFullYear(), pad(d.getMonth()+1), pad(d.getDate())].join('-')
- id: formatted-date
run: |
date="${DATE//\"/}"
echo "::set-output name=result::$date"
env:
DATE: ${{ steps.author-date.outputs.result }}
- name: Download build
uses: actions/download-artifact@v4
with:
name: prod
path: .
- name: Download requirements
uses: actions/download-artifact@v4
with:
name: requirements
path: .
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DATE: ${{ steps.formatted-date.outputs.result }}
with:
tag_name: ${{ env.DATE }}
release_name: Release ${{ env.DATE }}
draft: true
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: prod.zip
asset_name: kiwi.zip
asset_content_type: application/zip
- name: Upload Requirements Asset
id: upload-requirements-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: requirements.json
asset_name: requirements.json
asset_content_type: application/json
- name: Publish Release
id: publish_release
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.KIWIRELEASETOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}