Skip to content

Commit 6a1f922

Browse files
authored
Workflow Update
1 parent d2cb8f7 commit 6a1f922

File tree

1 file changed

+70
-12
lines changed

1 file changed

+70
-12
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ on:
1111
pull_request:
1212
branches: [ main ]
1313

14+
# Define explicit permissions to follow principle of least privilege
15+
permissions:
16+
contents: read # Allows read access to repository contents
17+
actions: read # Allows read access to GitHub Actions
18+
checks: write # Allows creating/updating checks on the workflow run
19+
pull-requests: write # Allows commenting on PRs for feedback
20+
packages: read # Allows reading packages
21+
1422
jobs:
1523
lint:
1624
name: Lint PHP and JavaScript
@@ -29,26 +37,42 @@ jobs:
2937
uses: actions/setup-node@v4
3038
with:
3139
node-version: '16'
32-
cache: 'npm'
40+
# Only use cache if package-lock.json exists
41+
cache: npm
42+
cache-dependency-path: '**/package-lock.json'
3343

3444
- name: Install PHP dependencies
35-
run: composer install --prefer-dist --no-progress
45+
run: |
46+
if [ -f composer.json ]; then
47+
composer install --prefer-dist --no-progress
48+
else
49+
echo "No composer.json found. Skipping composer install."
50+
fi
3651
3752
- name: Install JS dependencies
38-
run: npm ci
53+
run: |
54+
if [ -f package.json ]; then
55+
npm ci || npm install
56+
else
57+
echo "No package.json found. Skipping npm install."
58+
fi
3959
4060
- name: Lint PHP
4161
run: |
42-
if [ -f .phpcs.xml ] || [ -f phpcs.xml.dist ]; then
43-
composer run lint:php
62+
if [ -f composer.json ] && ([ -f .phpcs.xml ] || [ -f phpcs.xml.dist ]); then
63+
if grep -q "\"lint:php\"" composer.json; then
64+
composer run lint:php
65+
else
66+
echo "No lint:php script found in composer.json. Skipping."
67+
fi
4468
else
4569
echo "No PHP linting configuration found. Skipping."
4670
fi
4771
4872
- name: Lint JavaScript
4973
run: |
50-
if [ -f .eslintrc.js ] || [ -f .eslintrc.json ]; then
51-
npm run lint:js
74+
if [ -f package.json ] && ([ -f .eslintrc.js ] || [ -f .eslintrc.json ]); then
75+
npm run lint:js || echo "Lint script not found in package.json. Skipping."
5276
else
5377
echo "No JS linting configuration found. Skipping."
5478
fi
@@ -65,7 +89,9 @@ jobs:
6589
uses: actions/setup-node@v4
6690
with:
6791
node-version: '16'
68-
cache: 'npm'
92+
# Only use cache if package-lock.json exists
93+
cache: npm
94+
cache-dependency-path: '**/package-lock.json'
6995

7096
- name: Setup PHP
7197
uses: shivammathur/setup-php@v2
@@ -75,16 +101,48 @@ jobs:
75101

76102
- name: Install dependencies
77103
run: |
78-
composer install --no-dev --prefer-dist --no-progress
79-
npm ci
104+
if [ -f composer.json ]; then
105+
composer install --no-dev --prefer-dist --no-progress
106+
else
107+
echo "No composer.json found. Skipping composer install."
108+
fi
109+
110+
if [ -f package.json ]; then
111+
npm ci || npm install
112+
else
113+
echo "No package.json found. Skipping npm install."
114+
fi
80115
81116
- name: Build frontend assets
82-
run: npm run build
117+
run: |
118+
if [ -f package.json ]; then
119+
if grep -q "\"build\"" package.json; then
120+
npm run build
121+
else
122+
echo "No build script found in package.json. Skipping."
123+
fi
124+
else
125+
echo "No package.json found. Skipping build."
126+
fi
83127
84128
- name: Create plugin package
85129
run: |
86130
mkdir -p build/simple-wp-optimizer
87-
cp -r assets includes languages templates simple-wp-optimizer.php readme.txt LICENSE build/simple-wp-optimizer/
131+
132+
# Copy main plugin file
133+
cp simple-wp-optimizer.php build/simple-wp-optimizer/
134+
135+
# Copy directories if they exist
136+
[ -d assets ] && cp -r assets build/simple-wp-optimizer/ || echo "No assets directory found"
137+
[ -d includes ] && cp -r includes build/simple-wp-optimizer/ || echo "No includes directory found"
138+
[ -d languages ] && cp -r languages build/simple-wp-optimizer/ || echo "No languages directory found"
139+
[ -d templates ] && cp -r templates build/simple-wp-optimizer/ || echo "No templates directory found"
140+
141+
# Copy additional files if they exist
142+
[ -f readme.txt ] && cp readme.txt build/simple-wp-optimizer/ || echo "No readme.txt found"
143+
[ -f LICENSE ] && cp LICENSE build/simple-wp-optimizer/ || echo "No LICENSE file found"
144+
145+
# Create zip file
88146
cd build
89147
zip -r simple-wp-optimizer.zip simple-wp-optimizer
90148

0 commit comments

Comments
 (0)