Skip to content

Commit

Permalink
wip: composer update bash
Browse files Browse the repository at this point in the history
  • Loading branch information
arzola committed May 14, 2024
1 parent df6e44f commit 4abdf3b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/composer-update.yml
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 }}
4 changes: 2 additions & 2 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ jobs:
run: gh release upload ${{ steps.release.outputs.tag_name }} ${{github.workspace}}/$GITHUB_REPO_SLUG-$GITHUB_TAG.zip --clobber
- name: Trigger staging bedrock updates
if: ${{ steps.release.outputs.release_created }}
uses: pressbooks/composer-autoupdate-bedrock@feat/trigger-after-release
uses: pressbooks/composer-autoupdate-bedrock@feat/add-tag-in-sns-message
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_SNS_ARN_DEV: ${{ secrets.AWS_SNS_ARN_DEV }}
AWS_SNS_ARN_STAGING: ${{ secrets.AWS_SNS_ARN_STAGING }}
INPUT_TRIGGERED_BY: ${{ github.repository }}
BRANCH: ${{ steps.release.outputs.tag_name }}
REF: ${{ steps.release.outputs.tag_name }}

0 comments on commit 4abdf3b

Please sign in to comment.