-
-
Notifications
You must be signed in to change notification settings - Fork 1
153 lines (131 loc) · 5.14 KB
/
continuous-integration.yml
File metadata and controls
153 lines (131 loc) · 5.14 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
# This workflow runs continuous integration checks on the Simple WP 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@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: composer:v2, phpcs
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16'
# Only use cache if package-lock.json exists
cache: npm
cache-dependency-path: '**/package-lock.json'
- name: Install PHP dependencies
run: |
if [ -f composer.json ]; then
composer install --prefer-dist --no-progress
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@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '16'
# Only use cache if package-lock.json exists
cache: npm
cache-dependency-path: '**/package-lock.json'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: composer:v2
- name: Install dependencies
run: |
if [ -f composer.json ]; then
composer install --no-dev --prefer-dist --no-progress
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/simple-wp-optimizer
# Copy main plugin file
cp simple-wp-optimizer.php build/simple-wp-optimizer/
# Copy directories if they exist
[ -d assets ] && cp -r assets build/simple-wp-optimizer/ || echo "No assets directory found"
[ -d includes ] && cp -r includes build/simple-wp-optimizer/ || echo "No includes directory found"
[ -d languages ] && cp -r languages build/simple-wp-optimizer/ || echo "No languages directory found"
[ -d templates ] && cp -r templates build/simple-wp-optimizer/ || echo "No templates directory found"
# Copy additional files if they exist
[ -f readme.txt ] && cp readme.txt build/simple-wp-optimizer/ || echo "No readme.txt found"
[ -f LICENSE ] && cp LICENSE build/simple-wp-optimizer/ || echo "No LICENSE file found"
# Create zip file
cd build
zip -r simple-wp-optimizer.zip simple-wp-optimizer
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: simple-wp-optimizer
path: build/simple-wp-optimizer.zip