-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (68 loc) · 2.51 KB
/
composer-update.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Composer Update 🎵
on:
workflow_call:
inputs:
packages:
description: 'List of space seperated packages to be update. The packages can include a specific reference (ex: pressbooks/pressbooks pressbooks/pressbooks:1.0.1)'
workflow_dispatch:
inputs:
packages:
description: 'List of space seperated packages to be update. The packages can include a specific reference (ex: pressbooks/pressbooks pressbooks/pressbooks:1.0.1)'
:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_GITHUB_ACTIONS }}
PACKAGIST_TOKEN: ${{ secrets.PAT_COMPOSER_UPDATE }}
- name: Install PHP dependencies
run: |
export PATH="$HOME/.composer/vendor/bin:$PATH"
composer install --no-interaction
- name: Setup github config and create new branch
run: |
git config --global user.email "ops@pressbooks.com"
git config --global user.name "pressbooks-ops"
git checkout -b "dev-updated"
- name: Update packages
run: |
composer_info="$(composer info -D -N)"
counter_packages_updated=0
IFS=' ' read -r -a packages <<< "${{ github.event.inputs.packages }}"
for package in "${packages[@]}"; do
if [[ ! $composer_info =~ "${package%%:*}" ]]; then
echo "$package is not installed."
else
if [[ "$package" != .*/.*:.* ]]; then
composer update $package
else
composer remove --no-update $package
composer require --no-update $package
fi
if git diff --quiet; then
echo "No changes to commit."
else
git add .
git commit -m "Chore: upgrading $package"
counter_packages_updated=$((counter_packages_updated + 1))
echo "COUNTER_PACKAGES_UPDATED=$counter_packages_updated" >> $GITHUB_ENV
fi
fi
done
- name: Push changes and create pull request
run: |
if [ "$COUNTER_PACKAGES_UPDATED" -gt 0 ]; then
git push -u origin dev-updated
current_date=$(date +%Y-%m-%d)
gh pr create --base dev --head dev-updated --title "chore: Composer update with $COUNTER_PACKAGES_UPDATED changes" --body ""
fi
env:
GITHUB_TOKEN: ${{ secrets.PAT_FOR_GITHUB_ACTIONS }}