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’?

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

You define your workflow using a YAML configuration file and store it in your Git repository. You can compose your automation with reusable building blocks called ‘Actions‘. Workflows are executed 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 and 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 to be 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 we reference three secrets in this configuration. One is for the PHP-Prefixer Personal Access Token to authenticate, the second is for the Project ID to integrate with your configured project and the Token is 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:

Parameter Description Required Example
PERSONAL_ACCESS_TOKEN The PHP-Prefixer PAT/Personal Access Token. The token must be configured in the PHP-Prefixer account. Yes 789\|123456789...
PROJECT_ID The project ID to process the source code. The project must be configured in your account in the PHP-Prefixer account. Yes 5432
TOKEN The GitHub PAT/Personal Access Token to access private repositories. It is only required if the project, the library or the dependencies are private. No ghp_F4fZ9Cq7QF...
SCHEMA The PHP-Prefixer JSON configuration to be applied to the project. By default, the prefixer uses the configuration present in composer.json. If there is no extra configuration or the extra configuration must be replaced, 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.1 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: clones a repository (with GitHub’s checkout), calls the PHP-Prefixer service with a CLI, manages branches and tags, and 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 in the comments if there are any you’d like us to improve.

Happy prefixing!.

The post PHP-Prefixer GitHub Action v1 is available first appeared on PHP Prefixer Blog.

Read more

© 2022 Extly, CB - All rights reserved.