-
-
Notifications
You must be signed in to change notification settings - Fork 0
187 lines (163 loc) · 6.78 KB
/
continuous-integration.yml
File metadata and controls
187 lines (163 loc) · 6.78 KB
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
# This workflow runs continuous integration checks on the EngineScript Site Optimizer plugin.
# It performs code linting for both PHP and JavaScript files and builds the plugin package.
# The workflow is triggered on push to main branch and on pull requests to ensure code quality.
# It creates and stores a plugin zip file as an artifact that can be used for testing.
name: Continuous Integration
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Define explicit permissions to follow principle of least privilege
permissions:
contents: read # Allows read access to repository contents
actions: read # Allows read access to GitHub Actions
checks: write # Allows creating/updating checks on the workflow run
pull-requests: write # Allows commenting on PRs for feedback
packages: read # Allows reading packages
jobs:
lint:
name: Lint PHP and JavaScript
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2, phpcs
- name: Check for package-lock.json
id: check-lockfile
run: |
if [ -f "package-lock.json" ]; then
echo "lockfile_exists=true" >> $GITHUB_OUTPUT
else
echo "lockfile_exists=false" >> $GITHUB_OUTPUT
echo "package-lock.json not found. Caching will be skipped."
fi
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '16'
# Use conditional caching based on package-lock.json existence
cache: ${{ steps.check-lockfile.outputs.lockfile_exists == 'true' && 'npm' || '' }}
cache-dependency-path: |
**/package-lock.json
!**/node_modules/
- name: Install PHP dependencies
run: |
if [ -f composer.json ]; then
# Configure platform to ensure compatibility
composer config platform.php 7.4
composer install --prefer-dist --no-progress || {
echo "Standard install failed, trying with --ignore-platform-reqs"
composer install --prefer-dist --no-progress --ignore-platform-reqs
}
else
echo "No composer.json found. Skipping composer install."
fi
- name: Install JS dependencies
run: |
if [ -f package.json ]; then
npm ci || npm install
else
echo "No package.json found. Skipping npm install."
fi
- name: Lint PHP
run: |
if [ -f composer.json ] && ([ -f .phpcs.xml ] || [ -f phpcs.xml.dist ]); then
if grep -q "\"lint:php\"" composer.json; then
composer run lint:php
else
echo "No lint:php script found in composer.json. Skipping."
fi
else
echo "No PHP linting configuration found. Skipping."
fi
- name: Lint JavaScript
run: |
if [ -f package.json ] && ([ -f .eslintrc.js ] || [ -f .eslintrc.json ]); then
npm run lint:js || echo "Lint script not found in package.json. Skipping."
else
echo "No JS linting configuration found. Skipping."
fi
build:
name: Build Plugin
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check for package-lock.json in build
id: check-lockfile-build
run: |
if [ -f "package-lock.json" ]; then
echo "lockfile_exists=true" >> $GITHUB_OUTPUT
else
echo "lockfile_exists=false" >> $GITHUB_OUTPUT
echo "package-lock.json not found. Caching will be skipped."
fi
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '16'
# Use conditional caching based on package-lock.json existence
cache: ${{ steps.check-lockfile-build.outputs.lockfile_exists == 'true' && 'npm' || '' }}
cache-dependency-path: |
**/package-lock.json
!**/node_modules/
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2
- name: Install dependencies
run: |
if [ -f composer.json ]; then
# Configure platform to ensure compatibility
composer config platform.php 7.4
composer install --no-dev --prefer-dist --no-progress || {
echo "Standard install failed, trying with --ignore-platform-reqs"
composer install --no-dev --prefer-dist --no-progress --ignore-platform-reqs
}
else
echo "No composer.json found. Skipping composer install."
fi
if [ -f package.json ]; then
npm ci || npm install
else
echo "No package.json found. Skipping npm install."
fi
- name: Build frontend assets
run: |
if [ -f package.json ]; then
if grep -q "\"build\"" package.json; then
npm run build
else
echo "No build script found in package.json. Skipping."
fi
else
echo "No package.json found. Skipping build."
fi
- name: Create plugin package
run: |
mkdir -p build/enginescript-site-optimizer
# Copy main plugin file
cp enginescript-site-optimizer.php build/enginescript-site-optimizer/
# Copy directories if they exist
[ -d assets ] && cp -r assets build/enginescript-site-optimizer/ || echo "No assets directory found"
[ -d includes ] && cp -r includes build/enginescript-site-optimizer/ || echo "No includes directory found"
[ -d languages ] && cp -r languages build/enginescript-site-optimizer/ || echo "No languages directory found"
[ -d templates ] && cp -r templates build/enginescript-site-optimizer/ || echo "No templates directory found"
# Copy additional files if they exist
[ -f readme.txt ] && cp readme.txt build/enginescript-site-optimizer/ || echo "No readme.txt found"
[ -f LICENSE ] && cp LICENSE build/enginescript-site-optimizer/ || echo "No LICENSE file found"
# Create zip file
cd build
zip -r enginescript-site-optimizer.zip enginescript-site-optimizer
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: enginescript-site-optimizer
path: build/enginescript-site-optimizer.zip