support for github workflow steps
authorMichael Wallner <mike@php.net>
Tue, 12 Jan 2021 14:52:51 +0000 (15:52 +0100)
committerMichael Wallner <mike@php.net>
Tue, 12 Jan 2021 14:53:52 +0000 (15:53 +0100)
.editorconfig [new file with mode: 0644]
Makefile
README.md
gen-matrix.php

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..5e99128
--- /dev/null
@@ -0,0 +1,19 @@
+; see http://editorconfig.org
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = tab
+charset = utf-8
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.json]
+indent_style = space
+indent_size = 4
+
+[*.php]
+indent_style = space
index 4a903a800030c45581df06f9fd58e99cff648477..e417b5201909e901a6251fbb56d8c27389153bb1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,26 +1,27 @@
 export
 
+<<<<<<< HEAD
 PHP ?= 7.4
+=======
+PHP ?= 8.0
+>>>>>>> 3cab5c6 (support for github workflow steps)
 JOBS ?= 2
 PHP_MIRROR ?= https://php.net/distributions/
 TMPDIR ?= /tmp
 
-makdir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+mkfile := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
+makdir := $(dir $(mkfile))
 
-ifdef TRAVIS
-prefix ?= $(HOME)/cache/php-$(PHP)-$(shell env |grep -E '^with_|^enable_' | tr -c '[a-zA-Z_]' -)
-else
-prefix ?= $(TMPDIR)/php-$(PHP)-$(shell env |grep -E '^with_|^enable_' | tr -c '[a-zA-Z_]' -)
+ifeq (,$(findstring printenv,$(MAKECMDGOALS)))
+mkargs := $(shell $(MAKE) -f $(mkfile) printenv | sed -n -e 's,with_,,gp' -e 's,enable_,,gp' | tr -c '[a-zA-Z_]' -)
 endif
+
+prefix ?= $(TMPDIR)/php-$(PHP)-$(mkargs)
 exec_prefix ?= $(prefix)
 bindir = $(exec_prefix)/bin
 srcdir = $(prefix)/src
-ifdef TRAVIS_BUILD_DIR
-curdir ?= $(TRAVIS_BUILD_DIR)
-else
 # CURDIR is a make builtin
 curdir ?= $(CURDIR)
-endif
 
 enable_maintainer_zts ?= no
 enable_debug ?= no
@@ -56,6 +57,12 @@ CPPCHECK_ARGS ?= -v -j $(JOBS) --std=$(CPPCHECK_STD) --enable=$(CPPCHECK_ENABLE)
 .PHONY: all
 all: php
 
+.PHONY: printenv
+printenv:
+       @env | grep -E 'prefix=|dir=' | grep -v config_file_scan_dir | sort
+       @env | grep -E '^PHP|^PECL' | sort
+       @env | grep -E '^with_|^enable_' | grep -Ev 'php_config|config_file_scan_dir' | sort
+
 .PHONY: versions
 versions: $(PHP_RELEASES)
        grep "^$(PHP)" $< | cut -f1-2
@@ -112,7 +119,7 @@ $(srcdir) $(extdir) $(with_config_file_scan_dir):
 .PHONY: pecl-check
 pecl-check:
        @if test -z "$(PECL)"; then echo "No pecl extension specified, e.g. PECL=pecl_http:http"; exit 1; fi
-       if test -d $(PECL_DIR)/.git; then cd $(PECL_DIR)/; git pull; fi
+       if test -d $(PECL_DIR)/.git; then cd $(PECL_DIR)/; git pull || test -z "$$CI"; fi
 
 .PHONY: pecl-clean
 pecl-clean:
index 45c4c60f6554c27de86874baf6d226f5bc711461..64187d5864d8d92b133e2fa2b5219bd1eb407dd9 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,12 +1,12 @@
-# travis-pecl
+# pecl-ci
 
-These few lines of code support building and testing PHP extensions on Travis-CI.
+These few lines of code support building and testing PHP extensions on CI.
 
 ## Usage
 
 First, we'll add this repo to our extension as submodule:
 
-    git submodule add -n travis-pecl https://github.com/m6w6/travis-pecl.git travis/pecl
+    git submodule add -n pecl-ci https://github.com/m6w6/pecl-ci.git scripts/ci
     git submodule update --init
 
 Let's build a `.travis.yml`by example. We'll use a simple PHP script, e.g. `gen_travis_yml.php`,
@@ -33,7 +33,7 @@ which will generate the configuration for us:
     <?php
     
     # instantiate the generator
