Skip to content
Closed

Dev #12

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 17 additions & 25 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ jobs:
php-version: '8.2'
tools: composer:v2

- name: Update composer.json version
if: contains(fromJSON('["composer.json", "package.json"]'), 'composer.json')
run: |
if [ -f composer.json ]; then
jq '.version = "${{ steps.version.outputs.version_number }}"' composer.json > composer.tmp.json
mv composer.tmp.json composer.json
fi
# Skip composer.json version update - version tracked via git tags only
# This prevents merge conflicts between branches

- name: Update package.json version
if: contains(fromJSON('["package.json"]'), 'package.json')
Expand All @@ -77,16 +72,13 @@ jobs:
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"

if [ -f composer.json ]; then
git add composer.json
fi
# Only commit package.json updates if it exists
if [ -f package.json ]; then
git add package.json package-lock.json
fi

if ! git diff --cached --quiet; then
git commit -m "chore: bump version to ${{ steps.version.outputs.version_number }}"
git push origin HEAD:${{ github.ref_name }}
if ! git diff --cached --quiet; then
git commit -m "chore: bump version to ${{ steps.version.outputs.version_number }}"
git push origin HEAD:${{ github.ref_name }}
fi
fi

- name: Create and push tag
Expand Down Expand Up @@ -124,25 +116,25 @@ jobs:
OTHER=$(echo "$COMMITS" | grep -vE "^- (feat|feature|fix|bugfix|docs|documentation|style|formatting|refactor|refactoring|test|tests|chore|build|ci):" || true)

