Skip to content

Commit 39e8f2f

Browse files
committed
Install modules using cpanm
1 parent 0b8d2ef commit 39e8f2f

File tree

4 files changed

+493
-16
lines changed

4 files changed

+493
-16
lines changed

.github/workflows/check.yml

+148-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,158 @@ name: check
33
on: [push]
44

55
jobs:
6-
testing:
6+
cpanm:
77
runs-on: ubuntu-latest
8-
name: Testing GitHub action
8+
name: "install cpanm"
99
steps:
1010
- uses: actions/checkout@v2
1111
- name: uses install-with-cpanm
1212
uses: ./
1313
- name: which cpanm
1414
run: which cpanm
15+
16+
### ------------------------------------------------
17+
### Install a single module
18+
### ------------------------------------------------
19+
20+
one_module:
21+
runs-on: ubuntu-latest
22+
name: "cpanm and a module"
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: uses install-with-cpanm
26+
uses: ./
27+
with:
28+
install: "Simple::Accessor"
29+
- run: perl -MSimple::Accessor -e1
30+
31+
### ------------------------------------------------
32+
### Install multiple modules
33+
### ------------------------------------------------
34+
35+
multiple_modules:
36+
runs-on: ubuntu-latest
37+
name: "cpanm & modules"
38+
steps:
39+
- uses: actions/checkout@v2
40+
- name: uses install-with-cpanm
41+
uses: ./
42+
with:
43+
install: |
44+
Simple::Accessor
45+
abbreviation
46+
- run: perl -MSimple::Accessor -e1
47+
- run: perl -Mabbreviation -e1
48+
49+
### ------------------------------------------------
50+
### Install modules from a cpanfile
51+
### ------------------------------------------------
52+
53+
cpanfile_root:
54+
runs-on: ubuntu-latest
55+
name: "cpanfile as root"
56+
steps:
57+
- uses: actions/checkout@v2
58+
- name: "Create a cpanfile"
59+
run: |
60+
echo "requires 'Simple::Accessor';" > cpanfile.test
61+
- name: uses install-with-cpanm
62+
uses: ./
63+
with:
64+
cpanfile: "cpanfile.test"
65+
- run: perl -MSimple::Accessor -e1
66+
67+
cpanfile_nonroot:
68+
runs-on: ubuntu-latest
69+
name: "cpanfile nonroot local::lib"
70+
steps:
71+
- uses: actions/checkout@v2
72+
- name: "Create a cpanfile"
73+
run: |
74+
echo "requires 'Simple::Accessor';" > cpanfile.test
75+
- name: uses install-with-cpanm
76+
uses: ./
77+
with:
78+
path: "cpanm-local"
79+
cpanfile: "cpanfile.test"
80+
sudo: false
81+
args: "-L vendor"
82+
- run: sudo perl cpanm-local local::lib
83+
- run: perl -Mlocal::lib=--no-create,vendor -MSimple::Accessor -e1
84+
85+
### ------------------------------------------------
86+
### Install a module and enable tests
87+
### ------------------------------------------------
88+
89+
with_tests:
90+
runs-on: ubuntu-latest
91+
name: "install with tests"
92+
steps:
93+
- uses: actions/checkout@v2
94+
- name: uses install-with-cpanm
95+
uses: ./
96+
with:
97+
install: "Simple::Accessor"
98+
tests: true
99+
args: "-v"
100+
- run: perl -MSimple::Accessor -e1
101+
102+
### ------------------------------------------------
103+
### check perl-tester
104+
### ------------------------------------------------
105+
106+
perl_tester:
107+
runs-on: ubuntu-latest
108+
name: "perl v${{ matrix.perl-version }}"
109+
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
perl-version:
114+
- "5.30"
115+
- "5.28"
116+
# ...
117+
118+
container:
119+
image: perldocker/perl-tester:${{ matrix.perl-version }}
120+
121+
steps:
122+
- uses: actions/checkout@v2
123+
- name: uses install-with-cpanm
124+
uses: ./
125+
with:
126+
sudo: false
127+
install: |
128+
abbreviation
129+
ACH
130+
# checking that both modules are installed
131+
- run: perl -Mabbreviation -e1
132+
- run: perl -MACH -e1
133+
134+
## ------------------------------------------------
135+
## testing with windows
136+
## ------------------------------------------------
137+
windows:
138+
runs-on: windows-latest
139+
name: "windows"
140+
141+
steps:
142+
- name: Set up Perl
143+
run: |
144+
choco install strawberryperl
145+
echo "##[add-path]C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin"
146+
147+
- name: perl -V
148+
run: perl -V
149+
150+
- uses: actions/checkout@v2
151+
- name: "install-with-cpanm"
152+
153+
uses: ./
154+
with:
155+
install: |
156+
abbreviation
157+
ACH
158+
# checking that both modules are installed
159+
- run: perl -Mabbreviation -e1
160+
- run: perl -MACH -e1

README.md

+171-6
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,187 @@
22

33
# install-with-cpanm
44

