Skip to content

Commit

Permalink
Enhancement: Build phpunit-slow-test-detector.phar
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed May 30, 2023
1 parent 8a5bca1 commit 4d51a61
Show file tree
Hide file tree
Showing 18 changed files with 2,605 additions and 2,235 deletions.
1 change: 1 addition & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ branches:
checks:
- context: "Code Coverage (8.1, locked)"
- context: "Coding Standards (8.1, locked)"
- context: "Compile Phar (8.1, locked)"
- context: "Dependency Analysis (8.1, locked)"
- context: "Refactoring (8.1, locked)"
- context: "Security Analysis (8.1, locked)"
Expand Down
72 changes: 71 additions & 1 deletion .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,76 @@ jobs:
- name: "Run friendsofphp/php-cs-fixer"
run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --verbose"

compile-phar:
name: "Compile Phar"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "8.1"

dependencies:
- "locked"

env:
PHPUNIT_SLOW_TEST_DETECTOR_PHAR: ".build/phar/phpunit-slow-test-detector.phar"

steps:
- name: "Checkout"
uses: "actions/checkout@v3.5.2"

- name: "Set up PHP"
uses: "shivammathur/setup-php@2.25.2"
with:
coverage: "none"
extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter"
ini-values: "memory_limit=-1, phar.readonly=0"
php-version: "${{ matrix.php-version }}"
tools: "phive"

- name: "Set up problem matchers for PHP"
run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\""

- name: "Determine composer cache directory"
uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.8.0"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v3.3.1"
with:
path: "${{ env.COMPOSER_CACHE_DIR }}"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"

- name: "Install ${{ matrix.dependencies }} dependencies with composer"
uses: "ergebnis/.github/actions/composer/install@1.8.0"
with:
dependencies: "${{ matrix.dependencies }}"

- name: "Remove phpunit/phpunit"
run: "composer remove phpunit/phpunit --ansi --no-interaction --no-progress"

- name: "Remove git placeholder configuration with jq"
run: "echo $(cat box.json | jq 'del(.git)') > box.json"

- name: "Install dependencies with phive"
uses: "ergebnis/.github/actions/phive/install@1.8.0"
with:
trust-gpg-keys: "0x2DF45277AEF09A2F,0x033E5F8D801A2F8D,0x4AA394086372C20A"

- name: "Validate configuration for humbug/box"
run: ".phive/box validate box.json --ansi"

- name: "Compile phpunit-slow-test-detector.phar with humbug/box"
run: ".phive/box compile --ansi --config=box.json"

- name: "Show info about phpunit-slow-test-detector.phar with humbug/box"
run: ".phive/box info ${{ env.PHPUNIT_SLOW_TEST_DETECTOR_PHAR }} --ansi"

- name: "Run phar tests with phpunit/phpunit"
run: ".phive/phpunit --colors=always --configuration=test/Phar/phpunit.xml"

dependency-analysis:
name: "Dependency Analysis"

Expand Down Expand Up @@ -187,7 +257,7 @@ jobs:
- name: "Install dependencies with phive"
uses: "ergebnis/.github/actions/phive/install@1.8.0"
with:
trust-gpg-keys: "0x033E5F8D801A2F8D"
trust-gpg-keys: "0x2DF45277AEF09A2F,0x033E5F8D801A2F8D,0x4AA394086372C20A"

- name: "Run maglnet/composer-require-checker"
run: ".phive/composer-require-checker check --config-file=$(pwd)/composer-require-checker.json"
Expand Down
111 changes: 111 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,119 @@ jobs:

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "8.1"

dependencies:
- "locked"

env:
GPG_KEYS: ".build/phar/keys.asc"
GPG_KEYS_ENCRYPTED: "phar/keys.asc.gpg"
PHPUNIT_SLOW_TEST_DETECTOR_PHAR: ".build/phar/phpunit-slow-test-detector.phar"
PHPUNIT_SLOW_TEST_DETECTOR_PHAR_SIGNATURE: ".build/phar/phpunit-slow-test-detector.phar.asc"