if [ -n "$FEATURES" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### 🚀 Features"$'\n'"$FEATURES"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Features"$'\n'"$FEATURES"$'\n'
fi
if [ -n "$FIXES" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### 🐛 Bug Fixes"$'\n'"$FIXES"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Bug Fixes"$'\n'"$FIXES"$'\n'
fi
if [ -n "$DOCS" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### 📚 Documentation"$'\n'"$DOCS"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Documentation"$'\n'"$DOCS"$'\n'
fi
if [ -n "$REFACTOR" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### ♻️ Refactoring"$'\n'"$REFACTOR"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Refactoring"$'\n'"$REFACTOR"$'\n'
fi
if [ -n "$TEST" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### Tests"$'\n'"$TEST"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Tests"$'\n'"$TEST"$'\n'
fi
if [ -n "$CHORE" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### 🔧 Maintenance"$'\n'"$CHORE"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Maintenance"$'\n'"$CHORE"$'\n'
fi
if [ -n "$OTHER" ]; then
CHANGELOG="$CHANGELOG"$'\n'"### 📦 Other Changes"$'\n'"$OTHER"$'\n'
CHANGELOG="$CHANGELOG"$'\n'"### Other Changes"$'\n'"$OTHER"$'\n'
fi

CHANGELOG="$CHANGELOG"$'\n'"**Full Changelog**: "
Expand Down Expand Up @@ -196,7 +188,7 @@ jobs:
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.version }}
name: ${{ env.PACKAGE_DISPLAY_NAME }} ${{ steps.version.outputs.version }}
name: ${{ steps.version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ github.event.inputs.prerelease == 'true' }}
Expand All @@ -209,9 +201,9 @@ jobs:
- name: Release summary
if: success()
run: |
echo "Release created successfully!"
echo "Release created successfully!"
echo ""
echo "📦 To use this version in other packages:"
echo "To use this version in other packages:"
echo ""
echo " \"require\": {"
echo " \"${{ env.COMPOSER_NAMESPACE }}\": \"${{ steps.version.outputs.version_number }}\""
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4']

name: PHP ${{ matrix.php-version }}

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
tools: composer:v2

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Validate composer.json
run: composer validate --strict --no-check-lock

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction

- name: Security check for vulnerabilities
run: composer audit --no-dev

- name: Run PHPUnit tests
run: composer test

- name: Run PHPUnit with coverage
if: matrix.php-version == '8.2'
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

- name: Upload coverage to Codecov
if: matrix.php-version == '8.2'
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
fail_ci_if_error: false

- name: Run PHPCS coding standards check
if: matrix.php-version == '8.2'
run: composer lint

- name: Check PHP compatibility
if: matrix.php-version == '8.2'
run: composer phpcompat

test-status:
name: Test Status
runs-on: ubuntu-latest
needs: test
if: always()

steps:
- name: Check test results
run: |
if [ "${{ needs.test.result }}" == "success" ]; then
echo "✅ All tests passed!"
exit 0
else
echo "❌ Tests failed!"
exit 1
fi
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_component_is_singleton":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_init_registers_components":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_component_classes_registered":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_helper_is_singleton":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_init_registers_helpers":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_helper_classes_registered":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_utility_is_singleton":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_init_registers_utilities":4,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_utility_classes_registered":4},"times":{"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_component_is_singleton":0.001,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_init_registers_components":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_component_classes_registered":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_accessible_card_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_breadcrumbs_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_button_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_image_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_pagination_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_post_card_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\ComponentTest::test_post_feed_component_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_helper_is_singleton":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_init_registers_helpers":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_helper_classes_registered":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_escape_svg_helper_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_foreground_image_helper_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_section_background_helper_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\HelperTest::test_section_pattern_helper_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\Utilities\\ReadingTimeTest::test_calculate_reading_time_short_text":0.003,"BuiltNorth\\WPUtility\\Tests\\Unit\\Utilities\\ReadingTimeTest::test_calculate_reading_time_medium_text":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\Utilities\\ReadingTimeTest::test_calculate_reading_time_long_text":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\Utilities\\ReadingTimeTest::test_calculate_reading_time_with_html":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\Utilities\\ReadingTimeTest::test_calculate_reading_time_empty_content":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\Utilities\\ReadingTimeTest::test_calculate_reading_time_special_characters":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_utility_is_singleton":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_init_registers_utilities":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_utility_classes_registered":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_archive_url_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_country_list_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_get_terms_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_get_title_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_image_setup_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_lazy_load_first_block_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_reading_time_utility_exists":0,"BuiltNorth\\WPUtility\\Tests\\Unit\\UtilityTest::test_state_list_utility_exists":0}}
84 changes: 49 additions & 35 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
{
"name": "builtnorth/wp-utility",
"description": "Utility functions and helpers for WordPress development",
"type": "library",
"version": "2.1.0",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "BuiltNorth",
"email": "hello@builtnorth.co"
}
],
"require": {
"php": ">=8.1"
},
"autoload": {
"psr-4": {
"BuiltNorth\\WPUtility\\": "inc/"
}
},
"autoload-dev": {
"psr-4": {
"BuiltNorth\\WPUtility\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.0",
"phpcompatibility/php-compatibility": "^9.0"
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"minimum-stability": "stable",
"prefer-stable": true
"name": "builtnorth/wp-utility",
"description": "Utility functions and helpers for WordPress development",
"type": "library",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "BuiltNorth",
"email": "hello@builtnorth.co"
}
],
"require": {
"php": ">=8.1"
},
"autoload": {
"psr-4": {
"BuiltNorth\\WPUtility\\": "inc/"
}
},
"autoload-dev": {
"psr-4": {
"BuiltNorth\\WPUtility\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"10up/wp_mock": "^1.0",
"mockery/mockery": "^1.5",
"builtnorth/coding-standards": "*"
},
"scripts": {
"test": "phpunit",
"test:unit": "phpunit --testsuite Unit",
"test:coverage": "phpunit --coverage-html coverage",
"lint": "phpcs",
"lint:fix": "phpcbf",
"phpcs": "phpcs",
"phpcs:summary": "phpcs --report=summary",
"phpcbf": "phpcbf",
"phpcompat": "phpcs -p . --standard=PHPCompatibility --runtime-set testVersion 8.1-"
},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Loading
Loading