Skip to content

Instantly share code, notes, and snippets.

@YaFou
Last active April 22, 2020 20:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YaFou/e8f3e8abc7d4bb297df87f903ceeb6e2 to your computer and use it in GitHub Desktop.
Save YaFou/e8f3e8abc7d4bb297df87f903ceeb6e2 to your computer and use it in GitHub Desktop.
Some GitHub Actions workflows for continuous integration and nightly builds with PHP
name: Continuous integration
on:
push:
paths-ignore:
- '**.md'
- '.github/**'
pull_request:
paths-ignore:
- '**.md'
- '.github/**'
jobs:
test:
name: 'Test (PHP: ${{ matrix.php-versions }}, OS: ${{ matrix.operating-systems }}, dependencies: ${{ matrix.dependencies }})'
runs-on: ${{ matrix.operating-systems }}
# STRATEGY
strategy:
matrix:
operating-systems: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['7.3', '7.4']
dependencies: ['lowest', 'highest']
steps:
# SETUP
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
extensions: dom, mbstring
- name: Get Composer cache directory
id: composer-cache-directory
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Composer cache
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache-directory.outputs.dir }}
key: ${{ matrix.operating-systems }}_php${{ matrix.php-versions }}_dependencies-${{ matrix.dependencies }}_composer_${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ matrix.operating-systems }}_php${{ matrix.php-versions }}_dependencies-${{ matrix.dependencies }}_composer_
${{ matrix.operating-systems }}_php${{ matrix.php-versions }}_dependencies-${{ matrix.dependencies }}_
id: composer-cache
- name: Install lowest dependencies
if: matrix.dependencies == 'lowest'
run: composer update --prefer-lowest --no-interaction --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Install highest dependencies
if: matrix.dependencies == 'highest'
run: composer update --prefer-stable --no-interaction --no-progress --no-suggest --prefer-dist --optimize-autoloader
# TESTS
- name: Run tests and coverage
run: ./vendor/bin/phpunit
- name: Install lowest Codacy coverage dependency
run: composer require codacy/coverage --dev --prefer-dist --no-progress --no-suggest --prefer-lowest --optimize-autoloader
if: matrix.dependencies == 'lowest'
- name: Install highest Codacy coverage dependency
run: composer require codacy/coverage --dev --prefer-dist --no-progress --no-suggest --prefer-stable --optimize-autoloader
if: matrix.dependencies == 'highest'
- name: Send coverage
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: ./vendor/bin/codacycoverage phpunit coverage
- name: Upload coverage results
uses: actions/upload-artifact@v1
with:
name: 'Coverage results (PHP ${{ matrix.php-versions }}, OS ${{ matrix.operating-systems }}, dependencies ${{ matrix.dependencies }})'
path: ./coverage-html
name: Nighlty build
on:
schedule:
- cron: '0 0 * * *'
jobs:
build:
name: 'Build (branch: ${{ matrix.branches }})'
runs-on: ubuntu-latest
strategy:
matrix:
branches: ['dev', 'support/1.0.x', 'support/1.1.x', 'support/2.0.x']
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ matrix.branches }}
- name: Get build number
run: echo "::set-output name=build-number::$(date +%s)"
id: get-build-number
- name: Copy files in 'library' directory
run: |
mkdir library
cp -r ./src ./composer.json ./composer.lock ./.gitignore library
echo -e 'branch: ${{ matrix.branches }}\nbuild_number: ${{ steps.get-build-number.outputs.build-number }}' > library/.NIGHTLY_BUILD
- name: Format branch name
run: |
echo '${{ matrix.branches }}' > BRANCH
sed -i 's/\//_/g' BRANCH
echo "::set-output name=branch::$(cat BRANCH)"
rm BRANCH
id: format-branch-name
- name: Upload compressed library
uses: actions/upload-artifact@v1
with:
name: Nightly build (branch ${{ steps.format-branch-name.outputs.branch }}, build number ${{ steps.get-build-number.outputs.build-number }})
path: ./library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment