Skip to content

Commit 33c3fd9

Browse files
committed
docs(readme): Document the action
1 parent 637f40f commit 33c3fd9

File tree

5 files changed

+174
-17
lines changed

5 files changed

+174
-17
lines changed

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
# @package PHP Prefixer Build Action
2+
#
3+
# @author PHP Prefixer <team@php-prefixer.com>
4+
# @copyright Copyright (c)2019-2021 Desarrollos Inteligentes Virtuales, SL. All rights reserved.
5+
# @license MIT
6+
#
7+
# @see https://php-prefixer.com
8+
9+
#
110
# https://github.com/docker-library/php/blob/d2b630dc89b257cb80d6fc99e177caae152830b8/8.0/buster/cli/Dockerfile
2-
FROM php:8.0.9-cli
11+
# https://hub.docker.com/_/php
12+
#
13+
14+
FROM php:8.0-cli
315
RUN curl -sSfL -o /php-prefixer-cli.phar 'https://github.com/PHP-Prefixer/php-prefixer-cli/releases/download/0.0.6/php-prefixer-cli.phar' \
416
&& chmod +x php-prefixer-cli.phar \
517
&& curl -sSfL -o /usr/local/bin/composer 'https://getcomposer.org/composer.phar' \

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 PHP-Prefixer
3+
Copyright (c) 2021 PHP Prefixer / Desarrollos Inteligentes Virtuales, SL. <team@php-prefixer.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,134 @@
1-
# PHP Prefixer Build Action
21

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

action.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
name: PHP-Prefixer
2-
author: Put your name here
3-
description: 'Applies prefixes for PHP code stored in a specified directory'
2+
author: PHP Prefixer <team@php-prefixer.com>
3+
description: 'Action to prefix PHP libraries and projects. PHP-Prefixer is an automated online service powered by a complex rule-based system to apply prefixes to Composer dependencies. For information, please, visit https://php-prefixer.com.'
4+
45
inputs:
5-
source_dir_path:
6-
description: 'Relative path to source project directory. It must contain .git repository and composer.json file. If not set the base repository directory will be used as the value. Example: `foo/bar`'
7-
required: false
8-
target_branch:
9-
description: todo
10-
required: true
11-
default: 'prefixed'
126
personal_access_token:
13-
description: 'PAT/Personal Access Token generated via the https://php-prefixer.com site, Example: `789|1234567890123456789012345678901234567890`'
7+
description: 'The PHP-Prefixer PAT/Personal Access Token. The token must be configured in the PHP-Prefixer account. Example: `789|1234567890123456789012345678901234567890`.'
148
required: true
9+
1510
project_id:
16-
description: 'The project ID to process the source code. Example: `5123`'
11+
description: 'The project ID to process the source code. The project must be configured in your account in the PHP-Prefixer account. Example: `5123`.'
1712
required: true
13+
14+
source_dir_path:
15+
description: '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`.'
16+
required: false
17+
18+
target_branch:
19+
description: 'The branch in the repository where PHP-Prefixer will store the prefixed files after processing. By default: `prefixed`.'
20+
required: false
21+
default: 'prefixed'
22+
1823
gh_personal_access_token:
19-
description: 'GitHub PAT/Personal Access Token. Required for the private repository only'
24+
description: 'The GitHub PAT/Personal Access Token to access private repositories. It is only required if the project, the library or the dependencies are private.'
2025
required: false
2126
default: ''
27+
2228
runs:
2329
using: 'docker'
2430
image: 'Dockerfile'
31+
2532
branding:
2633
icon: 'code'
2734
color: 'blue'

entrypoint.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/usr/bin/env bash
22

3+
# @package PHP Prefixer Build Action
4+
#
5+
# @author PHP Prefixer <team@php-prefixer.com>
6+
# @copyright Copyright (c)2019-2021 Desarrollos Inteligentes Virtuales, SL. All rights reserved.
7+
# @license MIT
8+
#
9+
# @see https://php-prefixer.com
10+
311
set -eu
412

513
if [[ -z "$INPUT_SOURCE_DIR_PATH" ]]; then
@@ -35,7 +43,6 @@ initGitRepoForTargetDir() {
3543

3644
readonly remote=tmp$(($(date +%s%N)/1000000))
3745

38-
#git checkout "$INPUT_TARGET_BRANCH" || git checkout -b "$INPUT_TARGET_BRANCH"git remote add "$remote" "https://$INPUT_TARGET_REPO_USER:$GITHUB_ACCESS_TOKEN@github.com/$GITHUB_REPOSITORY"
3946
git remote add "$remote" "https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY"
4047

4148
git fetch "$remote"

0 commit comments

Comments
 (0)