Skip to content

Commit 0d11c0c

Browse files
committed
Fix Add-Path to append and add Add-PathPriority for prepending
1 parent 727437b commit 0d11c0c

5 files changed

Lines changed: 352 additions & 5 deletions

File tree

‎.github/workflows/e2e.yml‎

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
name: Runner
2+
on: [push]
3+
jobs:
4+
e2e-tests:
5+
name: E2E Tests - ${{ matrix.os }}
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
os: [ubuntu-24.04, macos-14, windows-latest]
11+
steps:
12+
# Test 1: Phar type tools with exact versions
13+
- name: Setup PHP with phar tools
14+
uses: shivammathur/setup-php@develop
15+
with:
16+
php-version: '8.3'
17+
tools: >-
18+
phpstan:1.12.0,
19+
psalm:5.26.0,
20+
php-cs-fixer:3.64.0,
21+
phpcs:3.10.3,
22+
phpmd:2.15.0,
23+
parallel-lint:1.4.0,
24+
cs2pr:1.8.2
25+
26+
- name: Test PHPStan 1.12.0
27+
run: php -r "if(strpos(shell_exec('phpstan --version 2>&1'), '1.12.0')===false) exit(1);"
28+
29+
- name: Test Psalm 5.26.0
30+
run: php -r "if(strpos(shell_exec('psalm --version 2>&1'), '5.26.0')===false) exit(1);"
31+
32+
- name: Test PHP-CS-Fixer 3.64.0
33+
run: php -r "if(strpos(shell_exec('php-cs-fixer --version 2>&1'), '3.64.0')===false) exit(1);"
34+
35+
- name: Test PHPCS 3.10.3
36+
run: php -r "if(strpos(shell_exec('phpcs --version 2>&1'), '3.10.3')===false) exit(1);"
37+
38+
- name: Test PHPMD 2.15.0
39+
run: php -r "if(strpos(shell_exec('phpmd --version 2>&1'), '2.15.0')===false) exit(1);"
40+
41+
- name: Test Parallel-Lint 1.4.0
42+
run: php -r "if(strpos(shell_exec('parallel-lint --version 2>&1'), '1.4.0')===false) exit(1);"
43+
44+
- name: Test CS2PR 1.8.2
45+
run: php -r "if(strpos(shell_exec('cs2pr -V 2>&1'), '1.8.2')===false) exit(1);"
46+
47+
# Test 2: Composer type tools
48+
- name: Setup PHP with composer tools
49+
uses: shivammathur/setup-php@develop
50+
with:
51+
php-version: '8.3'
52+
tools: >-
53+
rector:1.2.0,
54+
behat:3.28.0,
55+
phinx:0.16.10
56+
57+
- name: Test Rector 1.2.0
58+
run: php -r "if(strpos(shell_exec('rector --version 2>&1'), '1.2.0')===false) exit(1);"
59+
60+
- name: Test Behat 3.28.0
61+
run: php -r "if(strpos(shell_exec('behat --version 2>&1'), '3.28.0')===false) exit(1);"
62+
63+
- name: Test Phinx 0.16.10
64+
run: php -r "if(strpos(shell_exec('phinx --version 2>&1'), '0.16.10')===false) exit(1);"
65+
66+
# Test 3: Custom-function tools
67+
- name: Setup PHP with custom-function tools
68+
uses: shivammathur/setup-php@develop
69+
with:
70+
php-version: '8.3'
71+
tools: >-
72+
composer:2.7.9,
73+
phpunit:11.3.0,
74+
deployer:7.4.1,
75+
phive:0.15.3
76+
77+
- name: Test Composer 2.7.9
78+
run: php -r "if(strpos(shell_exec('composer --version 2>&1'), '2.7.9')===false) exit(1);"
79+
80+
- name: Test PHPUnit 11.3.0
81+
run: php -r "if(strpos(shell_exec('phpunit --version 2>&1'), '11.3.0')===false) exit(1);"
82+
83+
- name: Test Deployer 7.4.1
84+
run: php -r "if(strpos(shell_exec('deployer --version 2>&1'), '7.4.1')===false) exit(1);"
85+
86+
- name: Test Phive 0.15.3
87+
run: php -r "if(strpos(shell_exec('phive --version 2>&1'), '0.15.3')===false) exit(1);"
88+
89+
# Test 4: WP-CLI (Unix only)
90+
- name: Setup PHP with WP-CLI
91+
if: runner.os != 'Windows'
92+
uses: shivammathur/setup-php@develop
93+
with:
94+
php-version: '8.3'
95+
tools: wp-cli:2.11.0
96+
97+
- name: Test WP-CLI 2.11.0
98+
if: runner.os != 'Windows'
99+
run: php -r "if(strpos(shell_exec('wp --version 2>&1'), '2.11.0')===false) exit(1);"
100+
101+
# Test 5: Latest version resolution
102+
- name: Setup PHP with latest tool versions
103+
uses: shivammathur/setup-php@develop
104+
with:
105+
php-version: '8.3'
106+
tools: >-
107+
composer,
108+
phpunit,
109+
phpstan,
110+
php-cs-fixer
111+
112+
- name: Test tools installed (latest)
113+
run: |
114+
composer --version
115+
phpunit --version
116+
phpstan --version
117+
php-cs-fixer --version
118+
119+
# Test 6: Semver resolution (major.minor)
120+
- name: Setup PHP with major.minor versions
121+
uses: shivammathur/setup-php@develop
122+
with:
123+
php-version: '8.3'
124+
tools: >-
125+
phpstan:1.12,
126+
phpunit:11.3,
127+
psalm:5.26
128+
129+
- name: Test PHPStan resolves 1.12.x
130+
run: php -r "if(strpos(shell_exec('phpstan --version 2>&1'), '1.12.')===false) exit(1);"
131+
132+
- name: Test PHPUnit resolves 11.3.x
133+
run: php -r "if(strpos(shell_exec('phpunit --version 2>&1'), '11.3.')===false) exit(1);"
134+
135+
- name: Test Psalm resolves 5.26.x
136+
run: php -r "if(strpos(shell_exec('psalm --version 2>&1'), '5.26.')===false) exit(1);"
137+
138+
# Test 7: Composer channels
139+
- name: Setup PHP with composer stable
140+
uses: shivammathur/setup-php@develop
141+
with:
142+
php-version: '8.3'
143+
tools: composer:stable
144+
145+
- name: Test Composer stable channel
146+
run: composer --version
147+
148+
- name: Setup PHP with composer 2
149+
uses: shivammathur/setup-php@develop
150+
with:
151+
php-version: '8.3'
152+
tools: composer:2
153+
154+
- name: Test Composer 2 channel
155+
run: php -r "if(strpos(shell_exec('composer --version 2>&1'), 'Composer version 2')===false) exit(1);"
156+
157+
# Test 8: Tool aliases
158+
- name: Setup PHP with tool aliases
159+
uses: shivammathur/setup-php@develop
160+
with:
161+
php-version: '8.3'
162+
tools: >-
163+
phpdoc:3.5.0,
164+
ecs:12.3.0
165+
166+
- name: Test phpDocumentor 3.5.0 (alias - phpdoc)
167+
run: php -r "if(strpos(shell_exec('phpdoc --version 2>&1'), '3.5.0')===false) exit(1);"
168+
169+
- name: Test Easy Coding Standard 12.3.0 (alias - ecs)
170+
run: php -r "if(strpos(shell_exec('ecs --version 2>&1'), '12.3.0')===false) exit(1);"
171+
172+
# Test 9: User/repo format for composer tools
173+
- name: Setup PHP with user/repo tools
174+
uses: shivammathur/setup-php@develop
175+
with:
176+
php-version: '8.3'
177+
tools: laravel/pint:1.18.0
178+
179+
- name: Test Pint 1.18.0 (user/repo format)
180+
run: php -r "if(strpos(shell_exec('pint --version 2>&1'), '1.18.0')===false) exit(1);"
181+
182+
# Test 10: Dev tools (Unix only)
183+
- name: Setup PHP with dev tools
184+
if: runner.os != 'Windows'
185+
uses: shivammathur/setup-php@develop
186+
with:
187+
php-version: '8.3'
188+
tools: php-config, phpize
189+
190+
- name: Test php-config
191+
if: runner.os != 'Windows'
192+
run: php-config --version
193+
194+
- name: Test phpize
195+
if: runner.os != 'Windows'
196+
run: phpize --version
197+
198+
# Test 11: PECL (Unix only)
199+
- name: Setup PHP with PECL
200+
if: runner.os != 'Windows'
201+
uses: shivammathur/setup-php@develop
202+
with:
203+
php-version: '8.3'
204+
tools: pecl
205+
206+
- name: Test PECL
207+
if: runner.os != 'Windows'
208+
run: pecl version
209+
210+
# Test 12: Partial version resolution (major and major.minor)
211+
- name: Setup PHP with partial version tools
212+
uses: shivammathur/setup-php@develop
213+
with:
214+
php-version: '8.3'
215+
tools: >-
216+
phpunit:10,
217+
phpstan:2.1,
218+
psalm:6,
219+
deployer:7.5,
220+
phpcs:3.13
221+
222+
- name: Test PHPUnit 10.5.x (major version)
223+
run: php -r "if(strpos(shell_exec('phpunit --version 2>&1'), '10.5.')===false) exit(1);"
224+
225+
- name: Test PHPStan 2.1.x (major.minor version)
226+
run: php -r "if(strpos(shell_exec('phpstan --version 2>&1'), '2.1.')===false) exit(1);"
227+
228+
- name: Test Psalm 6.x (major version)
229+
run: php -r "if(strpos(shell_exec('psalm --version 2>&1'), 'Psalm 6.')===false) exit(1);"
230+
231+
- name: Test Deployer 7.5.x (major.minor version)
232+
run: php -r "if(strpos(shell_exec('deployer --version 2>&1'), '7.5.')===false) exit(1);"
233+
234+
- name: Test PHPCS 3.13.x (major.minor version)
235+
run: php -r "if(strpos(shell_exec('phpcs --version 2>&1'), '3.13.')===false) exit(1);"
236+
237+
# Test 13: Castor (custom-function)
238+
- name: Setup PHP with Castor
239+
uses: shivammathur/setup-php@develop
240+
with:
241+
php-version: '8.3'
242+
tools: castor:0.18.0
243+
244+
- name: Test Castor 0.18.0
245+
run: php -r "if(strpos(shell_exec('castor --version 2>&1'), '0.18.0')===false) exit(1);"
246+
247+
# Test 14: Phing (custom-function)
248+
- name: Setup PHP with Phing
249+
uses: shivammathur/setup-php@develop
250+
with:
251+
php-version: '8.3'
252+
tools: phing:3.0.1
253+
254+
- name: Test Phing 3.0.1
255+
run: php -r "if(strpos(shell_exec('phing -v 2>&1'), '3.0.1')===false) exit(1);"
256+
257+
# Test 15: PHPCPD (custom-function using phpunit handler)
258+
- name: Setup PHP with PHPCPD
259+
uses: shivammathur/setup-php@develop
260+
with:
261+
php-version: '8.3'
262+
tools: phpcpd:6.0.3
263+
264+
- name: Test PHPCPD 6.0.3
265+
run: php -r "if(strpos(shell_exec('phpcpd --version 2>&1'), '6.0.3')===false) exit(1);"
266+
267+
# Test 16: fetch_latest tools
268+
- name: Setup PHP with fetch_latest tool
269+
uses: shivammathur/setup-php@develop
270+
with:
271+
php-version: '8.3'
272+
tools: php-cs-fixer:3.64
273+
274+
- name: Test PHP-CS-Fixer 3.64.x (fetch_latest)
275+
run: php -r "if(strpos(shell_exec('php-cs-fixer --version 2>&1'), '3.64.')===false) exit(1);"
276+
277+
# Test 17: Multiple tools in single input
278+
- name: Setup PHP with multiple tools
279+
uses: shivammathur/setup-php@develop
280+
with:
281+
php-version: '8.3'
282+
tools: composer:2.7.9, phpunit:11.3.0, phpstan:1.12.0, php-cs-fixer:3.64.0, psalm:5.26.0
283+
284+
- name: Verify all tools installed with exact versions
285+
run: |
286+
php -r "if(strpos(shell_exec('composer --version 2>&1'), '2.7.9')===false) exit(1);"
287+
php -r "if(strpos(shell_exec('phpunit --version 2>&1'), '11.3.0')===false) exit(1);"
288+
php -r "if(strpos(shell_exec('phpstan --version 2>&1'), '1.12.0')===false) exit(1);"
289+
php -r "if(strpos(shell_exec('php-cs-fixer --version 2>&1'), '3.64.0')===false) exit(1);"
290+
php -r "if(strpos(shell_exec('psalm --version 2>&1'), '5.26.0')===false) exit(1);"
291+
292+
# Test 18: Box tool (phar type)
293+
- name: Setup PHP with Box
294+
uses: shivammathur/setup-php@develop
295+
with:
296+
php-version: '8.3'
297+
tools: box:4.6.2
298+
299+
- name: Test Box 4.6.2
300+
run: php -r "if(strpos(shell_exec('box --version 2>&1'), '4.6.2')===false) exit(1);"
301+
302+
# Test 19: Infection tool (phar type)
303+
- name: Setup PHP with Infection
304+
uses: shivammathur/setup-php@develop
305+
with:
306+
php-version: '8.3'
307+
tools: infection:0.29.6
308+
309+
- name: Test Infection 0.29.6
310+
run: php -r "if(strpos(shell_exec('infection --version 2>&1'), '0.29.6')===false) exit(1);"

