Skip to content

Commit

Permalink
Initial source code committed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkhode1 committed Sep 5, 2024
1 parent e23fcca commit cab9b39
Show file tree
Hide file tree
Showing 36 changed files with 9,553 additions and 2 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:
push:
branches: [ 1.x, 2.x ]
pull_request:
branches: [ 1.x, 2.x ]

permissions:
contents: read

jobs:

build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: "ubuntu-latest"
php: "7.4"
env: 'HIGHEST_LOWEST="update --prefer-lowest"'
coverage: "none"

steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
# Only report coverage once
coverage: ${{ matrix.coverage }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer -n ${HIGHEST_LOWEST-install} --prefer-dist -o

- name: Run test suite
if: matrix.coverage == 'none'
run: composer run-script test

- name: Run coverage
if: matrix.coverage == 'pcov'
run: composer run-script coverage

- name: Upload coverage results to Coveralls
if: matrix.coverage == 'pcov'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: composer run-script coveralls
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
.idea/
96 changes: 94 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,94 @@
# version-resolver
A PHP library for resolving version, supported releases etc. for Drupal Core, modules, themes, and other related projects.
[![CI](https://github.com/grasmash/yaml-expander/actions/workflows/php.yml/badge.svg)](https://github.com/vishalkhode1/version-resolver/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/vishalkhode1/version-resolver/badge.svg)](https://coveralls.io/github/vishalkhode1/version-resolver)

## Drupal Version Resolver PHP Library

The **Drupal Version Resolver Library** is a PHP library designed to help you
easily resolve Drupal project versions, supported releases, and retrieve all releases hosted
on [Drupal.org](https://www.drupal.org/). Whether you need to fetch release information for Drupal core or
contributed modules/themes, this library offers a simple API to access such data.

### Features
- Fetch supported releases for a given Drupal module or theme.
- Get all available releases for any Drupal project.
- Resolve different Drupal core versions, including the current version, development versions, and next minor versions.

### Requirements
- **PHP 7.4** and above.
- **Composer** for installation.
- Internet access to query data from drupal.org.

### Installation
To install this library, run below command:

```shell
composer require vkhode/version-resolver
```

### Example Usage
Here’s an example to retrieve the releases of a module hosted on Drupal.org:

```php
use Drupal\Tool\VersionResolver;

// Initialize the resolver with the project name.
$resolver = new VersionResolver('token');

// Get supported releases for the project.
$supported = $resolver->getSupportedReleases();

// Output format example:
[
"8.x-1.x" => [
"stable" => [
"name" => "token 8.x-1.15",
"version" => "8.x-1.15",
"tag" => "8.x-1.15",
"core_compatibility" => "^9.2 || ^10 || ^11"
],
"dev" => [
"name" => "token 8.x-1.x-dev",
"version" => "8.x-1.x-dev",
"tag" => "8.x-1.x",
"core_compatibility" => "^9.2 || ^10 || ^11"
]
]
]
```
#### Fetching All Releases
If you need to retrieve all releases (including older versions), you can do so with the following:

```php
$all = $resolver->getAllReleases();
```
**Note:** This method returns all releases, but it does not include projects compatible with Drupal Core 7.x and below.

#### Resolving Drupal Core Versions
The library also provides methods to resolve various types of Drupal core versions:

- **Current Stable**: Returns the current stable version (e.g., `10.3`).
- **Current Dev**: Returns the current development version (e.g., `10.3.x-dev`).
- **Next Minor**: Returns the next minor version (e.g., `11.0.0-rc1`).
- **Next Minor Dev**: Returns the next minor development version (e.g., `11.0.x-dev`) and so on.

Example usage:
```php
use Drupal\Tool\Drupal\Resolver\CoreVersionResolver;

$resolver = new CoreVersionResolver();

$currentVersion = $resolver->findCurrent();
$currentDevVersion = $resolver->findCurrentDev();
$nextMinorVersion = $resolver->findNextMinor();
$nextMinorDevVersion = $resolver->findNextMinorDev();
```

Example Output
```php
echo $currentVersion; // 10.3
echo $currentDevVersion; // 10.3.x-dev
echo $nextMinorVersion; // 11.0.0-rc1
echo $nextMinorDevVersion; // 11.0.x-dev
```

### Contact
If you have any questions or issues, feel free to open a GitHub issue or contact the maintainers directly.
70 changes: 70 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "vkhode/version-resolver",
"description": "A PHP library for resolving version, supported releases etc. for Drupal Core, modules, themes, and other related projects.",
"license": "MIT",
"keywords": [
"drupal",
"version resolver",
"php library",
"drupal tools"
],
"authors": [
{
"name": "Vishal Khode"
}
],
"homepage": "https://github.com/vishalkhode1/version-resolver",
"require": {
"php": "^7.4",
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^7.9"
},
"require-dev": {
"acquia/coding-standards": "^3.0",
"ergebnis/composer-normalize": "^2.43",
"php-coveralls/php-coveralls": "^2.7",
"php-parallel-lint/php-parallel-lint": "^1.4",
"phpro/grumphp": "^1.5",
"phpunit/phpunit": "^9"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"Drupal\\Tool\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Drupal\\Tool\\Tests\\": "tests/src/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"phpro/grumphp": true
},
"optimize-autoloader": true,
"sort-packages": true
},
"scripts": {
"cbf": "phpcbf",
"coverage": "php -d pcov.enabled=1 vendor/bin/phpunit tests/src --coverage-clover build/logs/clover.xml",
"coveralls": [
"php-coveralls -vvv"
],
"cs": "phpcs",
"lint": [
"find src -name '*.php' -print0 | xargs -0 -n1 php -l",
"find tests -name '*.php' -print0 | xargs -0 -n1 php -l"
],
"test": [
"@lint",
"@unit",
"@cs"
],
"unit": "phpunit"
}
}
Loading

0 comments on commit cab9b39

Please sign in to comment.