-    $gen = include "travis/pecl/gen-matrix.php";
+    $gen = include "scripts/ci/gen-matrix.php";
     
     # generate the matrix
     $env = $gen([
@@ -58,15 +58,15 @@ which will generate the configuration for us:
     
     before_script:
       # build the matrix' PHP version
-      - make -f travis/pecl/Makefile php
+      - make -f scripts/ci/Makefile php
       # build the extension, the PECL variable expects the extension name 
       # and optionally the soname and a specific version of the extension
       # separeated by double colon, e.g. PECL=myext:ext:1.7.5
-      - make -f travis/pecl/Makefile ext PECL=myext
+      - make -f scripts/ci/Makefile ext PECL=myext
     
     script:
       # run the PHPT test suite
-      - make -f travis/pecl/Makefile test
+      - make -f scripts/ci/Makefile test
     
 
 That's it, more TBD.
index 289209cfc6b716c584e75be3a55e669b95a8795d..1901afbb0131c28b8e51ae3bdf589c0535967c0d 100644 (file)
 <?php
 
-return function() {
-       foreach (func_get_args() as $array) {
-               $apc = [];
-               foreach ($array as $key => $values) {
-                       if (is_numeric($key) && is_string($values)) {
-                               // switch on yes/no
-                               $key = $values;
-                               $values = ["no", "yes"];
-                       } else if (is_numeric($key) && is_array($values)) {
-                               // mutually enasbled options
-                               $vpc = [];
-                               foreach ($values as $yes) {
-                                       $mpc = "$yes=yes ";
-                                       foreach ($values as $no) {
-                                               if ($yes === $no) {
-                                                       continue;
-                                               }
-                                               $mpc .= "$no=no ";
-                                       }
-                                       $vpc[] = $mpc;
-                               }
-                               $key = null;
-                               $values = $vpc;
-                       }
+return new class {
+    function github(array $matrix) {
+        $idx = function($job_id) {
+            static $ids = [];
+            
+            $parts = explode("-", $job_id);
+            $count = end($parts);
+            if (is_numeric($count)) {
+                unset($parts[key($parts)]);
+            }
+            
+            $base = implode("-", $parts);
+            if (isset($ids[$base])) {
+                $ids[$base]++;
+            } else {
+                $ids[$base] = 0;
+            }
+            $parts[] = $ids[$base];
+            
+            return implode("-", $parts);
+        };
+        
+        $all_jobs = [];
+        foreach ($matrix as $id => $array) {
+            $jobs = [];
+            foreach ($array as $key => $values) {
+                if (is_numeric($key) && is_string($values)) {
+                    // duplicate each job and switch on yes/no
+                    if (!$jobs) {
+                        $jobs[$idx($id)][$values] = "yes";
+                        $jobs[$idx($id)][$values] = "no";
+                    } else {
+                        foreach (array_keys($jobs) as $job_id) {
+                            $jobs[$job_id][$values] = "yes";
+                            $job_idx = $idx($job_id);
+                            $jobs[$job_idx] = $jobs[$job_id];
+                            $jobs[$job_idx][$values] = "no";
+                        }
+                    }
+                } else if (is_numeric($key) && is_array($values)) {
+                    // multiplicate each job for each mutually enabled combination of options
+                    $all_mut = [];
+                    foreach ($values as $yes) {
+                        $mut = [$yes => "yes"];
+                        foreach ($values as $no) {
+                            if ($yes !== $no) {
+                                $mut[$no] = "no";
+                            }
+                        }
+                        $all_mut[] = $mut;
+                    }
+                    
+                    if (!$jobs) {
+                        foreach ($all_mut as $mut) {
+                            $jobs[$idx($id)] = $mut;
+                        }
+                    } else {
+                        foreach (array_keys($jobs) as $job_id) {
+                            foreach ($all_mut as $i => $mut) {
+                                $mut_job = array_merge($jobs[$job_id], $mut);
+                                if ($i == 0) {
+                                    $jobs[$job_id] = $mut_job;
+                                } else {
+                                    $jobs[$idx($job_id)] = $mut_job;
+                                }
+                            }
+                        }
+                    }
+                } else {
+                    // multiplicate all jobs for each value
+                    if (!$jobs) {
+                        foreach ((array) $values as $val) {
+                            $jobs[$idx($id)][$key] = $val;
+                        }
+                    } else {
+                        foreach (array_keys($jobs) as $job_id) {
+                            foreach ((array) $values as $i => $val) {
+                                if ($i == 0) {
+                                    $jobs[$job_id][$key] = $val;
+                                } else {
+                                    $job_idx = $idx($job_id);
+                                    $jobs[$job_idx] = $jobs[$job_id];
+                                    $jobs[$job_idx][$key] = $val;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            $all_jobs[] = $jobs;
+        }
+        return array_merge(...$all_jobs);
+    }
+    function travis(array $matrix) {
+        $xpc = [];
+        foreach ($matrix as $id => $array) {
+            $apc = [];
+            foreach ($array as $key => $values) {
+                if (is_numeric($key) && is_string($values)) {
+                    // switch on yes/no
+                    $key = $values;
+                    $values = ["no", "yes"];
+                } else if (is_numeric($key) && is_array($values)) {
+                    // mutually enabled options
+                    $vpc = [];
+                    foreach ($values as $yes) {
+                        $mpc = "$yes=yes ";
+                        foreach ($values as $no) {
+                            if ($yes === $no) {
+                                continue;
+                            }
+                            $mpc .= "$no=no ";
+                        }
+                        $vpc[] = $mpc;
+                    }
+                    $key = null;
+                    $values = $vpc;
+                }
 
-                       if (empty($apc)) {
-                               // seed
-                               foreach ((array) $values as $val) {
-                                       $apc[] = strlen($key) ? "$key=$val" : $val;
-                               }
-                       } else {
-                               // combine
-                               $cpc = $apc;
-                               $apc = [];
-                               foreach ((array) $values as $val) {
-                                       foreach ($cpc as $e) {
-                                               $apc[] = strlen($key) ? "$e $key=$val" : "$e $val";
-                                       }
-                               }
-                       }
-               }
-               $xpc[] = $apc;
-       }
-       return $xpc;
+                if (empty($apc)) {
+                    // seed
+                    foreach ((array) $values as $val) {
+                        $apc[] = strlen($key) ? "$key=$val" : $val;
+                    }
+                } else {
+                    // combine
+                    $cpc = $apc;
+                    $apc = [];
+                    foreach ((array) $values as $val) {
+                        foreach ($cpc as $e) {
+                            $apc[] = strlen($key) ? "$e $key=$val" : "$e $val";
+                        }
+                    }
+                }
+            }
+            $xpc[$id] = $apc;
+        }
+        return $xpc;
+    }
+    function __invoke(...$args) {
+        return $this->travis(...$args); // BC
+    }
 };