簡體   English   中英

使用 github 操作在 Windows 上測試 Perl

[英]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

這是附加操作的 PR

我無權訪問 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM