Skip to content
Merged
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
7 changes: 6 additions & 1 deletion .github/workflows/autorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ name: Automatic releases
on:
workflow_dispatch:
schedule:
- cron: '5 4 * */6 *'
- cron: '5 4 * */3 0'

permissions:
contents: write
pull-requests: write

jobs:
auto-release:
name: Auto release
runs-on: ubuntu-latest
steps:
- name: Releasing if there is something new...
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Based on code from https://andre.arko.net/2022/05/15/automatic-dependabot-merges/

name: "Merge updates"

on:
workflow_run:
workflows:
- "Tests and Checks"
types:
- "completed"
branches:
- "dependabot/**"

permissions:
contents: write
pull-requests: write

jobs:
merge:
name: "Merge"
runs-on: "ubuntu-latest"
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
github.actor == 'dependabot[bot]'
steps:
- name: "Approve pull request"
uses: "juliangruber/approve-pull-request-action@v2"
with:
github-token: "${{ secrets.IMPRESSBOT_TOKEN }}"
number: "${{ github.event.workflow_run.pull_requests[0].number }}"

- name: "Merge pull request"
uses: "actions/github-script@v8"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const pullRequest = context.payload.workflow_run.pull_requests[0]
const repository = context.repo
await github.rest.pulls.merge({
merge_method: "merge",
owner: repository.owner,
pull_number: pullRequest.number,
repo: repository.repo,
})
69 changes: 0 additions & 69 deletions .github/workflows/on-pull-request.yml

This file was deleted.

99 changes: 99 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Tests and Checks

on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
- ready_for_review

jobs:
php-matrix:
name: Resolve PHP matrix
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.php-matrix.outputs.versions }}

steps:
- name: Checkouting code...
uses: actions/checkout@v6
with:
sparse-checkout: composer.json
sparse-checkout-cone-mode: false

- name: Installing PHP...
uses: shivammathur/setup-php@2.37.0
with:
php-version: '8.4'
coverage: none
tools: composer:v2

- name: Create php-matrix composer file...
shell: bash
run: |
package_constraint=$(php -r 'echo json_decode(file_get_contents("composer.json"), true)["require"]["clean/phpdoc-md"];')
php_constraint=$(composer show clean/phpdoc-md "$package_constraint" --all --format=json | php -r '$pkg = json_decode(stream_get_contents(STDIN), true); echo $pkg["requires"]["php"];')
php -r 'file_put_contents("composer.php-matrix.json", json_encode(["require" => ["php" => $argv[1]]], JSON_UNESCAPED_SLASHES));' "$php_constraint"

- name: Generating PHP matrix...
id: php-matrix
uses: typisttech/php-matrix-action@v2
with:
composer-json: composer.php-matrix.json
source: php.net

test:
name: Test (PHP ${{ matrix.php }})
needs:
- php-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: true
max-parallel: 5
matrix:
php: ${{ fromJSON(needs.php-matrix.outputs.versions) }}

steps:
- name: Checkouting code...
uses: actions/checkout@v6

- name: Detecting Composer major...
id: composer-major
env:
PHP_VERSION: ${{ matrix.php }}
shell: bash
run: |
case "$PHP_VERSION" in
5.*|7.0|7.1|7.2|7.3)
echo "value=v1" >> "$GITHUB_OUTPUT"
;;
*)
echo "value=v2" >> "$GITHUB_OUTPUT"
;;
esac

- name: Skipping tests for Composer v1 runtimes...
if: ${{ steps.composer-major.outputs.value == 'v1' }}
run: echo "Skipping PHP ${{ matrix.php }} because Composer v1 is EOL and unsupported by Packagist."

- name: Installing PHP...
if: ${{ steps.composer-major.outputs.value == 'v2' }}
uses: shivammathur/setup-php@2.37.0
with:
php-version: ${{ matrix.php }}
extensions: curl, gd, json, mbstring, pcre, session
coverage: none
tools: composer:v2

- name: Setup BATS
if: ${{ steps.composer-major.outputs.value == 'v2' }}
uses: mig4/setup-bats@v1
with:
bats-version: 1.8.2

- name: Test
if: ${{ steps.composer-major.outputs.value == 'v2' }}
run: bats tests
15 changes: 13 additions & 2 deletions bin/add-composer-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

COMPOSER_MAJOR=$(
composer --version 2>/dev/null | sed -nE 's/.* ([0-9]+)\..*/\1/p' | head -n 1
)

# Composer v1 does not support --ignore-platform-req=..., only --ignore-platform-reqs.
# To avoid pulling PHP-incompatible packages, skip platform ignore flags on Composer v1.
PLATFORM_FLAGS=""
if [ "$COMPOSER_MAJOR" != "1" ]; then
PLATFORM_FLAGS="--ignore-platform-req=ext-* --ignore-platform-req=lib-*"
fi

CURRENT_CMD=$(
cat <<EOF
composer require \
$("$SCRIPT_DIR"/get-composer-dependencies.php) \
--no-plugins \
--ignore-platform-reqs \
$PLATFORM_FLAGS \
--no-scripts \
--working-dir=$COPY_DATA_PATH
EOF
);

$CURRENT_CMD
$CURRENT_CMD
11 changes: 10 additions & 1 deletion bin/get-composer-dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@

$packages = [];
foreach ($composer['require'] as $package => $version) {
if (
$package === 'php' ||
strpos($package, 'ext-') === 0 ||
strpos($package, 'lib-') === 0 ||
strpos($package, 'composer-') === 0
) {
continue;
}

$packages[] = $package . "=" . $version;
}

echo implode(" ", $packages);
echo implode(" ", $packages);
4 changes: 2 additions & 2 deletions tests/06-add-composer-packages.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ setup() {
export COPY_DATA_PATH=$(mktemp -d)

pushd "$COPY_DATA_PATH" > /dev/null
git clone --no-tags --quiet https://github.com/imponeer/log-data-output-decorator.git .
git clone --branch v1.0.5 --depth 1 --quiet https://github.com/imponeer/log-data-output-decorator.git .
ls -la
popd > /dev/null
}
Expand All @@ -15,4 +15,4 @@ tear() {

@test "Adding packages for generation docs" {
$BATS_TEST_DIRNAME/../bin/add-composer-packages.sh
}
}
4 changes: 2 additions & 2 deletions tests/07-generate-docs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Imponeer\\ToArrayInterface
EOL

pushd "$COPY_DATA_PATH"
git clone --no-tags --quiet https://github.com/imponeer/toarray-interface.git .
git clone --branch v2.0.7 --depth 1 --quiet https://github.com/imponeer/toarray-interface.git .
popd

$BATS_TEST_DIRNAME/../bin/generate-config.php \
Expand All @@ -37,4 +37,4 @@ tear_file() {

@test "Generating produced some files" {
[ -s "$DOCS_PATH" ]
}
}
Loading