Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active January 10, 2023 12:21
Show Gist options
  • Save vielhuber/4130f4fc3ee978baafb1b24b7e623190 to your computer and use it in GitHub Desktop.
Save vielhuber/4130f4fc3ee978baafb1b24b7e623190 to your computer and use it in GitHub Desktop.
github actions

setup

  • add /.github/workflows/ci.yml
  • see preset below that supports phpunit, npm, mysql, postgres, sqlite
  • push with new version tag to github
  • add a badge to README.MD: [![build status](https://github.com/username/repo/actions/workflows/ci.yml/badge.svg)](https://github.com/username/repo/actions)
  • enjoy

environment variables

  • can be defined in the yml file; if you want to use secret variables, define them additionally in Settings > Secrets > Actions > Repository secrets
  • note that $_ENV is not available, so use $_SERVER instead (in case of https://github.com/vlucas/phpdotenv)

check for travis CI inside php

  • if( @$_SERVER['CI'] == 'true' ) { }

notes

run github actions locally

  • curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
  • restart
  • startup docker
  • ./bin/act
  • caveat: not everything is working inside act (e.g. systemd)
name: CI
env:
CI: true
SECRET_VARIABLE_1: ${{ secrets.SECRET_VARIABLE_1 }}
SECRET_VARIABLE_2: ${{ secrets.SECRET_VARIABLE_2 }}
SECRET_VARIABLE_3: ${{ secrets.SECRET_VARIABLE_3 }}
on: [push]
jobs:
build-test:
strategy:
matrix:
operating-system: ['ubuntu-latest', 'macos-latest', 'windows-latest']
php-versions: ['7.4', '8.0', '8.1']
node-versions: ['14.18.0', '16.17.0', '18.12.1', '19.3.0']
runs-on: ${{ matrix.operating-system }}
name: ${{ matrix.operating-system }} (PHP ${{ matrix.php-versions }}, Node ${{ matrix.node-versions }})
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install libraries
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install -y coreutils
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install coreutils
elif [ "$RUNNER_OS" == "Windows" ]; then
choco install important_windows_software
fi
shell: bash
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-versions }}'
extensions: mysqli, xdebug, mbstring, xmlrpc, gd, intl, xml, zip, soap, bcmath, imap, opcache, pgsql, pdo, imagick
tools: composer, phpunit
- name: Install MySQL
run: |
sudo systemctl start mysql.service
- name: Install Composer
run: composer install --no-interaction
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: '${{ matrix.node-versions }}'
- name: Install NPM
run: npm install
- name: PHP Tests
run: ./vendor/bin/phpunit
- name: JS Tests
run: npm run js:tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment