[Info] Using Github Actions to Test Extensions

Discussion forum for Extension Writers regarding Extension Development.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

[Info] Using Github Actions to Test Extensions

Post by MattF »

Whether you are setting up an extension for the first time or looking to migrate your extension's CI test suite from Travis-CI over to Github Actions, these are the simple steps to take. This assumes you already have created PHPUnit tests for your extension. Also big thanks to Marc1706 for his hard work in figuring much of this out.

Installation:

1. From your repository on GitHub, click "Add File" and select "Create new file" and name the file .github/workflows/tests.yml.

This will result in adding the following to your repository (.github is a hidden directory that may already exist in your repository, depending on if you are using some of Github's other features.):

Code: Select all

.github/workflows/tests.yml
2. Copy the following into the tests.yml file:

Code: Select all

name: Tests

env:
    EXTNAME: vendor/ext # Your extension vendor/package name
    SNIFF: 1            # Run code sniffer on your code? 1 or 0
    IMAGE_ICC: 1        # Run icc profile sniffer on your images? 1 or 0
    EPV: 1              # Run EPV (Extension Pre Validator) on your code? 1 or 0
    EXECUTABLE_FILES: 1 # Run check for executable files? 1 or 0
    PHPBB_BRANCH: 3.3.x # The phpBB branch to run tests on

on:
    push:
        branches:        # Run tests when commits are pushed to these branches in your repo
            - master
            - develop
    pull_request:        # Run tests when pull requests are made on these branches in your repo
        branches:
            - master
            - develop

jobs:
    # START Basic Checks Job (EPV, code sniffer, images check, etc.)
    basic-checks:
        runs-on: ubuntu-18.04
        strategy:
            matrix:
                include:
                    - php: '7.1'
                      db: "none"
                      NOTESTS: 1

        name: PHP ${{ matrix.php }} - ${{ matrix.db }}

        steps:
            - name: Checkout phpBB
              uses: actions/checkout@v2
              with:
                  repository: phpbb/phpbb
                  ref: ${{ env.PHPBB_BRANCH }}
                  path: phpBB3

            - name: Checkout extension
              uses: actions/checkout@v2
              with:
                  path: phpBB3/phpBB/ext/${{ env.EXTNAME }}

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap
                  coverage: none

            - name: Setup environment for phpBB
              env:
                  DB: ${{ matrix.db }}
                  PHP_VERSION: ${{ matrix.php }}
                  NOTESTS: '1'
              run: .github/setup-phpbb.sh $DB $PHP_VERSION $NOTESTS
              working-directory: ./phpBB3

            - name: Setup EPV
              if: ${{ env.EPV != 0 }}
              run: composer require phpbb/epv:dev-master --dev --no-interaction --ignore-platform-reqs
              working-directory: ./phpBB3/phpBB

            - name: Run code sniffer
              if: ${{ env.SNIFF != 0 }}
              env:
                  NOTESTS: '1'
              run: .github/ext-sniff.sh $EXTNAME $NOTESTS
              working-directory: ./phpBB3

            - name: Check image ICC profiles
              if: ${{ env.IMAGE_ICC != 0 }}
              run: .github/check-image-icc-profiles.sh
              working-directory: ./phpBB3

            - name: Check executable files
              if: ${{ env.EXECUTABLE_FILES != 0 }}
              run: .github/ext-check-executable-files.sh ./ $EXTNAME
              working-directory: ./phpBB3

            - name: Run EPV
              if: ${{ env.EPV != 0 }}
              run: phpBB/vendor/bin/EPV.php run --dir="phpBB/ext/$EXTNAME/"
              working-directory: ./phpBB3
    # END Basic Checks Job

    # START MySQL and MariaDB Job
    mysql-tests:
        runs-on: ubuntu-18.04
        strategy:
            matrix:
                include:
                    - php: '7.1'
                      db: "mariadb:10.1"
                    - php: '7.1'
                      db: "mariadb:10.2"
                    - php: '7.1'
                      db: "mariadb:10.3"
                    - php: '7.1'
                      db: "mariadb:10.4"
                    - php: '7.1'
                      db: "mariadb:10.5"
                    - php: '7.1'
                      db: "mysql:5.6"
                      db_alias: "MyISAM Tests"
                      MYISAM: 1
                    - php: '7.1'
                      db: "mysql:5.6"
                    - php: '7.1'
                      db: "mysql:5.7"
                    - php: '7.2'
                      db: "mysql:5.7"
                    - php: '7.3'
                      db: "mysql:5.7"
                    - php: '7.4'
                      db: "mysql:5.7"
                    - php: '7.4'
                      db: "mysql:8.0"
                    - php: '8.0'
                      db: "mysql:5.7"
                    - php: '8.1'
                      db: "mysql:5.7"

        name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}

        services:
            mysql:
                image: ${{ matrix.db }}
                env:
                    MYSQL_ALLOW_EMPTY_PASSWORD: yes
                    MYSQL_DATABASE: phpbb_tests
                ports:
                    - 3306:3306
                options: >-
                    --health-cmd="mysqladmin ping"
                    --health-interval=10s
                    --health-timeout=5s
                    --health-retries=3

            redis:
                image: redis
                options: >-
                    --health-cmd "redis-cli ping"
                    --health-interval 10s
                    --health-timeout 5s
                    --health-retries 5
                ports:
                    - 6379:6379

        steps:
            - name: Checkout phpBB
              uses: actions/checkout@v2
              with:
                  repository: phpbb/phpbb
                  ref: ${{ env.PHPBB_BRANCH }}
                  path: phpBB3

            - name: Checkout extension
              uses: actions/checkout@v2
              with:
                  path: phpBB3/phpBB/ext/${{ env.EXTNAME }}

            - id: database-type
              env:
                  MATRIX_DB: ${{ matrix.db }}
              run: |
                  db=$(echo "${MATRIX_DB%%:*}")
                  echo "::set-output name=db::$db"

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap
                  coverage: none

            - name: Setup environment for phpBB
              env:
                  DB: ${{steps.database-type.outputs.db}}
                  PHP_VERSION: ${{ matrix.php }}
                  NOTESTS: '0'
              run: .github/setup-phpbb.sh $DB $PHP_VERSION ${NOTESTS:-0}
              working-directory: ./phpBB3

            - name: Setup database
              env:
                  DB: ${{steps.database-type.outputs.db}}
                  MYISAM: ${{ matrix.MYISAM != 1 && '0' || '1' }}
              run: .github/setup-database.sh $DB $MYISAM
              working-directory: ./phpBB3

            - name: Setup PHPUnit files
              run: mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_
              working-directory: ./phpBB3

            - name: Run unit tests
              env:
                  DB: ${{steps.database-type.outputs.db}}
              run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php
              working-directory: ./phpBB3
    # END MySQL and MariaDB Job

    # START PostgreSQL Job
    postgres-tests:
        runs-on: ubuntu-18.04
        strategy:
            matrix:
                include:
                    - php: '7.1'
                      db: "postgres:9.5"
                    - php: '7.1'
                      db: "postgres:9.6"
                    - php: '7.1'
                      db: "postgres:10"
                    - php: '7.1'
                      db: "postgres:11"
                    - php: '7.1'
                      db: "postgres:12"
                    - php: '7.1'
                      db: "postgres:13"

        name: PHP ${{ matrix.php }} - ${{ matrix.db }}

        services:
            postgres:
                image: ${{ matrix.db != 'postgres:9.5' && matrix.db != 'postgres:9.6' && matrix.db != 'postgres:10' && matrix.db != 'postgres:11' && matrix.db != 'postgres:12' && matrix.db != 'postgres:13' && 'postgres:10' || matrix.db }}
                env:
                    POSTGRES_HOST: localhost
                    POSTGRES_USER: postgres
                    POSTGRES_PASSWORD: postgres
                ports:
                    - 5432:5432
                options: >-
                    -v /var/run/postgresql:/var/run/postgresql
                    --health-cmd pg_isready
                    --health-interval 10s
                    --health-timeout 5s
                    --health-retries 5

            redis:
                image: redis
                options: >-
                    --health-cmd "redis-cli ping"
                    --health-interval 10s
                    --health-timeout 5s
                    --health-retries 5
                ports:
                    - 6379:6379

        steps:
            - name: Checkout phpBB
              uses: actions/checkout@v2
              with:
                  repository: phpbb/phpbb
                  ref: ${{ env.PHPBB_BRANCH }}
                  path: phpBB3

            - name: Checkout extension
              uses: actions/checkout@v2
              with:
                  path: phpBB3/phpBB/ext/${{ env.EXTNAME }}

            - id: database-type
              env:
                  MATRIX_DB: ${{ matrix.db }}
              run: |
                  db=$(echo "${MATRIX_DB%%:*}")
                  echo "::set-output name=db::$db"

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap
                  coverage: none

            - name: Setup environment for phpBB
              env:
                  DB: ${{steps.database-type.outputs.db}}
                  PHP_VERSION: ${{ matrix.php }}
                  NOTESTS: '0'
              run: .github/setup-phpbb.sh $DB $PHP_VERSION ${NOTESTS:-0}
              working-directory: ./phpBB3

            - name: Setup database
              env:
                  DB: ${{steps.database-type.outputs.db}}
                  MYISAM: '0'
              run: .github/setup-database.sh $DB $MYISAM
              working-directory: ./phpBB3

            - name: Setup PHPUnit files
              run: mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_
              working-directory: ./phpBB3

            - name: Run unit tests
              env:
                  DB: ${{steps.database-type.outputs.db}}
              run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php
              working-directory: ./phpBB3
    # END PostgreSQL Job

    # START Other Tests Job (SQLite 3 and mssql)
    other-tests:
        runs-on: ubuntu-18.04
        strategy:
            matrix:
                include:
                    - php: '7.1'
                      db: "sqlite3"
                    - php: '7.2'
                      db: "mcr.microsoft.com/mssql/server:2017-latest"
                      db_alias: 'MSSQL 2017'
                    - php: '7.2'
                      db: "mcr.microsoft.com/mssql/server:2019-latest"
                      db_alias: 'MSSQL 2019'

        name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}

        services:
            mssql:
                image: ${{ matrix.db != 'mcr.microsoft.com/mssql/server:2017-latest' && matrix.db != 'mcr.microsoft.com/mssql/server:2019-latest' && 'mcr.microsoft.com/mssql/server:2017-latest' || matrix.db }}
                env:
                    SA_PASSWORD: "Pssw0rd_12"
                    ACCEPT_EULA: "y"
                ports:
                    - 1433:1433
                options: >-
                    --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Pssw0rd_12' -Q \"Use [master]; CREATE DATABASE [phpbb_tests] COLLATE Latin1_General_CI_AS\" || exit 1"
                    --health-interval 10s
                    --health-timeout 5s
                    --health-retries 5
                    --health-start-period 10s

            redis:
                image: redis
                options: >-
                    --health-cmd "redis-cli ping"
                    --health-interval 10s
                    --health-timeout 5s
                    --health-retries 5
                ports:
                    - 6379:6379

        steps:
            - name: Checkout phpBB
              uses: actions/checkout@v2
              with:
                  repository: phpbb/phpbb
                  ref: ${{ env.PHPBB_BRANCH }}
                  path: phpBB3

            - name: Checkout extension
              uses: actions/checkout@v2
              with:
                  path: phpBB3/phpBB/ext/${{ env.EXTNAME }}

            - id: database-type
              env:
                  MATRIX_DB: ${{ matrix.db }}
              run: |
                  if [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2017-latest' ] || [ $MATRIX_DB == 'mcr.microsoft.com/mssql/server:2019-latest' ]
                  then
                      db='mssql'
                  else
                      db=$(echo "${MATRIX_DB%%:*}")
                  fi
                  echo "::set-output name=db::$db"

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap
                  coverage: none

            - name: Setup environment for phpBB
              env:
                  DB: ${{steps.database-type.outputs.db}}
                  PHP_VERSION: ${{ matrix.php }}
                  NOTESTS: '0'
              run: .github/setup-phpbb.sh $DB $PHP_VERSION ${NOTESTS:-0}
              working-directory: ./phpBB3

            - name: Setup database
              env:
                  DB: ${{steps.database-type.outputs.db}}
                  MYISAM: '0'
              run: .github/setup-database.sh $DB $MYISAM
              working-directory: ./phpBB3

            - name: Setup PHPUnit files
              run: mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_
              working-directory: ./phpBB3

            - name: Run unit tests
              env:
                  DB: ${{steps.database-type.outputs.db}}
              run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php
              working-directory: ./phpBB3
    # END Other Tests Job
:!: You must change the EXTNAME variable to your extension's name (as you defined it in your composer.json file).

3. To run your workflow, scroll to the bottom of the page and select Create a new branch for this commit and start a pull request. Then, to create a pull request, click Propose new file.

That's it. You're most likely done! Once you merge this PR, all future commits and pull requests will trigger this CI workflow.

Customizing:

SNIFF:
IMAGE_ICC:
EPV:
EXECUTABLE_FILES:
:
You may also enable or disable additional tests such as the EPV, Code Sniffer, checking any images in your extension for ICC profiles and checking for executable text files by changing these variables to either 1 or 0.

PHPBB_BRANCH:
You may set the version of phpBB you want your extension tested in using this variable. This boilerplate is using the current version of phpBB which is the 3.3.x branch. Older versions of phpBB are not being supported but can still be used with Travis-CI.com.

TEST BRANCHES:
You may also add or remove the names of branches in your repository that you want tests run on. This boiler plate will trigger tests on commits or PRs to the master and develop branches in your repo.

PHP & DATABASE TEST ENVIRONMENTS:
Finally you may also make changes to the jobs. This boilerplate is made up of several jobs based on the databases being tested:
  • Basic Checks: The basic-checks job does not do any PHPUnit testing. This is where EPV, Code Sniffer and Image Profile checks run. If you never intend to run these checks you may either delete or comment out the entire basic-checks job.
  • MySQL Tests: The mysql-tests job runs PHPUnit tests in various MySQL and MariaDB and PHP combinations. They are all defined in the matrix which is the same as Travis-CI config files used. This boilerplate only runs in versions of PHP 7 and PHP 8 but you could, for example, add tests for versions of PHP 5. (Note that to include PHP 5 in the test matrix you must change the ubuntu server for that job to runs-on: ubuntu-16.04). You may delete or comment out some of the tests in the matrix if you do not want to test certain versions of PHP or MySQL or MariaDB.
  • PostgreSQL Tests: The postgres-tests job runs PHPUnit tests in various versions of PostgreSQL. The PHP version is consistent throughout since the mysql-checks job is the where we do most of our PHP environment checks. You may add additional checks to this matrix or you may either delete or comment out the entire postgres-tests job if you do not need to test PostgreSQL.
  • MSSQL, SQLite: The other-tests job runs PHPUnit tests in various versions of MSSQL and SQLite3. You may either delete or comment out the MSSQL or SQLite3 checks in the matrix if you do not need to test on either of those databases, or delete or comment out the entire other-tests job if you do not need to test any of these databases.
Migrating from Travis-CI

If you were previously using Travis-CI, to migrate over to Github Actions just follow the steps mentioned above. You should reference your old .travis.yml file when making the customization changes documentated above to your new tests.yml file.

Then you should delete the travis folder and .travis.yml files from your repository. This will cease Travis-CI testing on your repo.

Finally you should add the .github folder to any .gitattributes and build.xml. You could also remove any lingering references to travis in these files too.

This PR from the phpBB Advertisement Management Extension can prove a helpful guide in how we migrated from Travis-CI to Github Actions: https://github.com/phpbb-extensions/ad- ... t/pull/156

README Badges

Don't forget about adding a test status badge to your repo readme! Just change GITHUB-USERNAME/REPO-NAME.

Code: Select all

[![Build Status](https://github.com/GITHUB-USERNAME/REPO-NAME/workflows/Tests/badge.svg)](https://github.com/GITHUB-USERNAME/REPO-NAME/actions)
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by MattF »

This post is reserved to notify of any changes to the above post.

Dec 28, 2020:
The phpBB Extension Skeleton official extension v1.1.6 now supports generating the Github Actions workflow template posted above.

Dec 29, 2020:
If you are interested in adding a test on a Windows server here is the job code for that. Note that the Windows server test is pretty slow and the PHP version and DBM tested are already tested in the Linnux builds.

Code: Select all

    # START Test with IIS & PostgreSQL on Windows
    windows-tests:
        runs-on: windows-2016
        strategy:
            matrix:
                include:
                    - php: '7.4'
                      db: "postgres"

        name: Windows - PHP ${{ matrix.php }} - ${{ matrix.db }}

        steps:
            - name: Prepare git for Windows
              run: |
                  git config --system core.autocrlf false
                  git config --system core.eol lf

            - name: Checkout phpBB
              uses: actions/checkout@v2
              with:
                  repository: phpbb/phpbb
                  ref: ${{ env.PHPBB_BRANCH }}
                  path: phpBB3

            - name: Checkout extension
              uses: actions/checkout@v2
              with:
                  path: phpBB3/phpBB/ext/${{ env.EXTNAME }}

            - name: Setup PHP
              uses: shivammathur/setup-php@v2
              with:
                  php-version: ${{ matrix.php }}
                  extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, intl, gd, exif, iconv, pgsql, pdo_pgsql
                  ini-values: upload_tmp_dir=${{ runner.temp }}, sys_temp_dir=${{ runner.temp }}
                  coverage: none

            - name: Setup environment for phpBB
              env:
                  GITHUB_WORKSPACE: ${{ github.workspace }}
                  TEMP_DIR: ${{ runner.temp }}
              run: |
                  Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole, IIS-WebServer, IIS-CommonHttpFeatures, IIS-ManagementConsole, IIS-HttpErrors, IIS-HttpRedirect, IIS-WindowsAuthentication, IIS-StaticContent, IIS-DefaultDocument, IIS-HttpCompressionStatic, IIS-DirectoryBrowsing, IIS-WebServerManagementTools, IIS-CGI -All
                  Set-Service wuauserv -StartupType Manual
                  (Get-Content ${env:GITHUB_WORKSPACE}\phpBB3\phpBB\web.config).replace("<configuration>", "<configuration>`n`t<system.web>`n`t`t<customErrors mode=`"Off`"/>`n`t</system.web>") | Set-Content ${env:GITHUB_WORKSPACE}\phpBB3\phpBB\web.config
                  (Get-Content ${env:GITHUB_WORKSPACE}\phpBB3\phpBB\web.config).replace("`t</system.webServer>", "`t`t<httpErrors errorMode=`"Detailed`" />`n`t</system.webServer>") | Set-Content ${env:GITHUB_WORKSPACE}\phpBB3\phpBB\web.config
                  choco install urlrewrite -y
                  Import-Module WebAdministration
                  New-WebSite -Name 'phpBBTest' -PhysicalPath "${env:GITHUB_WORKSPACE}\phpBB3\phpBB" -Force
                  $session = Get-PSSession -Name WinPSCompatSession
                  $sb = {Set-ItemProperty 'IIS:\Sites\phpBBTest' -name Bindings -value @{protocol='http';bindingInformation='*:80:phpbb.test'}}
                  Invoke-Command -Scriptblock $sb -Session $session
                  $sb = {Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value true -location "IIS:\Sites\phpBBTest"}
                  Invoke-Command -Scriptblock $sb -Session $session
                  Add-Content -Path $env:windir\System32\drivers\etc\hosts -Value "`r`n127.0.0.1`tphpbb.test" -Force
                  [System.Environment]::SetEnvironmentVariable('PATH',$Env:PATH+";%windir%\system32\inetsrv")
                  echo Setup FAST-CGI configuration
                  Add-WebConfiguration -Filter /system.webServer/fastCgi -PSPath IIS:\ -Value @{fullpath="C:\tools\php\php-cgi.exe"}
                  echo Setup FACT-CGI handler
                  New-WebHandler -Name "PHP-FastCGI" -Path "*.php" -Modules FastCgiModule -ScriptProcessor "C:\tools\php\php-cgi.exe" -Verb '*' -ResourceType Either
                  iisreset
                  NET START W3SVC
                  mkdir "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\cache\test"
                  mkdir "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\cache\installer"
                  icacls "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\cache" /grant Users:F /T
                  icacls "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\files" /grant Users:F /T
                  icacls "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\store" /grant Users:F /T
                  icacls "${env:GITHUB_WORKSPACE}\phpBB3\phpBB\images\avatars\upload" /grant Users:F /T
                  $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow")
                  $acl = Get-ACL "${env:TEMP_DIR}"
                  $acl.AddAccessRule($accessRule)
                  Set-ACL -Path "${env:TEMP_DIR}" -ACLObject $acl
                  cd ${env:GITHUB_WORKSPACE}\phpBB3\phpBB
                  php ..\composer.phar install
                  cd ..

            - name: Setup database
              run: |
                  $postgreSqlSvc = Get-Service "postgresql*"
                  Set-Service $postgreSqlSvc.Name -StartupType manual
                  $postgreSqlSvc.Start()
                  try {
                    (Get-Service "postgresql*").Start()
                  } catch  {
                    $_ | select *
                  }
                  [System.Environment]::SetEnvironmentVariable('PATH',$Env:PATH+";${env:PGBIN}")
                  $env:PGPASSWORD = 'root'
                  psql -c 'DROP DATABASE IF EXISTS phpbb_tests;' -U postgres
                  psql -c 'create database phpbb_tests;' -U postgres

            - name: Setup PHPUnit files
              run: copy ".github\phpunit-psql-windows-github.xml" "phpBB\ext\${env:EXTNAME}\.github\"
              working-directory: ./phpBB3

            - name: Run unit tests
              run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/${env:EXTNAME}/.github/phpunit-psql-windows-github.xml --bootstrap ./tests/bootstrap.php --verbose --stop-on-error
              working-directory: ./phpBB3
    # END Test with IIS & PostgreSQL on Windows
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by MattF »

As of right now, the extecutable files check has not yet been merged to phpBB, so until then the EXECUTABLE_FILES option should be set to 0.
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by MattF »

PHP 8 Issue:

If your test suite does not have functional tests, you will probably get a fail in the PHP 8 tests. To fix this you must add the --testsuite 'phpBB Test Suite' option to the run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php command.

So it would look like this:

Code: Select all

run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php --testsuite 'phpBB Test Suite'
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
david63
Registered User
Posts: 19067
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by david63 »

Thanks for all of that Matt and Marc. I have been following your efforts on Discord

Will give it a try (after Christmas!)
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
RMcGirr83
Former Team Member
Posts: 21913
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: [Info] Using Github Actions to Test Extensions

Post by RMcGirr83 »

Ditto! The efforts are much appreciated.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
User avatar
KaileyT
Community Team Member
Community Team Member
Posts: 2933
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by KaileyT »

If we are only using EPV, is it as simple as removing the MySQL Tests, PostgreSQL Tests and MSSQL, SQLite sections from our tests.yml file?
Kailey Truscott - Community Team
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by MattF »

KaileyT wrote:
Thu Dec 24, 2020 11:24 pm
If we are only using EPV, is it as simple as removing the MySQL Tests, PostgreSQL Tests and MSSQL, SQLite sections from our tests.yml file?
Yep. Each of those sections are surrounded by # START and # END comments so you know where they begin and end.
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by MattF »

If anyone is interested in Code Coverage analysis:

I used to use Scrutinizer for Code Coevrage. But I just could not get it to work with Github Actions, so I switched over to Codecov.com. I made some adjustments to the MySQL job section to enable the creation and sending of a code coverage report to Codecov.com, and you can take a look at what I changed in this extension of mine as an example:

https://github.com/iMattPro/topicprevie ... l#L90-L236
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
RMcGirr83
Former Team Member
Posts: 21913
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: [Info] Using Github Actions to Test Extensions

Post by RMcGirr83 »

Ran into a slight issue. If you're like me and using application integration, say smartgit, you must allow the application to access workflows in it's token you assign in github. Steps are
  1. In Github click on your avatar and go to settings
  2. Go to developer settings -> Personal Access Tokens
  3. If the application is listed, click on its name to edit the settings associated with its OAuth token...make sure workflow is checked
  4. Click on update token to save the change
  5. On the same page click on Generate Token and copy the new token that Github shows you
  6. You then need to update or recreate your applications integration with github using the new token
For Smartgit -> Edit -> Preferences-> hosting providers. Click on the name and choose edit. Paste the new token into the token field and save.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 27163
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by Paul »

That most likely only applies if you originally checked it out using HTTPS. If you did check it out using SSH, it should work without setting the workflow option
User avatar
RMcGirr83
Former Team Member
Posts: 21913
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: [Info] Using Github Actions to Test Extensions

Post by RMcGirr83 »

OAuth is only over https no? I can choose to use either SSH or OAuth via smartgit.

[EDIT] I don't have tests in my repos and am getting errors on PHP 8 with the edited line in the tests.yml file per the post above.
Capture.PNG
Capture.PNG (9.68 KiB) Viewed 1838 times
[/EDIT]
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beerImage
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 27163
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by Paul »

Yes, oAuth is, as far as I know, only used over HTTPs. Over SSH, it uses your SSH private key to authenticate instead of oAuth. Using HTTPS with phpstorm together might also give issues, as it uses a 3rd party intergration, and that one also doesn't have the workflow scope setup, causing it to not work.
User avatar
david63
Registered User
Posts: 19067
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by david63 »

OK - I have got it working, but have the same problem as Rich re PHP 8/8.1. Removing those lines I get it run without any issues.

Thanks Rich for the tip about SmartGit integration.

The one thing that I did differently to Matt's OP was to create the tests.yml file (and its structure) on my local machine and then push it to GitHub.

Now have to start moving everything over to GitHub Actions :cry:
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5352
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [Info] Using Github Actions to Test Extensions

Post by MattF »

david63 wrote:
Sat Dec 26, 2020 2:01 pm
The one thing that I did differently to Matt's OP was to create the tests.yml file (and its structure) on my local machine and then push it to GitHub.
yes you can do it that way too. but i suggested it via github since it may not be straight forward for some to create the .github directory on an OS since it is a hidden directory.
david63 wrote:
Sat Dec 26, 2020 2:01 pm
Now have to start moving everything over to GitHub Actions :cry:
This is actually really easy. Once you've set up up one extension that is. I just copy the entire .github folder from one extension to another in my IDE, open the test.yml and change the EXTNAME and push it to the repo (remembering of course to delete old travis stuff too).
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
Post Reply

Return to “Extension Writers Discussion”