5-
GitHub action to install Perl Modules App::cpanminus
5+
GitHub action to install Perl Modules [App::cpanminus](https://github.com/miyagawa/cpanminus)
66

7-
This action installs 'cpanminus' as root so you can then use it in your workflow.
7+
This action installs 'cpanminus' then use it if needed to install some Perl Modules.
8+
9+
```yaml
10+
- name: install cpanm and multiple modules
11+
uses: perl-actions/[email protected]
12+
with:
13+
install: |
14+
Simple::Accessor
15+
Test::Parallel
16+
17+
# or you can use a cpanfile
18+
# cpanfile: 'your-cpanfile'
19+
# default values you can customize
20+
# sudo: true
21+
# where to install cpanm
22+
# path: "$Config{installsitescript}/cpanm"
23+
# which perl binary to use
24+
# perl: 'perl'
25+
```
26+
27+
## Using install-with-cpanm in a GitHub workflow
28+
29+
Here is a sample integration using install-with-cpanm action
30+
to test your Perl Modules using multiple Perl versions via the
31+
perl-tester images.
32+
33+
```yaml
34+
# .github/workflows/linux.yml
35+
jobs:
36+
perl_tester:
37+
runs-on: ubuntu-latest
38+
name: "perl v${{ matrix.perl-version }}"
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
perl-version:
44+
- "5.30"
45+
- "5.28"
46+
- "5.26"
47+
# ...
48+
# - '5.8'
49+
50+
container:
51+
image: perldocker/perl-tester:${{ matrix.perl-version }}
52+
53+
steps:
54+
- uses: actions/checkout@v2
55+
- name: uses install-with-cpm
56+
uses: perl-actions/[email protected]
57+
with:
58+
cpanfile: "cpanfile"
59+
sudo: false
60+
- run: perl Makefile.PL
61+
- run: make test
62+
```
863
964
## Inputs
1065
11-
none
66+
### `install`
67+
68+
List of one or more modules, separated by a newline `\n` character.
69+
70+
### `cpanfile`
71+
72+
Install modules from a cpanfile.
73+
74+
### `tests`
75+
76+
Boolean variable used to disable unit tests during installation
77+
Possible values: true | false [default: false]
78+
79+
### `args`
80+
81+
Extra arguments to pass to the cpanm command line.
82+
83+
example:
84+
85+
```yaml
86+
args: "-L vendor"
87+
```
88+
89+
### `sudo`
90+
91+
Run commands as sudo: true | false [default: true]
92+
93+
### `perl`
94+
95+
Which perl path to use. Default to use `perl` from the current `PATH`.
96+
By setting PATH correctly you probably do not need to use it.
97+
98+
### `path`
99+
100+
Where to install `cpanm`. Default value is `$Config{installsitescript}/cpanm`.
101+
You can use any `$Config` variable in your string.
12102

13103
## Outputs
14104

15105
none
16106

17107
## Example usage
18108

109+
### Install cpanm and use it manually later
110+
111+
```yaml
112+
uses: perl-actions/[email protected]
113+
# you can then use it later
114+
run: sudo cpanm Module::To::Install
115+
```
116+
117+
but you should prefer let the action install your modules
118+
119+
### Install cpanm and a single module
120+
121+
```yaml
122+
- name: install cpanm and one module
123+
uses: perl-actions/[email protected]
124+
with:
125+
install: "Simple::Accessor"
126+
```
127+
128+
### Install cpanm and multiple modules
129+
130+
```yaml
131+
- name: install cpanm and one module
132+
uses: perl-actions/[email protected]
133+
with:
134+
install: |
135+
Simple::Accessor
136+
Test::Parallel
137+
```
138+
139+
### Install modules from a cpanfile
140+
141+
```yaml
142+
- name: install cpanm and files from cpanfile
143+
uses: perl-actions/[email protected]
144+
with:
145+
cpanfile: "your-cpanfile"
146+
```
147+
148+
### Install a module and enable tests
149+
150+
Install modules with tests.
151+
152+
```yaml
153+
- name: install cpm and files from cpanfile
154+
uses: perl-actions/[email protected]
155+
with:
156+
install: "Simple::Accessor"
157+
tests: true
19158
```
20-
uses: perl-actions/[email protected]
21-
run: |
22-
sudo cpanm Module::To::Install
159+
160+
### Using install-with-cpm on Windows / win32
161+
162+
Here is a sample job using cpanm to install modules on windows.
163+
164+
```yaml
165+
windows:
166+
runs-on: windows-latest
167+
name: "windows"
168+
169+
steps:
170+
- name: Set up Perl
171+
run: |
172+
choco install strawberryperl
173+
echo "##[add-path]C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin"
174+
175+
- name: perl -V
176+
run: perl -V
177+
178+
- uses: actions/checkout@v2
179+
- name: "install-with-cpanm"
180+
uses: perl-actions/[email protected]
181+
with:
182+
install: |
183+
abbreviation
184+
ACH
185+
# checking that both modules are installed
186+
- run: perl -Mabbreviation -e1
187+
- run: perl -MACH -e1
23188
```

action.yml

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,42 @@
1-
name: "install cpanm"
2-
description: "install App::cpanminus"
1+
name: "install with cpanm"
2+
description: "install Perl Modules with App::cpanminus"
33
branding:
44
icon: "arrow-right"
55
color: "blue"
6+
7+
inputs:
8+
install:
9+
description: "List of modules or distributions to install [seperated by newline]"
10+
required: false
11+
12+
cpanfile:
13+
description: "Use a cpanfile to install modules"
14+
required: false
15+
16+
tests:
17+
description: "Run or not the unit tests"
18+
required: false
19+
default: false
20+
21+
args:
22+
description: "Extra args used passed to install command"
23+
required: false
24+
25+
sudo:
26+
description: "Perform installations as root"
27+
required: false
28+
default: true
29+
30+
perl:
31+
description: "Path of perl to use default to current PATH"
32+
required: false
33+
default: "perl"
34+
35+
path:
36+
description: "Path where to install cpanm: the string can use $Config values"
37+
required: false
38+
default: "$Config{installsitescript}/cpanm"
39+
640
runs:
741
using: "node12"
842
main: "index.js"

0 commit comments

Comments
 (0)