Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add GitHub Actions workflow #21

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
65 changes: 65 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This file lints the code and runs tests.
name: CI

on:
pull_request:
push:

env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --no-suggest --prefer-dist"

jobs:
tests:
runs-on: ubuntu-20.04
strategy:
matrix:
php:
- '8.0'
- '7.4'
- '7.3'
- '7.2'
- '7.1'
- '7.0'
- '5.6'
include:
- php: '7.0'
cs_fixer: true
name: 'Check with PHP ${{ matrix.php }}'
steps:
- uses: actions/checkout@v2

- name: Install Nix
uses: cachix/install-nix-action@v12

- name: Set up Nix cache
uses: cachix/cachix-action@v8
with:
# Use cache from https://github.com/fossar/nix-phps
name: fossar
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way Nix works, it takes build instructions for packages and builds them. It can also substitute the build result from a cache to reduce work. But since these are custom packages, they are not built by the official build servers and we need to use our own cache. I added a comment with a link to the repository that builds it.


- name: Update flake.nix to match the current CI job from matrix
run: sed -i 's/matrix.phpPackage = "php";/matrix.phpPackage = builtins.replaceStrings ["."] [""] "php${{ matrix.php }}";/' flake.nix

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- uses: actions/cache@v2
env:
cache-name: cache-composer-modules
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
run: nix-shell --run 'composer install'

- name: Lint source code
if: matrix.cs_fixer
run: nix-shell --run 'composer cs-check'

- name: Run unit tests
run: nix-shell --run 'composer test'
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
"symfony/phpunit-bridge": "^5.2",
"friendsofphp/php-cs-fixer": "~2.17"
},
"config": {
"bin-dir": "bin"
"scripts": {
"cs-check": "php-cs-fixer fix --verbose --dry-run --diff",
"cs-fix": "php-cs-fixer fix --verbose --diff",
"test": "simple-phpunit --verbose --bootstrap test/test-init.php test/WideImage"
},
"scripts-descriptions": {
"cs-check": "Check coding style",
"cs-fix": "Fix coding style",
"test": "Run all tests"
}
}
78 changes: 78 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
description = "An open-source PHP library for image manipulation";

inputs = {
# For old PHP versions.
phps.url = "github:fossar/nix-phps";
};

outputs = { self, phps }:
let
# nixpkgs is a repository with software packages and some utilities.
# From simplicity, we inherit it from the phps flake.
inherit (phps.inputs) nixpkgs;

# Configure the development shell here (e.g. for CI).

# By default, we use the default PHP version from Nixpkgs.
matrix.phpPackage = "php";
in
let
# We only support a single platform at the moment,
# since our binary cache only contains PHP packages for that.
system = "x86_64-linux";

# Get Nixpkgs packages for current platform.
pkgs = nixpkgs.legacyPackages.${system};

# Create a PHP package from the selected PHP package.
php = phps.packages.${system}.${matrix.phpPackage};
in {
# Expose shell environment for development.
devShell.${system} = pkgs.mkShell {
nativeBuildInputs = [
# Composer and PHP.
php
php.packages.composer
];
};
};
}
3 changes: 1 addition & 2 deletions lib/TrueColorImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ public function resizeInsideRect(
$alignTop = 'center',
$mergeOpacity = 100,
$fillColor = null
)
{
) {
if ($fillColor) {
if (is_numeric($fillColor)) {
$fillColor = $this->getColorRGB($fillColor);
Expand Down
9 changes: 9 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).shellNix
1 change: 0 additions & 1 deletion test/run.bat

This file was deleted.

1 change: 0 additions & 1 deletion test/run.sh

This file was deleted.