Skip to content

KomodoHQ/composer-update-action

 
 

Repository files navigation

composer update action

update test Maintainability Test Coverage

The following GitHub Action will run composer update and create a pull request with the changes.

The application runs on top of Laravel Zero which is a micro-framework for console applications.

Reusable workflow version

https://github.com/kawax/composer-workflow

Version

Git branch PHP
7.3 7.3
7.4 7.4
8.2 8.2
8.3 8.3
master 8.1

To add new versions simply create a new branch with your desired PHP version and update the README.md file. You will need to update the Dockerfile and the composer.json file to reflect the new PHP version.

Please follow the naming convention for the branch name!

Note: Currently only PHP 7.3, 7.4, 8.2, 8.3 are supported with Composer version 2.

Usage

Create .github/workflows/update.yml

name: composer update

on:
  schedule:
    - cron: '0 0 * * *' #UTC

jobs:
  composer_update_job:
    runs-on: ubuntu-latest
    name: composer update
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: composer update action
        uses: kawax/composer-update-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

env

  • COMPOSER_PATH : Specify if using subdirectory. Where composer.json is located.
  • GIT_NAME : git user name
  • GIT_EMAIL : git email
  • APP_SINGLE_BRANCH : If set, the new functionality is enabled.
  • APP_SINGLE_BRANCH_POSTFIX : A postfix for the branch used for updates. Default value is "-updated". If the branch doesn't exist, a new branch will be created with the parent branch name plus the postfix, e.g. "master-updated".
  • APP_USE_MAINTENANCE_BRANCH_CONVENTION : Branches from your defined parent branch using a specific naming convention will be ignored. Naming convention is "maintenance/month-year", this overrides the single branch settings.
  • GIT_COMMIT_PREFIX : Add a prefix to the commit message and pull request title. E.g. "[UPDATE] "
  • COMPOSER_PACKAGES : Specify which packages should be updated. E.g. "typo3/cms-*". Setting this variable will also run Composer with the --with-dependencies argument.

Upgrade task

      - name: composer update action
        uses: kawax/composer-update-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          COMPOSER_PATH: /subdir
          GIT_NAME: cu
          GIT_EMAIL: cu@composer-update
          APP_SINGLE_BRANCH: 1
          APP_SINGLE_BRANCH_POSTFIX: -updated
          APP_USE_MAINTENANCE_BRANCH_CONVENTION: 1
          GIT_COMMIT_PREFIX: '[UPDATE] '
          COMPOSER_PACKAGES: 'typo3/cms-*'

Upgrade Action

This task requires a composer_update_allowlist.txt to exist in the composer path and a compatible set of packages with the action's PHP version

The value of the file need to be new line separated as seen:

e.g.

composer/installers
vlucas/phpdotenv
oscarotero/env
nesbot/carbon

The action will then update the packages in the composer_update_allowlist.txt file and create a PR with the changes.

name: composer update

# Allows manual workflow dispatch and runs on the 24th of every month
on:
    workflow_dispatch:
    schedule:
        - cron: '0 0 24 * *'

jobs:
    composer_update_job:
        runs-on: ubuntu-latest
        name: Composer Update
        permissions:
            contents: write
            pull-requests: write
        steps:
            - name: Checkout
              uses: actions/checkout@v3
            - name: Composer Update Action
              uses: KomodoHQ/composer-update-action@master
              env:
                GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
                COMPOSER_PATH: '/site' // e.g. /site, /;
                GIT_NAME: cu
                GIT_EMAIL: cu@composer-update
                APP_USE_MAINTENANCE_BRANCH_CONVENTION: 1 // e.g. maintenance/may-2024
                GIT_COMMIT_PREFIX: '[UPDATE] '

To avoid any permissions issues, it is important to allow contents and pull-requests permissions for the GITHUB_TOKEN. This can be done by adding the following to your workflow file:

        composer_update_job:
        runs-on: ubuntu-latest
        name: composer update
        permissions:
            contents: write
            pull-requests: write

Troubleshooting

Missing PHP extension

foo/bar 1.0.0 requires ext-XXX * -> the requested PHP extension XXX is missing from your system.

Configure platform in your composer.json.

  "config": {
    "platform": {
      "php": "7.2.0", 
      "ext-XXX": "1.0.0"
     }
  },

LICENCE

MIT

Languages

  • PHP 97.6%
  • Dockerfile 2.3%
  • Shell 0.1%