From 37eb5501060040441a8070a0a6c74c95ec2aed21 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 12 Jan 2021 15:52:51 +0100 Subject: [PATCH] support for github workflow steps --- .editorconfig | 19 +++++ Makefile | 27 +++++--- README.md | 14 ++-- gen-matrix.php | 184 +++++++++++++++++++++++++++++++++++++------------ 4 files changed, 184 insertions(+), 60 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5e99128 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/Makefile b/Makefile index 4a903a8..e417b52 100644 --- 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: diff --git a/README.md b/README.md index 45c4c60..64187d5 100644 --- 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: $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 + } }; -- 2.30.2