steps:
- name: "Checkout"
uses: "actions/checkout@v3.5.2"

- name: "Set up PHP"
uses: "shivammathur/setup-php@2.25.2"
with:
coverage: "none"
extensions: "none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter"
php-version: "${{ matrix.php-version }}"
tools: "phive"

- name: "Determine composer cache directory"
uses: "ergebnis/.github/actions/composer/determine-cache-directory@1.8.0"

- name: "Cache dependencies installed with composer"
uses: "actions/cache@v3.3.1"
with:
path: "${{ env.COMPOSER_CACHE_DIR }}"
key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"

- name: "Install ${{ matrix.dependencies }} dependencies with composer"
uses: "ergebnis/.github/actions/composer/install@1.8.0"
with:
dependencies: "${{ matrix.dependencies }}"

- name: "Remove phpunit/phpunit"
run: "composer remove phpiunit/phpunit --ansi --no-interaction --no-progress"

- name: "Install dependencies with phive"
uses: "ergebnis/.github/actions/phive/install@1.8.0"
with:
trust-gpg-keys: "0x2DF45277AEF09A2F,0x033E5F8D801A2F8D,0x4AA394086372C20A"

- name: "Validate configuration for humbug/box"
run: ".phive/box validate box.json --ansi"

- name: "Compile phpunit-slow-test-detector.phar with humbug/box"
run: ".phive/box compile --ansi --config=box.json"

- name: "Show info about phpunit-slow-test-detector.phar with humbug/box"
run: ".phive/box info ${{ env.PHPUNIT_SLOW_TEST_DETECTOR_PHAR }} --ansi"

- name: "Run phar tests with phpunit/phpunit"
run: ".phive/phpunit --colors=always --configuration=test/Phar/phpunit.xml"

- name: "Show gpg version"
run: "gpg --version"

- name: "Decrypt keys.asc.gpg with gpg"
run: "gpg --batch --output ${{ env.GPG_KEYS }} --passphrase \"${{ secrets.GPG_DECRYPT_PASSPHRASE }}\" --yes --decrypt ${{ env.GPG_KEYS_ENCRYPTED }}"

- name: "Import keys from keys.asc with gpg"
run: "gpg --batch --import ${{ env.GPG_KEYS }}"

- name: "Sign phpunit-slow-test-detector.phar with gpg"
run: "gpg --armor --local-user \"${{ secrets.GPG_LOCAL_USER }}\" --output ${{ env.PHPUNIT_SLOW_TEST_DETECTOR_PHAR_SIGNATURE }} --passphrase \"${{ secrets.GPG_KEY_PASSPHRASE }}\" --pinentry-mode loopback --yes --detach-sig ${{ env.PHPUNIT_SLOW_TEST_DETECTOR_PHAR }}"

- name: "Remove decrypted keys.asc"
run: "rm ${{ env.GPG_KEYS }}"

- name: "Determine tag"
run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"

- name: "Create release"
uses: "ergebnis/.github/actions/github/release/create@1.8.0"
with:
github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}"

- name: "Upload release assets"
uses: "actions/github-script@v6.4.1"
with:
github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}"
script: |
const fs = require("fs");
const files = [
{
name: "phpunit-slow-test-detector.phar",
path: process.env.PHPUNIT_SLOW_TEST_DETECTOR_PHAR,
},
{
name: "phpunit-slow-test-detector.phar.asc",
path: process.env.PHPUNIT_SLOW_TEST_DETECTOR_PHAR_SIGNATURE,
},
];
for (const file of files) {
try {
await github.rest.repos.uploadReleaseAsset({
data: fs.readFileSync(file.path),
name: file.name,
origin: process.env.RELEASE_UPLOAD_URL,
owner: context.repo.owner,
release_id: process.env.RELEASE_ID,
repo: context.repo.repo,
});
} catch (error) {
core.setFailed(error.message);
}
}
2 changes: 2 additions & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="humbug/box" version="^4.3.8" installed="4.3.8" location="./.phive/box" copy="false"/>
<phar name="composer-require-checker" version="^4.5.0" installed="4.5.0" location="./.phive/composer-require-checker" copy="false"/>
<phar name="phpunit" version="^10.1.3" installed="10.1.3" location="./.phive/phpunit" copy="false"/>
</phive>
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ For a full diff see [`2.2.0...2.2.0`][2.1.1...2.2.0].

