Skip to content

Commit 199f563

Browse files
alongoszSteveb-p
andauthored
[Composer Install] Created a composite Ibexa composer-install action (#72)
For more details see #72 Key changes: * [GHA][Composer Install] Created a script to process dependencies.json * [GHA][Composer Install] Created a composite action * [GHA][Composer Install] Added conditional checks for Satis keys * [GHA][Composer Install] Implemented handling of `shouldBeAddedAsVCS` * [GHA][Composer Install] Improved debugging output * [GHA][Composer Install] Called dependencies script using its absolute path * [GHA][Composer Install] Parametrized PHP extensions list --------- Co-Authored-By: Paweł Niedzielski <[email protected]>
1 parent cb3144d commit 199f563

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: "Configure tokens for private packages and install PHP Dependencies with Composer using optionally dependencies.json"
2+
author: 'Ibexa AS'
3+
description: >-
4+
Configures GitHub App tokens and installs PHP dependencies using Composer.
5+
If a dependencies.json file is present, it updates composer.json accordingly before installation.
6+
7+
inputs:
8+
gh-client-id:
9+
description: 'GitHub App ID'
10+
required: true
11+
gh-client-secret:
12+
description: 'GitHub App ID'
13+
required: true
14+
satis-network-key:
15+
description: 'Satis Network Key'
16+
required: false
17+
satis-network-token:
18+
description: 'Satis Network Token'
19+
required: false
20+
php-extensions:
21+
description: 'Comma-separated list of PHP extensions to install'
22+
required: false
23+
default: 'pdo_sqlite, gd'
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- uses: actions/create-github-app-token@v2
29+
id: generate_token
30+
with:
31+
app-id: ${{ inputs.gh-client-id }}
32+
private-key: ${{ inputs.gh-client-secret }}
33+
owner: ${{ github.repository_owner }}
34+
35+
- name: Setup PHP Action
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php }}
39+
coverage: none
40+
extensions: ${{ inputs.php-extensions }}
41+
tools: cs2pr
42+
43+
- if: ${{ inputs.satis-network-key != '' && inputs.satis-network-token != '' }}
44+
name: Add composer keys for private packagist
45+
shell: bash
46+
run: composer config http-basic.updates.ibexa.co $SATIS_NETWORK_KEY $SATIS_NETWORK_TOKEN
47+
env:
48+
SATIS_NETWORK_KEY: ${{ inputs.satis-network-key }}
49+
SATIS_NETWORK_TOKEN: ${{ inputs.satis-network-token }}
50+
51+
- if: steps.generate_token.outputs.token != ''
52+
name: Add composer key for GitHub App
53+
shell: bash
54+
run: composer config github-oauth.github.com $GITHUB_TOKEN
55+
env:
56+
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
57+
58+
- name: 'Process dependencies.json and update composer.json'
59+
shell: bash
60+
run: |
61+
if [[ -f dependencies.json ]]
62+
then
63+
"${GITHUB_ACTION_PATH}/composer-replace-dependencies.bash" dependencies.json
64+
fi
65+
env:
66+
GITHUB_ACTION_PATH: ${{ github.action_path }}
67+
68+
- uses: ramsey/composer-install@v3
69+
with:
70+
dependency-versions: highest
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
dependencies_json=${1:-dependencies.json}
6+
composer_file=composer.json
7+
8+
# Process each package from dependencies.json
9+
while IFS= read -r package; do
10+
name=$(echo "$package" | jq -r '.package')
11+
requirement=$(echo "$package" | jq -r '.requirement')
12+
should_be_added_as_vcs=$(echo "$package" | jq -r '.shouldBeAddedAsVCS')
13+
14+
if jq -e ".require | has(\"$name\")" "$composer_file" >/dev/null
15+
then
16+
composer require --no-update "$name":"$requirement"
17+
echo "> Updated '$name' package requirement to '$requirement'"
18+
elif jq -e ".\"require-dev\" | has(\"$name\")" "$composer_file" >/dev/null
19+
then
20+
composer require --dev --no-update "$name":"$requirement"
21+
echo "> Updated '$name' dev package requirement to '$requirement'"
22+
else
23+
# Skip further processing for a dependency which is not a part of currently processed composer.json
24+
continue
25+
fi
26+
27+
if [[ $should_be_added_as_vcs == "true" ]] ; then
28+
repository_url=$(echo "$package" | jq -r '.repositoryUrl')
29+
echo ">> Configuring VCS repository $repository_url for $name"
30+
composer config repositories."$(uuidgen)" vcs "$repository_url"
31+
fi
32+
done < <(jq -c '.packages[]' "$dependencies_json")
33+
34+
echo "> Display updated composer.json for debugging"
35+
cat "$composer_file"

0 commit comments

Comments
 (0)