Skip to content

Commit

Permalink
ci: Auto-determine checks to run
Browse files Browse the repository at this point in the history
This will allow us to support multiple platforms easily.
  • Loading branch information
jtojnar committed May 15, 2022
1 parent 0e8ee01 commit 104ae88
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 42 deletions.
42 changes: 1 addition & 41 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,4 @@ jobs:
name: fossar
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- name: Set job parameters
id: params
run: |
branch=${{ matrix.php.branch }}
major=${branch%%.*}
minor=${branch#*.}
attr=php$major$minor
echo "::set-output name=major::$major"
echo "::set-output name=attr::$attr"
- name: Build PHP
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-php

- name: Build Imagick extension
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-imagick

- name: Build Redis extension
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-redis

- name: Build Redis 3 extension
if: ${{ steps.params.outputs.major < 8 }}
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-redis3

- name: Build MySQL extension
if: ${{ steps.params.outputs.major < 7 }}
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-mysql

- name: Build Xdebug extension
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-xdebug

- name: Build Tidy extension
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-tidy

- name: Check that composer PHAR works
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-composer-phar

- name: Validate php.extensions.mysqli default unix socket path
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-mysqli-socket-path

- name: Validate php.extensions.pdo_mysql default unix socket path
run: nix-build -A outputs.checks.x86_64-linux.${{ steps.params.outputs.attr }}-pdo_mysql-socket-path
- run: nix-shell run-flake-checks.nix --argstr branch "${{ matrix.php.branch }}"
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
}:

drv // {
description = "PHP ${phpVersion}${description}";
inherit description;
phpBranch = phpVersion;
}
)
supportedChecks;
Expand Down
67 changes: 67 additions & 0 deletions run-flake-checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Runs Nix flake checks individually with group markers for GitHub Actions.
# Invoke with `nix-shell run-flake-checks.nix --argstr branch "8.1"`
{
# PHP attribute to run checks for. `null` for all checks.
branch ? null,
}:

let
self = import ./.;

pkgs = self.inputs.nixpkgs.legacyPackages.${builtins.currentSystem};
inherit (self.inputs.nixpkgs) lib;

checks = self.outputs.checks.${builtins.currentSystem};

phpName =
assert lib.assertMsg (builtins.match "[0-9]+.[0-9]+" branch != null) "Branch name “${builtins.toString branch}” does not match a version number.";

"php${lib.versions.major branch}${lib.versions.minor branch}";

relevantChecks =
if branch == null
then checks
else lib.filterAttrs (key: value: lib.hasPrefix "${phpName}-" key) checks;
in

assert lib.assertMsg (relevantChecks != { }) "No checks found for branch “${builtins.toString branch}”.";

pkgs.stdenv.mkDerivation {
name = "run-flake-checks";

buildCommand = ''
echo 'Please run `nix-shell run-flake-checks.nix`, `nix-build` cannot be used.' > /dev/stderr
exit 1
'';

shellHook =
''
set -o errexit
''
+ builtins.concatStringsSep
"\n"
(
lib.mapAttrsToList
(
name:
value:

let
description =
lib.optionalString (branch == null) "PHP ${value.phpBranch} – "
+ value.description;
in
''
echo "::group::${description}"
echo Run nix-build -A outputs.checks.${builtins.currentSystem}.${name}
nix-build --no-out-link -A outputs.checks.${builtins.currentSystem}.${name}
echo "::endgroup::"
''
)
relevantChecks
)
+ ''
exit 0
''
;
}

0 comments on commit 104ae88

Please sign in to comment.