Skip to content

Commit 451b9fe

Browse files
committed
Install modules on windows using cpm
Fix #3 Tests for windows
1 parent 6fd3df7 commit 451b9fe

File tree

3 files changed

+65
-27
lines changed

3 files changed

+65
-27
lines changed

.github/workflows/check.yml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
perl-version:
130130
- "5.30"
131131
- "5.28"
132-
- "5.26"
132+
# ...
133133

134134
container:
135135
image: perldocker/perl-tester:${{ matrix.perl-version }}
@@ -139,9 +139,14 @@ jobs:
139139
- name: uses install-with-cpm
140140
uses: ./
141141
with:
142-
install: "Simple::Accessor"
143142
global: true
144143
sudo: false
144+
install: |
145+
abbreviation
146+
ACH
147+
# checking that both modules are installed
148+
- run: perl -Mabbreviation -e1
149+
- run: perl -MACH -e1
145150

146151
### ------------------------------------------------
147152
### Use some custom args to install
@@ -162,24 +167,18 @@ jobs:
162167
args: "--with-recommends --with-suggests"
163168

164169
## ------------------------------------------------
165-
## testing with Perl from perl-tester
170+
## testing with windows
166171
## ------------------------------------------------
167-
perl:
168-
runs-on: ubuntu-latest
169-
name: "perl v${{ matrix.perl-version }}"
170-
171-
strategy:
172-
fail-fast: false
173-
matrix:
174-
perl-version:
175-
- "5.30"
176-
- "5.28"
177-
# ...
178-
179-
container:
180-
image: perldocker/perl-tester:${{ matrix.perl-version }}
172+
windows:
173+
runs-on: windows-latest
174+
name: "windows"
181175

182176
steps:
177+
- name: Set up Perl
178+
run: |
179+
choco install strawberryperl
180+
echo "##[add-path]C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin"
181+
183182
- name: perl -V
184183
run: perl -V
185184

@@ -188,7 +187,6 @@ jobs:
188187

189188
uses: ./
190189
with:
191-
sudo: false
192190
install: |
193191
abbreviation
194192
ACH

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,34 @@ Disable the `-g` flag.
199199
cpanfile: "your-cpanfile"
200200
args: "--with-recommends --with-suggests"
201201
```
202+
203+
### Using install-with-cpm on Windows / win32
204+
205+
Here is a sample job using cpm to install modules on windows.
206+
207+
```
208+
windows:
209+
runs-on: windows-latest
210+
name: "windows"
211+
212+
steps:
213+
- name: Set up Perl
214+
run: |
215+
choco install strawberryperl
216+
echo "##[add-path]C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin"
217+
218+
- name: perl -V
219+
run: perl -V
220+
221+
- uses: actions/checkout@v2
222+
- name: "install-with-cpm"
223+
224+
uses: perl-actions/[email protected]
225+
with:
226+
install: |
227+
abbreviation
228+
ACH
229+
# checking that both modules are installed
230+
- run: perl -Mabbreviation -e1
231+
- run: perl -MACH -e1
232+
```

index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const io = require("@actions/io");
66

77
const fs = require("fs");
88
const path = require("path");
9+
const os = require("os");
910

1011
var PERL;
1112

@@ -19,7 +20,8 @@ async function install_cpm_location() {
1920
},
2021
};
2122

22-
const p = core.getInput("path");
23+
var p = core.getInput("path");
24+
p.replace("\\", "\\\\");
2325
await exec.exec(PERL, ["-MConfig", "-e", `print "${p}"`], options);
2426

2527
return path.resolve(out);
@@ -37,13 +39,19 @@ async function install_cpm(install_to) {
3739

3840
console.log(`install_to ${install_to}`);
3941

40-
// need to run it as sudo
41-
await do_exec([
42-
PERL,
43-
"-MFile::Copy=cp",
44-
"-e",
45-
`cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`,
46-
]);
42+
const platform = os.platform();
43+
//console.log(`OS: :${platform}:`);
44+
45+
if (platform == "win32") {
46+
await io.cp(cpmScript, install_to);
47+
} else {
48+
await do_exec([
49+
PERL,
50+
"-MFile::Copy=cp",
51+
"-e",
52+
`cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`,
53+
]);
54+
}
4755
//await io.cp(cpmScript, install_to); /* need to run with sudo */
4856
//await ioUtil.chmod(install_to, '0755')
4957

@@ -72,7 +80,8 @@ function is_false(b) {
7280

7381
async function do_exec(cmd) {
7482
const sudo = is_true(core.getInput("sudo"));
75-
const bin = sudo ? "sudo" : cmd.shift();
83+
const platform = os.platform();
84+
const bin = sudo && platform != "win32" ? "sudo" : cmd.shift();
7685

7786
console.log(`do_exec: ${bin}`);
7887

0 commit comments

Comments
 (0)