Skip to content

Commit

Permalink
Merge pull request #52 from WyriHaximus/update-ci-workflow-to-latest-gen
Browse files Browse the repository at this point in the history
Update CI workflow to latest generation
  • Loading branch information
WyriHaximus committed Aug 8, 2022
2 parents 0374d38 + 866d4e5 commit 52dc93b
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
@@ -1 +1 @@
github: WyriHaximus
github: WyriHaximus
194 changes: 145 additions & 49 deletions .github/workflows/ci.yml
@@ -1,84 +1,180 @@
name: Continuous Integration
on:
push:
branches:
- 'main'
- 'master'
- 'refs/heads/v[0-9]+.[0-9]+.[0-9]+'
pull_request:
jobs:
generate-checks-strategy:
name: Generate Checks
package-name:
name: Package Name
runs-on: ubuntu-latest
needs:
- lint-json
outputs:
package-name: ${{ steps.package-name.outputs.package-name }}
steps:
- uses: actions/checkout@v3
- id: package-name
run: |
printf "::set-output name=package-name::[\"%s\"]" $(docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.name' "${GITHUB_WORKSPACE}/composer.json")
supported-versions-matrix:
name: Supported Versions Matrix
runs-on: ubuntu-latest
needs:
- lint-yaml
- lint-json
outputs:
version: ${{ steps.supported-versions-matrix.outputs.version }}
upcoming: ${{ steps.supported-versions-matrix.outputs.upcoming }}
steps:
- uses: actions/checkout@v3
- id: supported-versions-matrix
uses: WyriHaximus/github-action-composer-php-versions-in-range@v1
with:
upcomingReleases: true
supported-checks-matrix:
name: Supported Checks Matrix
runs-on: ubuntu-latest
needs:
- lint-yaml
outputs:
check: ${{ steps.generate-checks-strategy.outputs.check }}
check: ${{ steps.supported-checks-matrix.outputs.check }}
steps:
- uses: actions/checkout@v1
- id: generate-checks-strategy
- uses: actions/checkout@v3
- id: supported-checks-matrix
name: Generate check
run: |
printf "Checks found: %s\r\n" $(make task-list-ci)
printf "::set-output name=check::%s" $(make task-list-ci)
lint:
runs-on: ubuntu-latest
steps:
- name: Lint Code Base
uses: docker://github/super-linter:v2.2.0
composer-install:
can-require:
name: Test we can require "${{ matrix.package-name }}" on PHP ${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ["8.0", 8.1]
composer: [lowest, current, highest]
needs: lint
php: ${{ fromJson(needs.supported-versions-matrix.outputs.version) }}
package-name: ${{ fromJson(needs.package-name.outputs.package-name) }}
needs:
- lint-yaml
- lint-json
- package-name
- supported-versions-matrix
runs-on: ubuntu-latest
container:
image: ghcr.io/wyrihaximusnet/php:${{ matrix.php }}-nts-alpine-dev-root
image: ghcr.io/wyrihaximusnet/php:${{ matrix.php }}-nts-buster-dev-root
steps:
- uses: actions/checkout@v1
- name: Cache composer packages
uses: actions/cache@v1
- uses: actions/checkout@v2
with:
path: ./vendor/
key: ${{ matrix.composer }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
- name: Install Dependencies
run: composer update --prefer-lowest --no-progress --ansi --no-interaction --prefer-dist -o
if: matrix.composer == 'lowest'
- name: Install Dependencies
run: composer install --ansi --no-progress --no-interaction --prefer-dist -o
if: matrix.composer == 'current'
- name: Install Dependencies
run: composer update --ansi --no-progress --no-interaction --prefer-dist -o
if: matrix.composer == 'highest'
path: checked_out_package
- name: Set Up composer.json
run: |
echo "{\"repositories\": [{\"name\": \"${{ matrix.package-name }}\",\"type\": \"path\",\"url\": \"./checked_out_package\"}]}" > composer.json
- name: Require package
if: needs.supported-versions-matrix.outputs.upcoming != matrix.php
run: |
composer require "${{ matrix.package-name }}:dev-${GITHUB_SHA}" --no-progress --ansi --no-interaction --prefer-dist -o || composer require "${{ matrix.package-name }}:dev-${GITHUB_REF_NAME}" --no-progress --ansi --no-interaction --prefer-dist -o
qa:
name: Run ${{ matrix.check }} on PHP ${{ matrix.php }} with ${{ matrix.composer }} dependency preference
strategy:
fail-fast: false
matrix:
php: ["8.0", 8.1]
composer: [lowest, current, highest]
check: ${{ fromJson(needs.generate-checks-strategy.outputs.check) }}
php: ${{ fromJson(needs.supported-versions-matrix.outputs.version) }}
composer: [lowest, locked, highest]
check: ${{ fromJson(needs.supported-checks-matrix.outputs.check) }}
needs:
- composer-install
- generate-checks-strategy
- lint-yaml
- lint-json
- supported-checks-matrix
- supported-versions-matrix
runs-on: ubuntu-latest
container:
image: ghcr.io/wyrihaximusnet/php:${{ matrix.php }}-nts-alpine-dev-root
image: ghcr.io/wyrihaximusnet/php:${{ matrix.php }}-nts-buster-dev-root
steps:
- uses: actions/checkout@v1
- name: Cache composer packages
uses: actions/cache@v1
- uses: actions/checkout@v3
- uses: ramsey/composer-install@v2
with:
path: ./vendor/
key: ${{ matrix.composer }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
- name: Install Dependencies
run: (test -f vendor && true ) || composer update --prefer-lowest --no-progress --ansi --no-interaction --prefer-dist -o
if: matrix.composer == 'lowest'
- name: Install Dependencies
run: (test -f vendor && true ) || composer install --ansi --no-progress --no-interaction --prefer-dist -o
if: matrix.composer == 'current'
- name: Install Dependencies
run: (test -f vendor && true ) || composer update --ansi --no-progress --no-interaction --prefer-dist -o
if: matrix.composer == 'highest'
dependency-versions: ${{ matrix.composer }}
- name: Fetch Tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
if: matrix.check == 'backward-compatibility-check'
- run: make ${{ matrix.check }} || true
if: needs.supported-versions-matrix.outputs.upcoming == matrix.php
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_RUN_LOCALLY: ${{ secrets.COVERALLS_RUN_LOCALLY }}
- run: make ${{ matrix.check }}
if: needs.supported-versions-matrix.outputs.upcoming != matrix.php
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_RUN_LOCALLY: ${{ secrets.COVERALLS_RUN_LOCALLY }}
tests-directly-on-os:
name: Run tests on PHP ${{ matrix.php }} with ${{ matrix.composer }} dependency preference (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
php: ${{ fromJson(needs.supported-versions-matrix.outputs.version) }}
composer: [lowest, locked, highest]
needs:
- lint-yaml
- lint-json
- supported-checks-matrix
- supported-versions-matrix
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: pcov
extensions: intl, sodium
- uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.composer }}
- run: make unit-testing-raw || true
if: needs.supported-versions-matrix.outputs.upcoming == matrix.php
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_RUN_LOCALLY: ${{ secrets.COVERALLS_RUN_LOCALLY }}
- run: make unit-testing-raw
if: needs.supported-versions-matrix.outputs.upcoming != matrix.php
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_RUN_LOCALLY: ${{ secrets.COVERALLS_RUN_LOCALLY }}
lint-yaml:
name: Lint YAML
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
with:
config_data: |
extends: default
ignore: |
/.git/
rules:
line-length: disable
document-start: disable
truthy: disable
lint-json:
name: Lint JSON
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"
check-mark:
name: ✔️
needs:
- lint-yaml
- lint-json
- can-require
- qa
- tests-directly-on-os
runs-on: ubuntu-latest
steps:
- run: echo "✔️"
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
etc/qa/.phpunit.result.cache
var/*
!var/.gitkeep
vendor/
etc/qa/.phpunit.result.cache
53 changes: 36 additions & 17 deletions Makefile
Expand Up @@ -3,26 +3,32 @@ SHELL=bash

.PHONY: *

DOCKER_CGROUP:=$(shell cat /proc/1/cgroup | grep docker | wc -l)
COMPOSER_CACHE_DIR:=$(shell composer config --global cache-dir -q || echo ${HOME}/.composer/cache)

ifneq ("$(wildcard /.dockerenv)","")
IN_DOCKER:=TRUE
else ifneq ("$(DOCKER_CGROUP)","0")
IN_DOCKER:=TRUE
COMPOSER_SHOW_EXTENSION_LIST=$(shell composer show -t | grep -o "\-\-\(ext-\).\+" | sort | uniq | cut -d- -f4- | tr -d '\n' | grep . | sed '/^$$/d' | xargs | sed -e 's/ /, /g' | tr -cd '[:alnum:],' | sed 's/.$$//')
SLIM_DOCKER_IMAGE=$(shell php -r 'echo count(array_intersect(["gd", "vips"], explode(",", "${COMPOSER_SHOW_EXTENSION_LIST}"))) > 0 ? "" : "-slim";')
COMPOSER_CACHE_DIR=$(shell composer config --global cache-dir -q || echo ${HOME}/.composer-php/cache)
PHP_VERSION:=$(shell docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.config.platform.php' "`pwd`/composer.json" | php -r "echo str_replace('|', '.', explode('.', implode('|', explode('.', stream_get_contents(STDIN), 2)), 2)[0]);")
COMPOSER_CONTAINER_CACHE_DIR=$(shell docker run --rm -it "ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine${SLIM_DOCKER_IMAGE}-dev" composer config --global cache-dir -q || echo ${HOME}/.composer-php/cache)

ifneq ("$(wildcard /.you-are-in-a-wyrihaximus.net-php-docker-image)","")
IN_DOCKER=TRUE
else
IN_DOCKER:=FALSE
IN_DOCKER=FALSE
endif

ifeq ("$(IN_DOCKER)","TRUE")
DOCKER_RUN:=
else
PHP_VERSION:=$(shell docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.config.platform.php' "`pwd`/composer.json" | php -r "echo str_replace('|', '.', explode('.', implode('|', explode('.', stream_get_contents(STDIN), 2)), 2)[0]);")
DOCKER_RUN:=docker run --rm -it \
-v "`pwd`:`pwd`" \
-v "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache" \
-v "${COMPOSER_CACHE_DIR}:${COMPOSER_CONTAINER_CACHE_DIR}" \
-w "`pwd`" \
"ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine-dev"
"ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine${SLIM_DOCKER_IMAGE}-dev"
endif

ifneq (,$(findstring icrosoft,$(shell cat /proc/version)))
THREADS=1
else
THREADS=$(shell nproc)
endif

all: ## Runs everything ###
Expand All @@ -32,32 +38,45 @@ syntax-php: ## Lint PHP syntax
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .

cs-fix: ## Fix any automatically fixable code style issues
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml -vvvv

cs: ## Check the code for code style issues
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(shell nproc) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml

stan: ## Run static analysis (PHPStan)
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c ./etc/qa/phpstan.neon

psalm: ## Run static analysis (Psalm)
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats --config=./psalm.xml
$(DOCKER_RUN) vendor/bin/psalm --threads=$(THREADS) --shepherd --stats --config=./etc/qa/psalm.xml

unit-testing: ## Run tests
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
$(DOCKER_RUN) test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true

unit-testing-raw: ## Run tests ###
php vendor/phpunit/phpunit/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && ./vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true

mutation-testing: ## Run mutation testing
$(DOCKER_RUN) vendor/bin/roave-infection-static-analysis-plugin --ansi --min-msi=100 --min-covered-msi=100 --threads=$(shell nproc) --ignore-msi-with-no-mutations
$(DOCKER_RUN) vendor/bin/roave-infection-static-analysis-plugin --ansi --log-verbosity=all --threads=$(THREADS) --psalm-config etc/qa/psalm.xml || (cat ./var/infection.log && false)

mutation-testing-raw: ## Run mutation testing ###
php vendor/roave/infection-static-analysis-plugin/bin/roave-infection-static-analysis-plugin --ansi --log-verbosity=all --threads=$(THREADS) --psalm-config etc/qa/psalm.xml || (cat ./var/infection.log && false)

composer-require-checker: ## Ensure we require every package used in this package directly
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=./etc/qa/composer-require-checker.json

composer-unused: ## Ensure we don't require any package we don't use in this package directly
$(DOCKER_RUN) composer unused --ansi
$(DOCKER_RUN) vendor/bin/composer-unused --ansi

composer-install: ## Install dependencies
$(DOCKER_RUN) composer install --no-progress --ansi --no-interaction --prefer-dist -o

backward-compatibility-check: ## Check code for backwards incompatible changes
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true
$(MAKE) backward-compatibility-check-raw || true

backward-compatibility-check-raw: ## Check code for backwards incompatible changes, doesn't ignore the failure ###
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check

shell: ## Provides Shell access in the expected environment ###
$(DOCKER_RUN) ash
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Expand Up @@ -9,16 +9,16 @@
}
],
"require": {
"php": "^8",
"php": "^8.1",
"ext-json": "*",
"api-clients/rx": "^2.2",
"evenement/evenement": "^3.0",
"react/promise": "^2.7",
"react/stream": "^1.1.0",
"reactivex/rxphp": "^2.0",
"thecodingmachine/safe": "^1.3"
},
"require-dev": {
"api-clients/rx": "^2.2",
"react/promise-stream": "^1.2",
"wyrihaximus/async-test-utilities": "^4.2 || ^5.0",
"wyrihaximus/ticking-promise": "^3"
Expand All @@ -39,10 +39,12 @@
"infection/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"icanhazstring/composer-unused": true,
"ergebnis/composer-normalize": true
"ergebnis/composer-normalize": true,
"ocramius/package-versions": true,
"localheinz/composer-normalize": true
},
"platform": {
"php": "8.0.12"
"php": "8.1.12"
},
"sort-packages": true
},
Expand Down

0 comments on commit 52dc93b

Please sign in to comment.