diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index 5e0b354..31b69a4 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -1,79 +1,25 @@ name: Shared - Continuous Integration for common tasks - on: workflow_call: - + outputs: + documentation-artifact-id: + description: Generated PHP API documentation. + value: ${{ jobs.documentation.outputs.artifact-id }} permissions: {} - jobs: checks: - runs-on: ubuntu-latest + uses: hoverkraft-tech/ci-github-php/.github/workflows/continuous-integration.yml@b81aa7b46f6b7a18ff1d9582c918cc1cc8296b98 # 2.0.0 permissions: contents: read id-token: write - strategy: - matrix: - include: - - php-versions: "8.2" - - php-versions: "8.3" - - php-versions: "8.4" - - php-versions: "8.5" - stable: true - steps: - - name: Checkout - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - - name: โš™๏ธ Setup PHP, with composer and extensions - uses: ./.github/workflows/actions/setup-php - with: - php-version: ${{ matrix.php-versions }} - - - name: โ™ป๏ธ Tools cache - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: tools/cache - key: ${{ runner.os }}-tools-${{ matrix.php-versions }}-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-tools- - - - name: ๐Ÿ‘• Lint - if: matrix.stable - run: composer php-cs-fixer -- --format=checkstyle | tools/vendor/bin/cs2pr - - - name: ๐Ÿ”ฌ Rector - id: rector - if: matrix.stable - run: composer rector - - - name: ๐Ÿ”ฌ Static analysis - if: matrix.stable - run: composer phpstan -- --error-format=github - - - name: โ™ป๏ธ Tests cache - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: tests/.phpunit.result.cache - key: ${{ runner.os }}-tests-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-tests- - - - name: โ™ป๏ธ Fixtures cache - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: .cache - key: fixture-cache-${{ hashFiles('composer.lock') }} - restore-keys: fixture-cache- - - - name: ๐Ÿ—‚๏ธ Load fixtures - run: composer test:load-fixtures - - - name: ๐Ÿงช Test - run: composer test:ci - - - name: ๐Ÿ“Š Upload coverage results to Codecov - if: matrix.stable - uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 - with: - files: ./build/logs/clover.xml + with: + ignore-plugins: false + test: '{"coverage":"codecov","cache":".cache"}' + package: | + { + "tests": "php-css-lint '.example { color: red; }'\nif php-css-lint '.example { unknown-property: invalid; }'; then\n echo 'Invalid CSS unexpectedly passed validation.' >&2\n exit 1\nfi" + } + documentation: + uses: hoverkraft-tech/ci-github-php/.github/workflows/documentation.yml@b81aa7b46f6b7a18ff1d9582c918cc1cc8296b98 # 2.0.0 + permissions: + contents: read diff --git a/.github/workflows/actions/setup-php/action.yml b/.github/workflows/actions/setup-php/action.yml deleted file mode 100644 index c677434..0000000 --- a/.github/workflows/actions/setup-php/action.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: "Setup PHP" -description: "A composite action to set up PHP with specified version and extensions" - -inputs: - php-version: - description: "The PHP version to install" - required: true - -runs: - using: "composite" - steps: - - name: โš™๏ธ Setup PHP, with composer and extensions - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 - with: - php-version: ${{ inputs.php-version }} - extensions: none,iconv,dom,curl,mbstring,tokenizer,xml,xmlwriter,simplexml,ctype - coverage: pcov - - - name: โ™ป๏ธ Get composer cache directory - id: composer-cache - shell: bash - run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - - - name: โ™ป๏ธ Cache composer dependencies - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ inputs.php-versions }}-${{ hashFiles('**/composer.json') }} - restore-keys: ${{ runner.os }}-composer- - - - name: โš™๏ธ Install dependencies - shell: bash - run: | - composer install --no-progress --prefer-dist --optimize-autoloader - composer --working-dir=tools install --no-progress --prefer-dist --optimize-autoloader diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 6c9366d..218b558 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -10,7 +10,7 @@ permissions: {} jobs: greetings: - uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@2334d395217f9811699dbd4ace9d8559e4d99e0d # 0.37.3 + uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0 permissions: contents: read issues: write diff --git a/.github/workflows/main-ci.yml b/.github/workflows/main-ci.yml index e390c9b..fb9e5a2 100644 --- a/.github/workflows/main-ci.yml +++ b/.github/workflows/main-ci.yml @@ -14,63 +14,39 @@ permissions: {} jobs: ci: name: Continuous Integration - uses: ./.github/workflows/__shared-ci.yml + uses: $/.github/workflows/__shared-ci.yml permissions: contents: read id-token: write secrets: inherit - docs-generate-phpdoc: - runs-on: ubuntu-latest - needs: ci - container: phpdoc/phpdoc:3 - env: - ARTIFACT_PATH: ./_site - outputs: - artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }} - artifact-path: ${{ env.ARTIFACT_PATH }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - - name: ๐Ÿ“ƒ Generate PHP documentation - run: phpdoc run -d ./src -t $ARTIFACT_PATH/phpdoc - - - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - id: upload-artifact - with: - name: docs-phpdoc - path: ${{ env.ARTIFACT_PATH }} - docs-publish: name: Publish documentation - needs: docs-generate-phpdoc + needs: ci runs-on: ubuntu-latest permissions: pages: write id-token: write environment: name: github-pages - url: ${{ steps.deployment.outputs.page_url }} + url: ${{ steps.deployment.outputs.url }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: - artifact-ids: ${{ needs.docs-generate-phpdoc.outputs.artifact-id }} - path: ${{ needs.docs-generate-phpdoc.outputs.artifact-path }} + artifact-ids: ${{ needs.ci.outputs.documentation-artifact-id }} + path: _site - - uses: hoverkraft-tech/ci-github-publish/actions/deploy/jekyll@ed354ada70b9f518c2bb663e18a80041c2cf5156 # 0.27.1 + - uses: hoverkraft-tech/ci-github-publish/actions/deploy/jekyll@4193622a365c0ab0bcbd6645895fd2c3126b72ba # 3.0.2 id: build with: - site-path: ${{ needs.docs-generate-phpdoc.outputs.artifact-path }} pages: | ./docs/*.md - - uses: hoverkraft-tech/ci-github-publish/actions/deploy/github-pages@ed354ada70b9f518c2bb663e18a80041c2cf5156 # 0.27.1 + - uses: hoverkraft-tech/ci-github-publish/actions/deploy/github-pages@4193622a365c0ab0bcbd6645895fd2c3126b72ba # 3.0.2 id: deployment with: build-path: ${{ steps.build.outputs.build-path }} diff --git a/.github/workflows/need-fix-to-issue.yml b/.github/workflows/need-fix-to-issue.yml index c46213d..188254a 100644 --- a/.github/workflows/need-fix-to-issue.yml +++ b/.github/workflows/need-fix-to-issue.yml @@ -17,7 +17,7 @@ permissions: {} jobs: main: - uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@0.37.3 + uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0 permissions: contents: read issues: write diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 12136b5..eb64cf5 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -1,21 +1,15 @@ ---- -name: "Prepare release" - +name: Prepare release on: - push: - branches: [main] pull_request: - types: [opened, reopened, synchronize] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - + types: + - opened + - reopened + - synchronize + - edited permissions: {} - jobs: - release: - uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@ed354ada70b9f518c2bb663e18a80041c2cf5156 # 0.27.1 + prepare-release: + uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@4193622a365c0ab0bcbd6645895fd2c3126b72ba # 3.0.2 permissions: contents: read pull-requests: write diff --git a/.github/workflows/pull-request-ci.yml b/.github/workflows/pull-request-ci.yml index d8cfcae..d483cc9 100644 --- a/.github/workflows/pull-request-ci.yml +++ b/.github/workflows/pull-request-ci.yml @@ -15,7 +15,7 @@ permissions: {} jobs: ci: name: Continuous Integration - uses: ./.github/workflows/__shared-ci.yml + uses: $/.github/workflows/__shared-ci.yml permissions: contents: read id-token: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3149b34 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: Release +on: + workflow_dispatch: + inputs: + force: + description: Release even when no relevant changes were detected. + type: boolean + default: false + schedule: + - cron: 37 7 * * 1 +permissions: {} +concurrency: + group: composer-release + cancel-in-progress: false +jobs: + prepare: + uses: hoverkraft-tech/ci-github-php/.github/workflows/prepare-package-release.yml@b81aa7b46f6b7a18ff1d9582c918cc1cc8296b98 # 2.0.0 + permissions: + contents: read + pull-requests: read + with: + force: ${{ github.event_name == 'workflow_dispatch' && inputs.force || false }} + release-config: &release-config | + tag-prefix: v + tag-template: v$RESOLVED_VERSION + name-template: v$RESOLVED_VERSION + validate: + needs: prepare + if: needs.prepare.outputs.status == 'ready' + uses: $/.github/workflows/__shared-ci.yml + permissions: + contents: read + id-token: write + publish: + needs: [prepare, validate] + uses: hoverkraft-tech/ci-github-php/.github/workflows/release.yml@b81aa7b46f6b7a18ff1d9582c918cc1cc8296b98 # 2.0.0 + permissions: + contents: write + pull-requests: read + with: + tag: ${{ needs.prepare.outputs.tag }} + release-config: *release-config + secrets: + changelog-summary: ${{ secrets.CHANGELOG_SUMMARY }} diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml index 71820a4..e387262 100644 --- a/.github/workflows/semantic-pull-request.yml +++ b/.github/workflows/semantic-pull-request.yml @@ -11,7 +11,6 @@ permissions: {} jobs: main: - uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@2334d395217f9811699dbd4ace9d8559e4d99e0d # 0.37.3 + uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0 permissions: - contents: write - pull-requests: write + contents: read diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 9e9814c..0cec0ee 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -8,7 +8,7 @@ permissions: {} jobs: main: - uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@0.37.3 + uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0 permissions: issues: write pull-requests: write diff --git a/.github/workflows/update-css-referential.yml b/.github/workflows/update-css-referential.yml index 6080949..df62961 100644 --- a/.github/workflows/update-css-referential.yml +++ b/.github/workflows/update-css-referential.yml @@ -20,15 +20,15 @@ jobs: persist-credentials: false - name: โš™๏ธ Setup PHP, with composer and extensions - uses: ./.github/workflows/actions/setup-php + uses: hoverkraft-tech/ci-github-php/actions/setup-php@b81aa7b46f6b7a18ff1d9582c918cc1cc8296b98 # 2.0.0 with: - php-version: 8.5 + ignore-plugins: "false" - name: Generate CSS Referential run: composer run-script generate-css-referentials - name: Push changes and create pull request - uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 + uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3 with: branch: update-css-referential add-paths: | diff --git a/.gitignore b/.gitignore index e39e1be..2b84387 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ composer.lock .cache tests/.phpunit.result.cache build/ +/junit.xml +/clover.xml diff --git a/Makefile b/Makefile index 786fb50..4aa6445 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ -PHP_VERSION=8.5 +PHP_VERSION ?= +PHP_IMAGE_TAG = $(if $(PHP_VERSION),$(PHP_VERSION),dev) PROJECT_NAME=$(shell basename $(CURDIR)) UID=$(shell id -u) GID=$(shell id -g) -IMAGE="${PROJECT_NAME}:${PHP_VERSION}" +IMAGE="${PROJECT_NAME}:$(PHP_IMAGE_TAG)" .PHONY: help @@ -11,9 +12,18 @@ help: setup: build-php install test-load-fixtures ## Initialize project -build-php: ## Build PHP image - @echo "Build php ${PHP_VERSION}" - @DOCKER_BUILDKIT=1 docker build -t "${IMAGE}" --build-arg "VERSION=${PHP_VERSION}" --build-arg "UID=${UID}" --build-arg "GID=${GID}" . +build-php: ## Build PHP image from the Composer constraint, or PHP_VERSION override + @set -eu; version="$(PHP_VERSION)"; \ + if [ -z "$$version" ]; then \ + workflow_ref=$$(grep -hE '^[[:space:]]*(-[[:space:]]*)?uses:' .github/workflows/*.y*ml | grep -oE 'hoverkraft-tech/ci-github-php/[^@[:space:]]+@[a-f0-9]{40}' | cut -d@ -f2 | sort -u); \ + if [ "$${#workflow_ref}" -ne 40 ]; then \ + echo 'Expected one consistent ci-github-php commit pin in .github/workflows.' >&2; exit 1; \ + fi; \ + resolver=$$(docker build --quiet "https://github.com/hoverkraft-tech/ci-github-php.git#$$workflow_ref:actions/get-php-versions"); \ + version=$$(docker run --rm --volume "$(CURDIR):/project:ro" "$$resolver"); \ + fi; \ + echo "Build PHP $$version"; \ + DOCKER_BUILDKIT=1 docker build -t "${IMAGE}" --build-arg "VERSION=$$version" --build-arg "UID=${UID}" --build-arg "GID=${GID}" . install: ## Install PHP dependencies for given PHP version rm -f composer.lock diff --git a/composer.json b/composer.json index 370f462..1cdcecb 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,10 @@ "php scripts/css-referential-scraper", "php scripts/css-popular-downloader" ], - "test:ci": "@test -d pcov.enabled=1 -d max_execution_time=0 --coverage-text --coverage-clover ./build/logs/clover.xml --coverage-html ./build/coverage/", + "test:ci": [ + "@test:load-fixtures", + "@test --log-junit=junit.xml --coverage-clover=clover.xml" + ], "php-cs-fixer": "@php-cs-fixer:fix --dry-run", "php-cs-fixer:fix": "tools/vendor/bin/php-cs-fixer fix --show-progress=dots --diff --config=.php-cs-fixer.dist.php", "rector": "@rector:fix --dry-run", @@ -78,6 +81,11 @@ "@rector", "@phpstan", "@test:ci" + ], + "lint:ci": [ + "@php-cs-fixer", + "@rector", + "@phpstan --error-format=github" ] }, "config": { diff --git a/docs/development.md b/docs/development.md index 23ee35e..3a6d8b6 100644 --- a/docs/development.md +++ b/docs/development.md @@ -2,7 +2,14 @@ ## Setup -_You can override default PHP version by setting `PHP_VERSION` as Makefile argument. Example: `make PHP_VERSION=8.2 setup`._ +Local builds select the highest stable PHP release allowed by `composer.json` using the +shared Hoverkraft resolver. Docker is the only runtime required on the host. The +resolver revision comes from the existing `ci-github-php` workflow pins, so dependency +updates also apply to local builds. A checkout with consistent workflow pins is required +for automatic selection. Override the selection with `make PHP_VERSION=8.2 setup`; use +the same override for later commands. Without an override, commands use the local `dev` +image created by setup. Rebuild it to pick up newly available compatible releases. CI +automatically tests every compatible stable minor. ```sh make setup