Skip to content

Commit 4abdf3b

Browse files
committed
wip: composer update bash
1 parent df6e44f commit 4abdf3b

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

.github/workflows/composer-update.yml

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

.github/workflows/prepare-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ jobs:
4444
run: gh release upload ${{ steps.release.outputs.tag_name }} ${{github.workspace}}/$GITHUB_REPO_SLUG-$GITHUB_TAG.zip --clobber
4545
- name: Trigger staging bedrock updates
4646
if: ${{ steps.release.outputs.release_created }}
47-
uses: pressbooks/composer-autoupdate-bedrock@feat/trigger-after-release
47+
uses: pressbooks/composer-autoupdate-bedrock@feat/add-tag-in-sns-message
4848
env:
4949
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
5050
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
5151
AWS_SNS_ARN_DEV: ${{ secrets.AWS_SNS_ARN_DEV }}
5252
AWS_SNS_ARN_STAGING: ${{ secrets.AWS_SNS_ARN_STAGING }}
5353
INPUT_TRIGGERED_BY: ${{ github.repository }}
54-
BRANCH: ${{ steps.release.outputs.tag_name }}
54+
REF: ${{ steps.release.outputs.tag_name }}

0 commit comments

Comments
 (0)