‎dist/index.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/scripts/unix.sh‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,27 @@ get_shell_profile() {
170170
add_path() {
171171
path_to_add=$1
172172
if [[ -n "$GITHUB_PATH" ]]; then
173-
existing=$(cat "$GITHUB_PATH" 2>/dev/null)
174-
printf '%s\n%s' "$path_to_add" "$existing" > "$GITHUB_PATH"
173+
echo "$path_to_add" >> "$GITHUB_PATH"
175174
else
176175
profile=$(get_shell_profile)
177176
([ -e "$profile" ] && grep -q ":$path_to_add\"" "$profile" 2>/dev/null) || echo "export PATH=\"\${PATH:+\${PATH}:}$path_to_add\"" | sudo tee -a "$profile" >/dev/null 2>&1
178177
fi
179178
[[ ":$PATH:" == *":$path_to_add:"* ]] || export PATH="${PATH:+${PATH}:}$path_to_add"
180179
}
181180

181+
# Function to prepend a path to the PATH variable with priority.
182+
add_path_priority() {
183+
path_to_add=$1
184+
if [[ -n "$GITHUB_PATH" ]]; then
185+
existing=$(cat "$GITHUB_PATH" 2>/dev/null)
186+
printf '%s\n%s' "$path_to_add" "$existing" > "$GITHUB_PATH"
187+
else
188+
profile=$(get_shell_profile)
189+
([ -e "$profile" ] && grep -q "\"$path_to_add:" "$profile" 2>/dev/null) || echo "export PATH=\"$path_to_add:\${PATH}\"" | sudo tee -a "$profile" >/dev/null 2>&1
190+
fi
191+
[[ ":$PATH:" == *":$path_to_add:"* ]] || export PATH="$path_to_add${PATH:+:${PATH}}"
192+
}
193+
182194
# Function to add environment variables using a PATH.
183195
add_env_path() {
184196
env_path=$1

‎src/scripts/win32.ps1‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ Function Add-Path {
8484
[string]$PathItem
8585
)
8686
if ($env:GITHUB_PATH) {
87-
$existingContent = Get-Content $env:GITHUB_PATH -Raw -ErrorAction SilentlyContinue
88-
Set-Content -Path $env:GITHUB_PATH -Value "$PathItem`n$existingContent" -NoNewline -Encoding utf8
87+
Add-Content -Path $env:GITHUB_PATH -Value $PathItem -Encoding utf8
8988
} else {
9089
$currentPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH -ErrorAction SilentlyContinue).Path
9190
if ($currentPath -notlike "*$PathItem;*" -and $currentPath -notlike "*$PathItem") {
@@ -97,6 +96,25 @@ Function Add-Path {
9796
}
9897
}
9998

99+
# Function to prepend a location to PATH with priority.
100+
Function Add-PathPriority {
101+
param(
102+
[string]$PathItem
103+
)
104+
if ($env:GITHUB_PATH) {
105+
$existingContent = Get-Content $env:GITHUB_PATH -Raw -ErrorAction SilentlyContinue
106+
Set-Content -Path $env:GITHUB_PATH -Value "$PathItem`n$existingContent" -NoNewline -Encoding utf8
107+
} else {
108+
$currentPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH -ErrorAction SilentlyContinue).Path
109+
if ($currentPath -notlike "*$PathItem;*" -and $currentPath -notlike "*$PathItem") {
110+
Set-ItemProperty -Path 'hkcu:\Environment' -Name Path -Value "$PathItem;$currentPath"
111+
}
112+
}
113+
if(-not "$env:PATH;".contains("$PathItem;")) {
114+
$env:PATH = "$PathItem;$env:PATH"
115+
}
116+
}
117+
100118
# Function to add an environment variable.
101119
Function Add-Env {
102120
param(

‎src/tools.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,5 +714,12 @@ export async function addTools(
714714
}
715715
});
716716

717+
// Re-add bin_dir to GITHUB_PATH with priority so phar tools take precedence over composer tool dependencies
718+
if (os === 'win32') {
719+
script += '\nAdd-PathPriority $bin_dir';
720+
} else {
721+
script += '\nadd_path_priority "$bin_dir"';
722+
}
723+
717724
return script;
718725
}

0 commit comments

Comments
 (0)