|
1 | | -# PHP Prefixer Build Action |
2 | 1 |
|
3 | | -Action for applying PHP prefixes to namespaces, functions, helpers, traits, interfaces, etc. |
| 2 | +<img src="https://php-prefixer.com/images/logo/php-prefixer-action_100.png" align="right" alt="PHP Prefixer Action for Github" /> |
| 3 | + |
| 4 | +Use the PHP Prefixer CLI in your Github Actions |
| 5 | +============================================ |
| 6 | + |
| 7 | +The **PHP Prefixer Build Action** integrates the [PHP-Prefixer](https://php-prefixer.com/) service with GitHub Actions. |
| 8 | + |
| 9 | +**PHP-Prefixer** is a service to apply PHP prefixes to namespaces, functions, helpers, traits, interfaces, etc. Start with a Composer project and a set of dependencies, and prefix all library files at once to generate a consistent prefixed codebase. |
| 10 | + |
| 11 | +PHP-Prefixer abstracts the complexity of manually applying prefixes to PHP files. The service **automates and streamlines the process of prefixing** with the scalability and simplicity of serverless computing. |
| 12 | + |
| 13 | +PHP-Prefixer is a **rule-based expert system** that processes the project and dependencies iteratively to prefix every project file. |
| 14 | + |
| 15 | +Given this sample class declaration: |
| 16 | + |
| 17 | +```php |
| 18 | +namespace ACME\Carbon; |
| 19 | + |
| 20 | +use ACME\Carbon\Exceptions\InvalidDateException; |
| 21 | +use DateInterval; |
| 22 | +use ACME\Symfony\Component\Translation; |
| 23 | + |
| 24 | +class Carbon extends DateTime |
| 25 | +{ |
| 26 | + const NO_ZERO_DIFF = 01; |
| 27 | +... |
| 28 | +``` |
| 29 | + |
| 30 | +The associated prefixed class declaration, with a new and distinct namespace `ACME`: |
| 31 | + |
| 32 | +```php |
| 33 | +namespace ACME\Carbon; |
| 34 | + |
| 35 | +use ACME\Carbon\Exceptions\InvalidDateException; |
| 36 | +use DateInterval; |
| 37 | +use ACME\Symfony\Component\Translation; |
| 38 | + |
| 39 | +class Carbon extends DateTime |
| 40 | +{ |
| 41 | + const NO_ZERO_DIFF = 01; |
| 42 | +... |
| 43 | +``` |
| 44 | + |
| 45 | +An example repository has been created at https://php-prefixer.com/docs/guides/how-to-prefix-wordpress-plugin-with-private-dep/ to show how to use this action in a real project. The repository also depends on a private dependency and uses GitHub PAT/Personal Access Tokens for authentication. |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +To use the Action, you must create an account on [PHP-Prefixer](https://php-prefixer.com/) and prepare your projects with the prefix defined in the `composer.json` schema. Before using the Action and the command-line, we recommend checking the documentation and guides here: <https://php-prefixer.com/docs/>. You can also prefix your firsts projects on the service web interface. |
| 50 | + |
| 51 | +Create your Github Workflow configuration in `.github/workflows/prefixer.yml` or similar. |
| 52 | + |
| 53 | +```yaml |
| 54 | +name: Prefixer |
| 55 | + |
| 56 | +on: [push] |
| 57 | + |
| 58 | +jobs: |
| 59 | + build: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + |
| 62 | + steps: |
| 63 | + - name: Checkout |
| 64 | + uses: actions/checkout@v2 |
| 65 | + |
| 66 | + - name: Run PHP-Prefixer |
| 67 | + uses: PHP-Prefixer/php-prefixer-build-action@v0.0.1 |
| 68 | + env: |
| 69 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + with: |
| 71 | + personal_access_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 72 | + project_id: ${{ secrets.PROJECT_ID }} |
| 73 | + # ... then your own project steps ... |
| 74 | +``` |
| 75 | + |
| 76 | +### Available Parameters |
| 77 | + |
| 78 | +The Action requires two parameters to function, and it can receive additional parameters for GitHub integration: |
| 79 | + |
| 80 | +Parameter | Description | Required | Example |
| 81 | +---------|----------| ---------|---------- |
| 82 | +PERSONAL_ACCESS_TOKEN | The PHP-Prefixer PAT/Personal Access Token. The token must be configured in the PHP-Prefixer account. | Yes | `789|1234567890123456789012345678901234567890` |
| 83 | +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` |
| 84 | +SOURCE_DIR_PATH | The relative path to the source project directory. It must contain a .git repository and composer.json file. If not, set the base repository directory will be used as the value. Example: `foo/bar`. | No | `./` |
| 85 | +TARGET_BRANCH | The branch in the repository where PHP-Prefixer will store the prefixed files after processing. | No | `prefixed` |
| 86 | +GH_PERSONAL_ACCESS_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 | |
| 87 | + |
| 88 | +## Prefixing Private Repositories |
| 89 | + |
| 90 | +To prefix from a private repository, GitHub PAT/Personal Access Tokens must be used. Generate a **Personal Access Token** for this purpose and add it to your private repository's configuration. |
| 91 | + |
| 92 | +Create a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) for the Github account you wish to authenticate with. |
| 93 | + |
| 94 | +Add the GitHub PAT/Personal Access Tokens to your project using [Github Secrets][secrets], and pass them into the `PHP-Prefixer/php-prefixer-build-action` action by using the `gh_personal_access_token` input. |
| 95 | + |
| 96 | +Example yaml, showing how to pass secrets: |
| 97 | + |
| 98 | +```yaml |
| 99 | +jobs: |
| 100 | + build: |
| 101 | + |
| 102 | + ... |
| 103 | + |
| 104 | + - name: Run PHP-Prefixer |
| 105 | + uses: PHP-Prefixer/php-prefixer-build-action@v0.0.1 |
| 106 | + env: |
| 107 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 108 | + with: |
| 109 | + personal_access_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |
| 110 | + project_id: ${{ secrets.PROJECT_ID }} |
| 111 | + gh_personal_access_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} |
| 112 | +``` |
| 113 | +
|
| 114 | +There is an example repository available for reference at https://github.com/PHP-Prefixer/how-to-prefix-wordpress-plugin-with-private-dep that uses a private dependency. Check it out for a live working project. |
| 115 | +
|
| 116 | +## Version Numbers |
| 117 | +
|
| 118 | +This action is released with semantic version numbers and tagged, so the latest major release's tag always points to the latest release within the matching major version. |
| 119 | +
|
| 120 | +Please feel free to use `uses: PHP-Prefixer/php-prefixer-build-action@v1` to always run the latest version of v1, or `uses: PHP-Prefixer/php-prefixer-build-action@v1.0.0` to specify the exact release. |
| 121 | + |
| 122 | +*** |
| 123 | + |
| 124 | +If you found this repository helpful, please consider [upvoting the product on ProductHunt](https://www.producthunt.com/posts/php-prefixer). |
| 125 | + |
| 126 | +## Additional Links |
| 127 | + |
| 128 | +- PHP-Prefixer: https://php-prefixer.com/ |
| 129 | +- Documentation: https://php-prefixer.com/docs |
| 130 | +- Config Reference: https://php-prefixer.com/docs/config/ |
| 131 | +- API: https://php-prefixer.com/docs/rest-api-reference/ |
| 132 | +- Command Line: https://php-prefixer.com/docs/command-line/ |
| 133 | + |
| 134 | +[secrets]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets |
0 commit comments