diff --git a/.editorconfig b/.editorconfig index f549ee8..2d3ea1f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,7 @@ indent_style = tab indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true + +[*.{css,json,scss,xml,yml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a91ed5b..38c721a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,49 +1,97 @@ name: Tests on: - pull_request: - branches: [main] - push: - branches: [main] + pull_request: + branches: [main] + push: + branches: [main] + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v5 - - - name: Install PHP 8.4 - uses: shivammathur/setup-php@v2 - with: - php-version: "8.4" - ini-values: date.timezone='UTC' - extensions: posix, dom, curl, libxml, mbstring, zip, pcntl, pdo, pgsql, pdo_pgsql, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: pcov - tools: composer:v2 - - - name: Add PHP symlink for php84 - run: sudo ln -s /usr/bin/php /usr/bin/php84 - - - name: Validate composer.json and composer.lock - run: composer validate --strict - - - name: Run PHP Lint - uses: overtrue/phplint@10.0 - with: - path: ./src - -# - name: Cache Composer packages -# uses: actions/cache@v3 -# with: -# path: vendor -# key: ${{ runner.os }}-php-${{ hashFiles('composer.lock') }} -# restore-keys: | -# ${{ runner.os }}-php- - - - name: Install dependencies - run: composer test-init - -# - name: Static analysis -# run: composer qa + version_check: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Read plugin version + id: current_version + shell: bash + run: | + set -euo pipefail + + MAIN_FILE="src/i-order-terms.php" + PLUGIN_VERSION=$(grep -Po "^\s*\*\s*Version:\s*\K[^\s]+" "$MAIN_FILE" | head -n1) + echo "Plugin version: $PLUGIN_VERSION" + echo "version=$PLUGIN_VERSION" >> $GITHUB_OUTPUT + + - name: Check plugin versions match + shell: bash + run: | + set -euo pipefail + + VERSION="${{ steps.current_version.outputs.version }}" + + CLASS_FILE="src/code/class-i-order-terms.php" + README_FILE="src/readme.txt" + CLASS_VER=$(grep -Po "const\s+PLUGIN_VERSION\s*=\s*'[^']+'" "$CLASS_FILE" | grep -Po "'\K[^']+(?=')") + README_VER=$(grep -Po "^\s*Stable tag:\s*\K[^\s]+" "$README_FILE" | head -n1) + + echo "Main plugin version: $VERSION" + echo "Class version: $CLASS_VER" + echo "Stable version: $README_VER" + + if [ -z "$VERSION" ] || [ -z "$CLASS_VER" ] || [ -z "$README_VER" ]; then + echo "Could not parse versions from files (v='$VERSION', class='$CLASS_VER', readme='$README_VER')." >&2 + exit 1 + fi + if [ "$VERSION" != "$CLASS_VER" ] || [ "$VERSION" != "$README_VER" ]; then + echo "Version mismatch: v=$VERSION, class=$CLASS_VER, readme=$README_VER" >&2 + exit 1 + fi + echo "All versions match!" + + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Install PHP 8.4 + uses: shivammathur/setup-php@v2 + with: + php-version: "8.4" + ini-values: date.timezone='UTC' + extensions: posix, dom, curl, libxml, mbstring, zip, pcntl, pdo, pgsql, pdo_pgsql, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: pcov + tools: composer:v2 + + - name: Add PHP symlink for php84 + run: sudo ln -s /usr/bin/php /usr/bin/php84 + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Run PHP Lint + uses: overtrue/phplint@10.0 + with: + path: ./src + + # - name: Cache Composer packages + # uses: actions/cache@v3 + # with: + # path: vendor + # key: ${{ runner.os }}-php-${{ hashFiles('composer.lock') }} + # restore-keys: | + # ${{ runner.os }}-php- + + - name: Install dependencies + run: composer test-init + + # - name: Static analysis + # run: composer qa