### Changed

- Added support for installing extension as a PHAR ([#273]), by [@localheinz]

### Changed

- Suggested and required `phpunit/phpunit` as a development dependency to allow usage with `phpunit/phpunit` when installed as PHAR ([#272]), by [@localheinz]

## [`2.1.1`][2.1.1]
Expand Down Expand Up @@ -129,5 +133,6 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
[#224]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/224
[#243]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/243
[#272]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/272
[#273]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/273

[@localheinz]: https://github.com/localheinz
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,19 @@ dependency-analysis: phive vendor ## Runs a dependency analysis with maglnet/com
help: ## Displays this list of targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: phar
phar: phive vendor ## Builds a phar with humbug/box
.phive/box validate box.json
composer remove phpunit/phpunit --no-interaction --no-progress
.phive/box compile --config=box.json
git checkout HEAD -- composer.json composer.lock
.phive/box info .build/phar/phpunit-slow-test-detector.phar
.phive/phpunit --configuration=test/Phar/phpunit.xml

.PHONY: phive
phive: .phive ## Installs dependencies with phive
mkdir -p .build/phive/
PHIVE_HOME=.build/phive phive install --trust-gpg-keys 0x033E5F8D801A2F8D
PHIVE_HOME=.build/phive phive install --trust-gpg-keys 0x2DF45277AEF09A2F,0x033E5F8D801A2F8D,0x4AA394086372C20A

.PHONY: refactoring
refactoring: vendor ## Runs automated refactoring with rector/rector
Expand Down
14 changes: 14 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://raw.githubusercontent.com/humbug/box/4.3.8/res/schema.json",
"compactors": [
"KevinGH\\Box\\Compactor\\Json",
"KevinGH\\Box\\Compactor\\Php"
],
"compression": "GZ",
"files": [
"manifest.xml"
],
"git": "git",
"main": "phar/phpunit-slow-test-detector.php",
"output": ".build/phar/phpunit-slow-test-detector.phar"
}
17 changes: 1 addition & 16 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
{
"symbol-whitelist": [
"PHPUnit\\Event\\Code\\Test",
"PHPUnit\\Event\\Telemetry\\Duration",
"PHPUnit\\Event\\Telemetry\\HRTime",
"PHPUnit\\Event\\Test\\Passed",
"PHPUnit\\Event\\Test\\PassedSubscriber",
"PHPUnit\\Event\\Test\\Prepared",
"PHPUnit\\Event\\Test\\PreparedSubscriber",
"PHPUnit\\Event\\TestRunner\\ExecutionFinished",
"PHPUnit\\Event\\TestRunner\\ExecutionFinishedSubscriber",
"PHPUnit\\Metadata\\Annotation\\Parser\\Registry",
"PHPUnit\\Runner\\Extension\\Extension",
"PHPUnit\\Runner\\Extension\\Facade",
"PHPUnit\\Runner\\Extension\\ParameterCollection",
"PHPUnit\\TextUI\\Configuration\\Configuration"
]
"symbol-whitelist": []
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
"source": "https://github.com/ergebnis/phpunit-slow-test-detector"
},
"require": {
"php": "~8.1.0 || ~8.2.0"
"php": "~8.1.0 || ~8.2.0",
"phpunit/phpunit": "^10.1.3"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.31.0",
"ergebnis/data-provider": "^1.3.0",
"ergebnis/license": "^2.1.0",
"ergebnis/php-cs-fixer-config": "^5.7.0",
"fakerphp/faker": "^1.22.0",
"phpunit/phpunit": "^10.0.1",
"psalm/plugin-phpunit": "~0.18.4",
"rector/rector": "~0.16.0",
"vimeo/psalm": "^5.12.0"
Expand Down
Loading

0 comments on commit 4d51a61

Please sign in to comment.