-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters