windows - 使用 github 操作在 Windows 上测试 Perl

标签 windows perl github-actions

我已经发布了 MooseX::Extended到 CPAN ( github repository here )。

我正在尝试设置 github 操作并且 linux 测试运行得很好。然而,( Windows is failing with this error :

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 模块 passes its CPAN testers tests on Windows ,所以我不知道为什么它在 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

This is the PR to which the actions are attached .

我无法访问 Windows 框。有谁知道我错过了什么?

最佳答案

由于 GitHub Actions/Workflows 使用的 Windows 容器已经具有 Strawberry Perl 版本预安装,它将不允许您安装任何其他版本。您无法删除预装的 Perl 版本,并且通过 Chocolatey 删除/安装新版本也几乎是不可能的。如果您重新安装容器中已有的 Chocolatey 版本,它似乎允许这样做,但它基本上是一个 NOOP 供您作为测试设置。

容器还安装了 MinGW;这对我们也不利。单独安装 MinGW 会阻止构建 XS 模块(无论它们是依赖项还是您自己的模块是 XS 模块)。当然,只有当 MinGW 出现在 Perl 安装之前的 PATH 中时才会发生这种情况,但是当您删除一个 Perl 并添加另一个 Perl 时,您就会遇到这个问题。

要解决这个问题,最好的做法是从 PATH 环境变量中删除当前安装的 Perl 版本,以及当前安装的 MinGW 版本。一旦两者都安全地脱离了 PATH,您就可以安装一个 Portable[1] Strawberry Perl , 将该 Perl 的路径放入您的 PATH 并开始使用全新安装的 Strawberry Perl 进行测试。 GitHub 最近打破了我们直接在 Action YAML 文件中执行此操作的能力。

这一切听起来很头疼,但事实并非如此。为此,我们可以使用一个操作: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 上进行测试的最明智的方法。

关于windows - 使用 github 操作在 Windows 上测试 Perl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72367353/

相关文章:

c - 如何在 linux 中使用 windows sockets 编译程序?

Python 等效于管道 zcat 结果到 Perl 中的文件句柄

node.js - Github Action err : bash: line 3: npm: command not found

android - 在 System.getenv 中找不到 Github Secret

c++ - GetTickCount() 换行时会发生什么?

c - 线程创建和删除的开销与未使用线程的开销

python - 是否将 Anaconda 添加到路径

perl - 为什么 Perl 在使用 bigint 时会警告 "useless constant 1"?

perl - 在 Perl/Moose 中,我可以有两个相互依赖的默认属性吗?

laravel - 您如何使用此 GitHub Actions 工作流程设置 PHP 版本?