[英]Testing Perl on Windows with github actions
我已经发布了MooseX::Extended到 CPAN(这里是 github 存储库)。
我正在尝试设置 github 操作,并且 linux 测试运行良好。 但是,( Windows 因此错误而失败:
Configuring true-v1.0.2 ... OK
==> Found dependencies: Function::Parameters
--> Working on Function::Parameters
Fetching http://www.cpan.org/authors/id/M/MA/MAUKE/Function-Parameters-2.001003.tar.gz ... OK
Configuring Function-Parameters-2.001003 ... OK
Building Function-Parameters-2.001003 ... OK
Successfully installed Function-Parameters-2.001003
! Installing true failed. See C:\Users\RUNNER~1\.cpanm\work\1653412748.5640\build.log for details. Retry with --force to force install it.
Building true-v1.0.2 ... FAIL
当然,我看不到C:\Users\RUNNER~1\.cpanm\work\1653412748.5640\build.log
以了解发生了什么。
true
的模块在 Windows 上通过了它的 CPAN 测试人员测试,所以我不知道为什么它在 Github Actions 中失败了。
我的工作流程如下所示:
# Hacked from https://github.com/skaji/perl-github-actions-sample/blob/master/.github/workflows/windows.yml
# See also: https://perlmaven.com/github-actions-running-on-3-operating-systems
name: windows
on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:
jobs:
perl:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
perl-version:
- '5.20'
- '5.22'
- '5.24'
- '5.26'
- '5.28'
- '5.30'
- '5.32'
- '5.34'
- 'latest'
steps:
- uses: actions/checkout@v2
- name: Set up Perl
run: |
choco install strawberryperl
echo "C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin" >> $GITHUB_PATH
- name: perl -V
run: perl -V
- name: Install Dependencies
run: curl -sL https://git.io/cpm | perl - install -g --show-build-log-on-failure Dist::Zilla
- name: Run Tests
run: |
dzil authordeps --missing | cpanm --notest
dzil listdeps --author --missing | cpanm --notest
dzil test --author --release
我无权访问 Windows 框。 有谁知道我错过了什么?
由于 GitHub Actions/Workflows 使用的 Windows 容器已经预装了Strawberry Perl版本,因此它不允许您安装任何其他版本。 您无法删除预安装的 Perl 版本,并且通过 Chocolatey 删除/安装新版本也几乎是不可能的。 如果您从 Chocolatey 重新安装容器上已经存在的版本,它似乎允许这样做,但作为测试设置,这对您来说基本上是一个NOOP
。
该容器还安装了 MinGW; 这也可能对我们不利。 单独安装 MinGW 会阻止构建 XS 模块(无论它们是依赖项还是您自己的模块是 XS 模块)。 当然,只有在安装 Perl 之前 MinGW 出现在PATH
中时才会发生这种情况,但是当您删除一个 Perl 并添加另一个 Perl 时,您将遇到这个问题。
为了解决这个问题,最好的做法是从PATH
环境变量中删除当前安装的 Perl 版本,以及他们当前安装的 MinGW 版本。 一旦两者都安全地脱离 PATH,您可以安装 Portable[1] Strawberry Perl ,将该 Perl 的路径放入您的PATH
并开始使用全新安装的 Strawberry Perl 进行测试。 GitHub 最近打破了我们直接在 Action YAML 文件中执行此操作的能力。
这一切听起来让人头疼,但事实并非如此。 为此目的,我们可以使用一个 Action: actions-setup-perl 。 通过此操作,您可以轻松地使用您喜欢的任何版本的 Perl 进行测试。 因此,如果您听到有人报告 Windows 上 Perl v5.26 的错误,您现在可以将其添加到您的矩阵中并轻松测试,而无需用户来回进行任何来回操作:
name: windows
on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:
jobs:
perl:
runs-on: windows-latest
strategy:
fail-fast: true
matrix:
perl-version:
- '5.30'
# - '5.28'
# - '5.26'
# - '5.24'
# - '5.22'
# - '5.20'
# - '5.18'
# - '5.16'
- '5.14'
steps:
- name: Setup perl
uses: shogo82148/actions-setup-perl@v1
with:
perl-version: ${{ matrix.perl-version }}
distribution: strawberry
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v2
- name: perl -V
run: perl -V
- name: Ensure we have a working toolchain
run: cpanm ExtUtils::Manifest App::cpanminus
- name: Install Dependencies
run: cpanm -n --installdeps .
- name: Run Tests
run: cpanm --test-only -v .
[1]
Strawberry Perl 的便携版本已压缩,已经编译的 Perl 版本不需要您在 Windows 上运行安装程序。 这意味着不需要更高的权限等。您只需将存档解压缩到要从中运行 Perl 的目录中,然后在$env:PATH
变量中添加到 Perl 的相关路径。 它消除了构建不规则等的任何烦恼。我发现它是在 Windows 上测试的最明智的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.