PHP-Prefixer GitHub Action v1 is Available

In December 2021, as part of the efforts to ease and automate the CI/CD pipelines, we published the GitHub Action for PHP-Prefixer v1, and it is now available on the GitHub marketplace.

The Action is the definitive implementation of the core integration scenario to connect your GitHub builds with your PHP namespace and scope prefixing process.

The GitHub Action has been revamped from the previous iteration. The new version has been completely re-written from scratch following these guidelines:

What is ‘GitHub Actions’?

GitHub Actions is a popular platform to automate software development workflows, like CI/CD built around the GitHub ecosystem.

You define the workflow using a YAML configuration file and store it in your Git repository. You can compose your automation with reusable building blocks called ‘Actions‘. You then execute the workflows in containers for a repeatable and reliable process.

GitHub organizes the available Actions on the GitHub marketplace. Below, you can find how a PHP-Prefixer Action looks on the Marketplace:

PHP-Prefixer Action on the GitHub marketplace

Getting started with GitHub Actions for PHP-Prefixer

To illustrate how to use the new GitHub Action for PHP-Prefixer, we updated the Hello Prefixed World plugin to automate the plugin prefixing.

The plugin has a call to the PHP Prefixer Build Action (.github/workflow/prefix.yml) that integrates the service with GitHub Actions. PHP-Prefixer abstracts the complexity of manually applying prefixes to PHP files. The service automates and streamlines the process of prefixing while providing the scalability and simplicity of serverless computing.

The complete workflow file is available in the sample plugin repository. Note that the workflow file has been updated from the previous version and aligned with the GitHub Action Checkout – actions/checkout variable naming.

#
# Getting started with GitHub Actions for PHP-Prefixer
#
name: PHP-Prefixer

on: [workflow_dispatch]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Run PHP-Prefixer
        uses: PHP-Prefixer/php-prefixer-build-action@v1.0.0
        with:
          personal_access_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          project_id: ${{ secrets.PROJECT_ID }}
          token: ${{ secrets.GH_ACCESS_TOKEN }}

Note that the workflow file has three secrets.

  • One is for the PHP-Prefixer Personal Access Token to authenticate.
  • The second is for the Project ID to integrate with your configured project.
  • The third secret is the GitHub Token used to access the GitHub assets.

Beyond the basic configuration

The Action requires two parameters to function, and it can receive additional parameters for GitHub integration:

ParameterDescriptionRequiredExample
PERSONAL_ACCESS_TOKENThe PHP-Prefixer PAT/Personal Access Token. The token must be configured in the PHP-Prefixer account.Yes789\|123456789...
PROJECT_IDThe project ID to process the source code. The project must be configured in your account in the PHP-Prefixer account.Yes5432
TOKENThe GitHub PAT/Personal Access Token to access private repositories. It is only required if the project, the library, or the dependencies are private.Noghp_F4fZ9Cq7QF...
SCHEMAThe PHP-Prefixer JSON configuration is applied to the project. By default, the prefixer uses the configuration present in composer.json. This parameter overrides the composer.json extra configuration to define the PHP-Prefixer schema.No{"project-name": "Prefixed Project","namespaces-prefix": "PPP","global-scope-prefix": "PPP_"}
PHP-Prefixer Build Action Parameters

For a full reference of the configuration options, please, check the documentation here: https://php-prefixer.com/docs/how-to-guides/command-line/ci-cd/#php-prefixer-build-action.

Conclusion

GitHub Action v1 for PHP-Prefixer is now available to facilitate the usage of PHP-Prefixer (an automated online service to apply prefixes to PHP Composer dependencies). The Command-Line provides an ideal tool to integrate the prefixing service in any CI/CD context. This release includes installing and using the PHP-Prefixer CLI and committing the prefixed codebase to a prefixed branch in the source repository.

The new Action combines GitHub Action Checkout and GitHub Action Toolkit. The GitHub Actions ToolKit provides a set of packages to make creating actions more straightforward and robust. The Action does a little bit of everything, including:

  • Clones a repository (with GitHub’s checkout)
  • Calls the PHP-Prefixer service with a CLI
  • Manages branches and tags
  • Commits the prefixed results

The final result has been a success so far.

You can now automate your builds with GitHub Actions and integrate with PHP-Prefixer for all your deployment and automation needs.

Please let us know how you’d like us to improve in the comments.

Happy prefixing!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.