Skip to content

Commit 253575b

Browse files
authored
Merge pull request #76 from impresscms-dev/feat/workflows-like-evert-main
Rework workflows to mirror evert-action setup
2 parents 7e5cb4a + 6c7fbb4 commit 253575b

8 files changed

Lines changed: 177 additions & 77 deletions

.github/workflows/autorelease.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ name: Automatic releases
33
on:
44
workflow_dispatch:
55
schedule:
6-
- cron: '5 4 * */6 *'
6+
- cron: '5 4 * */3 0'
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
711

812
jobs:
913
auto-release:
14+
name: Auto release
1015
runs-on: ubuntu-latest
1116
steps:
1217
- name: Releasing if there is something new...

.github/workflows/dependabot.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Based on code from https://andre.arko.net/2022/05/15/automatic-dependabot-merges/
2+
3+
name: "Merge updates"
4+
5+
on:
6+
workflow_run:
7+
workflows:
8+
- "Tests and Checks"
9+
types:
10+
- "completed"
11+
branches:
12+
- "dependabot/**"
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
jobs:
19+
merge:
20+
name: "Merge"
21+
runs-on: "ubuntu-latest"
22+
if: >
23+
github.event.workflow_run.event == 'pull_request' &&
24+
github.event.workflow_run.conclusion == 'success' &&
25+
github.actor == 'dependabot[bot]'
26+
steps:
27+
- name: "Approve pull request"
28+
uses: "juliangruber/approve-pull-request-action@v2"
29+
with:
30+
github-token: "${{ secrets.IMPRESSBOT_TOKEN }}"
31+
number: "${{ github.event.workflow_run.pull_requests[0].number }}"
32+
33+
- name: "Merge pull request"
34+
uses: "actions/github-script@v8"
35+
with:
36+
github-token: "${{ secrets.GITHUB_TOKEN }}"
37+
script: |
38+
const pullRequest = context.payload.workflow_run.pull_requests[0]
39+
const repository = context.repo
40+
await github.rest.pulls.merge({
41+
merge_method: "merge",
42+
owner: repository.owner,
43+
pull_number: pullRequest.number,
44+
repo: repository.repo,
45+
})

.github/workflows/on-pull-request.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Tests and Checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
- ready_for_review
12+
13+
jobs:
14+
php-matrix:
15+
name: Resolve PHP matrix
16+
runs-on: ubuntu-latest
17+
outputs:
18+
versions: ${{ steps.php-matrix.outputs.versions }}
19+
20+
steps:
21+
- name: Checkouting code...
22+
uses: actions/checkout@v6
23+
with:
24+
sparse-checkout: composer.json
25+
sparse-checkout-cone-mode: false
26+
27+
- name: Installing PHP...
28+
uses: shivammathur/setup-php@2.37.0
29+
with:
30+
php-version: '8.4'
31+
coverage: none
32+
tools: composer:v2
33+
34+
- name: Create php-matrix composer file...
35+
shell: bash
36+
run: |
37+
package_constraint=$(php -r 'echo json_decode(file_get_contents("composer.json"), true)["require"]["clean/phpdoc-md"];')
38+
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"];')
39+
php -r 'file_put_contents("composer.php-matrix.json", json_encode(["require" => ["php" => $argv[1]]], JSON_UNESCAPED_SLASHES));' "$php_constraint"
40+
41+
- name: Generating PHP matrix...
42+
id: php-matrix
43+
uses: typisttech/php-matrix-action@v2
44+
with:
45+
composer-json: composer.php-matrix.json
46+
source: php.net
47+
48+
test:
49+
name: Test (PHP ${{ matrix.php }})
50+
needs:
51+
- php-matrix
52+
runs-on: ubuntu-latest
53+
strategy:
54+
fail-fast: true
55+
max-parallel: 5
56+
matrix:
57+
php: ${{ fromJSON(needs.php-matrix.outputs.versions) }}
58+
59+
steps:
60+
- name: Checkouting code...
61+
uses: actions/checkout@v6
62+
63+
- name: Detecting Composer major...
64+
id: composer-major
65+
env:
66+
PHP_VERSION: ${{ matrix.php }}
67+
shell: bash
68+
run: |
69+
case "$PHP_VERSION" in
70+
5.*|7.0|7.1|7.2|7.3)
71+
echo "value=v1" >> "$GITHUB_OUTPUT"
72+
;;
73+
*)
74+
echo "value=v2" >> "$GITHUB_OUTPUT"
75+
;;
76+
esac
77+
78+
- name: Skipping tests for Composer v1 runtimes...
79+
if: ${{ steps.composer-major.outputs.value == 'v1' }}
80+
run: echo "Skipping PHP ${{ matrix.php }} because Composer v1 is EOL and unsupported by Packagist."
81+
82+
- name: Installing PHP...
83+
if: ${{ steps.composer-major.outputs.value == 'v2' }}
84+
uses: shivammathur/setup-php@2.37.0
85+
with:
86+
php-version: ${{ matrix.php }}
87+
extensions: curl, gd, json, mbstring, pcre, session
88+
coverage: none
89+
tools: composer:v2
90+
91+
- name: Setup BATS
92+
if: ${{ steps.composer-major.outputs.value == 'v2' }}
93+
uses: mig4/setup-bats@v1
94+
with:
95+
bats-version: 1.8.2
96+
97+
- name: Test
98+
if: ${{ steps.composer-major.outputs.value == 'v2' }}
99+
run: bats tests

bin/add-composer-packages.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@ set -e
44

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

7+
COMPOSER_MAJOR=$(
8+
composer --version 2>/dev/null | sed -nE 's/.* ([0-9]+)\..*/\1/p' | head -n 1
9+
)
10+
11+
# Composer v1 does not support --ignore-platform-req=..., only --ignore-platform-reqs.
12+
# To avoid pulling PHP-incompatible packages, skip platform ignore flags on Composer v1.
13+
PLATFORM_FLAGS=""
14+
if [ "$COMPOSER_MAJOR" != "1" ]; then
15+
PLATFORM_FLAGS="--ignore-platform-req=ext-* --ignore-platform-req=lib-*"
16+
fi
17+
718
CURRENT_CMD=$(
819
cat <<EOF
920
composer require \
1021
$("$SCRIPT_DIR"/get-composer-dependencies.php) \
1122
--no-plugins \
12-
--ignore-platform-reqs \
23+
$PLATFORM_FLAGS \
1324
--no-scripts \
1425
--working-dir=$COPY_DATA_PATH
1526
EOF
1627
);
1728

18-
$CURRENT_CMD
29+
$CURRENT_CMD

bin/get-composer-dependencies.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66

77
$packages = [];
88
foreach ($composer['require'] as $package => $version) {
9+
if (
10+
$package === 'php' ||
11+
strpos($package, 'ext-') === 0 ||
12+
strpos($package, 'lib-') === 0 ||
13+
strpos($package, 'composer-') === 0
14+
) {
15+
continue;
16+
}
17+
918
$packages[] = $package . "=" . $version;
1019
}
1120

12-
echo implode(" ", $packages);
21+
echo implode(" ", $packages);

tests/06-add-composer-packages.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ setup() {
44
export COPY_DATA_PATH=$(mktemp -d)
55

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

1616
@test "Adding packages for generation docs" {
1717
$BATS_TEST_DIRNAME/../bin/add-composer-packages.sh
18-
}
18+
}

tests/07-generate-docs.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Imponeer\\ToArrayInterface
1313
EOL
1414

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

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

3838
@test "Generating produced some files" {
3939
[ -s "$DOCS_PATH" ]
40-
}
40+
}

0 commit comments

Comments
 (0)