diff --git a/.github/workflows/composer-update.yml b/.github/workflows/composer-update.yml new file mode 100644 index 0000000..8496119 --- /dev/null +++ b/.github/workflows/composer-update.yml @@ -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 }} \ No newline at end of file diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index aee8ee3..ffefa30 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -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 }}