How to Write Tests using Github Actions
Tags: perl, github
Published: 2022-06-28 06:25:58


I explain how to write tests using [Github Actions](https://docs.github.com/en/actions). This tests are run on Windows, [Linux](https://en.linux.perlzemi.com/)/[Ubuntu](https://en.ubuntu.perlzemi.com/)(64bit, 32bit), Mac, and support [Perl 5.8](https://en.perlzemi.com/blog/20160225145640.html). Dependent CPAN modules can be used.

This article is originally <a href="https://en.perlzemi.com/blog/20220628150309.html">How to Write Tests using Github Actions - Perl ABC</a>

### Examples of Tests using Github Actions

See examples at first.

[Examples](https://github.com/yuki-kimoto/SPVM-Time-Local/tree/master/.github/workflows)

### Downloading cpanm

Download `cpanm` into your home direcotry of your product and add excutable permission to it.

<pre>
curl -L http://cpanmin.us > cpanm
chmod +x cpanm
</pre>

### Github Actions Definitions

These are Github Actions.

#### Linux - Ubuntu - 64bit**Ubuntrulinux-ubuntu-latest.yml**

<pre>
name: linux-ubuntu-latest

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - run: perl -V
      - run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
      - run: perl cpanm -L ~/mylib -n SPVM
      - run: echo "PERL5LIB=$HOME/mylib/lib/perl5/"$(perl -MConfig -e 'print $Config{archname}') >> $GITHUB_ENV
      - run: perl Makefile.PL
      - run: make
      - run: make disttest
</pre>

#### Linux - Ubuntu - 32bit

**linux-ubuntu-latest-32bit.yml**

<pre>
name: linux-ubuntu-latest-32bit

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: i386/ubuntu:latest
    steps:
      - run: |
          apt update
          apt install -y libperl-dev build-essential
      - uses: actions/checkout@v1
      - run: perl -V
      - run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
      - run: perl cpanm -L ~/mylib -n SPVM
      - run: echo "PERL5LIB=$HOME/mylib/lib/perl5/"$(perl -MConfig -e 'print $Config{archname}') >> $GITHUB_ENV
      - run: perl Makefile.PL
      - run: make
      - run: make disttest
</pre>

#### Linux - Ubuntu - 64bit - Perl 5.8

**linux-ubuntu-latest-perl-5.8.9.yml**

<pre>
name: linux-ubuntu-latest-perl-5.8.9

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: shogo82148/actions-setup-perl@v1
        with:
          perl-version: '5.8.9'
      - run: perl -V
      - run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
      - run: perl cpanm ExtUtils::CBuilder
      - run: perl cpanm -L ~/mylib -n SPVM
      - run: echo "PERL5LIB=$HOME/mylib/lib/perl5/"$(perl -MConfig -e 'print $Config{archname}') >> $GITHUB_ENV
      - run: perl Makefile.PL
      - run: make
      - run: make disttest
</pre>

#### Mac

**macos-latest.yml**

<pre>
name: macos-latest

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:

jobs:
  build:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v1
      - run: brew install perl
      - run: perl -V
      - run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
      - run: perl cpanm -L ~/mylib -n SPVM
      - run: echo "PERL5LIB=$HOME/mylib/lib/perl5/"$(perl -MConfig -e 'print $Config{archname}') >> $GITHUB_ENV
      - run: perl Makefile.PL
      - run: make
      - run: make disttest
</pre>

#### Windows Server 2019

**windows-2019.yml**

<pre>
name: windows-2019

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:

jobs:
  perl:
    runs-on: windows-2019
    steps:
      - uses: actions/checkout@master
      - run: perl -V
      - run: perl -MConfig -MData::Dumper -e 'local $Data::Dumper::Sortkeys = 1;warn Dumper \%Config;'
      - run: perl cpanm -n SPVM
      - run: perl Makefile.PL
      - run: gmake
      - run: gmake disttest
</pre>