Skip to content

Commit 07a4a12

Browse files
gpibarraGerardo IbarraProjektGopher
authored
[ Feat ] Windows Support (#33)
* fix windows path hook * fix tests * github actions windows --------- Co-authored-by: Gerardo Ibarra <gibarra@upgradeit.com.ar> Co-authored-by: Len Woodward <Len@ProjektGopher.com>
1 parent 990b17a commit 07a4a12

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

.github/workflows/pint.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ on:
33
workflow_dispatch:
44
push:
55
branches-ignore:
6-
- 'dependabot/npm_and_yarn/*'
6+
- "dependabot/npm_and_yarn/*"
77
jobs:
88
phplint:
9-
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
operating-system:
12+
- ubuntu-latest
13+
php-version:
14+
- "8.2"
15+
name: php ${{ matrix.php-version }} on ${{ matrix.operating-system }}
16+
runs-on: ${{ matrix.operating-system }}
1017
steps:
1118
- name: Checkout
1219
uses: actions/checkout@v2

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
matrix:
88
operating-system:
99
- ubuntu-latest
10+
- windows-latest
1011
php-version:
1112
- "8.1"
1213
- "8.2"

app/Whisky.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ public function __construct()
1515
public static function cwd(string $path = ''): string
1616
{
1717
if ($path) {
18-
return getcwd().DIRECTORY_SEPARATOR.$path;
18+
return Whisky::normalizePath(getcwd().'/'.$path);
1919
}
2020

21-
return getcwd();
21+
return Whisky::normalizePath(getcwd());
2222
}
2323

2424
public static function bin(): string
2525
{
26-
return match (true) {
26+
return Whisky::normalizePath(match (true) {
2727
self::dogfooding() => self::cwd('whisky'),
2828
self::isRunningGlobally() => '/usr/local/bin/whisky', // TODO
2929
default => self::cwd('vendor/bin/whisky'),
30-
};
30+
});
3131
}
3232

3333
public static function dogfooding(): bool
@@ -43,9 +43,9 @@ public static function isRunningGlobally(): bool
4343

4444
public static function base_path(string $path = ''): string
4545
{
46-
return Phar::running()
46+
return Whisky::normalizePath(Phar::running()
4747
? Whisky::cwd("vendor/projektgopher/whisky/{$path}")
48-
: base_path($path);
48+
: base_path($path));
4949
}
5050

5151
public static function readConfig(string $key): string|array|null
@@ -56,4 +56,18 @@ public static function readConfig(string $key): string|array|null
5656

5757
return data_get($cfg, $key);
5858
}
59+
60+
public static function normalizePath($path): string
61+
{
62+
if (Whisky::isWindows()) {
63+
return str_replace('\\', '/', $path);
64+
}
65+
66+
return $path;
67+
}
68+
69+
public static function isWindows(): bool
70+
{
71+
return str_starts_with(strtoupper(PHP_OS), 'WIN');
72+
}
5973
}

tests/Feature/InstallTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
it('fails if git is not initialized', function () {
1212
File::shouldReceive('exists')
1313
->once()
14-
->with(base_path('.git'))
14+
->with(normalizePath(base_path('.git')))
1515
->andReturnFalse();
1616

1717
$this->artisan('install')

tests/Feature/RunTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
it('deletes skip-once file if exists and outputs nothing', function () {
66
File::shouldReceive('exists')
77
->once()
8-
->with(base_path('bin/skip-once'))
8+
->with(normalizePath(base_path('bin/skip-once')))
99
->andReturnTrue();
1010

1111
File::shouldReceive('delete')
1212
->once()
13-
->with(base_path('bin/skip-once'))
13+
->with(normalizePath(base_path('bin/skip-once')))
1414
->andReturnTrue();
1515

1616
$this->artisan('get-run-cmd pre-commit')

tests/Pest.php

+14
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,17 @@ function something(): void
4343
{
4444
// ..
4545
}
46+
47+
function normalizePath($path): string
48+
{
49+
if (isWindows()) {
50+
return str_replace('\\', '/', $path);
51+
}
52+
53+
return $path;
54+
}
55+
56+
function isWindows(): bool
57+
{
58+
return str_starts_with(strtoupper(PHP_OS), 'WIN');
59+
}

0 commit comments

Comments
 (0)