Skip to content

Commit b506d0a

Browse files
committed
Add support for github-token input
1 parent 2a3befd commit b506d0a

4 files changed

Lines changed: 22 additions & 21 deletions

File tree

README.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,6 @@ These tools can be set up globally using the `tools` input. It accepts a string
258258

259259
When you specify just the major version or the version in `major.minor` format, the latest patch version matching the input will be setup.
260260

261-
With the exception of major versions of `composer`, if you specify only the `major` version or the version in `major.minor` format for a tool you can get rate limited by GitHub's API. To avoid this, it is recommended to provide a [`GitHub` OAuth token](https://github.com/shivammathur/setup-php#github-composer-authentication "Composer GitHub OAuth").
262-
You can do that by setting `GITHUB_TOKEN` environment variable. The `COMPOSER_TOKEN` environment variable has been deprecated in favor of `GITHUB_TOKEN` and will be removed in the next major version.
263-
264-
```yaml
265-
- name: Setup PHP with tools
266-
uses: shivammathur/setup-php@v2
267-
with:
268-
php-version: '8.4'
269-
tools: php-cs-fixer:3.64, phpunit:11.4
270-
env:
271-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
272-
```
273-
274261
- The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying the major version `v1` or `v2`, or the version in `major.minor` or `semver` format. Additionally, for composer `snapshot` and `preview` can also be specified to set up the respective releases.
275262

276263
```yaml
@@ -473,6 +460,12 @@ Disable coverage for these reasons:
473460
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
474461
- See [tools support](#wrench-tools-support) for tools supported.
475462

463+
#### `github-token` (optional)
464+
465+
- Specify the GitHub token to use for authentication.
466+
- Accepts a `string`.
467+
- By default, `GITHUB_TOKEN` secret provided by GitHub Actions is used.
468+
476469
### Outputs
477470

478471
#### `php-version`
@@ -561,8 +554,6 @@ jobs:
561554
ini-values: post_max_size=256M, max_execution_time=180
562555
coverage: xdebug
563556
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
564-
env:
565-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
566557
```
567558

568559
### Nightly Build Setup
@@ -804,17 +795,16 @@ restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
804795

805796
### GitHub Composer Authentication
806797

807-
If you have a number of workflows which set up multiple tools or have many composer dependencies, you might hit the GitHub's rate limit for composer. Also, if you specify only the major version or the version in `major.minor` format, you can hit the rate limit. To avoid this you can specify an `OAuth` token by setting `GITHUB_TOKEN` environment variable. You can use [`GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token "GITHUB_TOKEN documentation") secret for this purpose.
798+
By default, setup-php uses the `GITHUB_TOKEN` secret that is generated for each workflow run. In case you want to use a Personal Access Token (PAT) instead, you can set the `github-token` input.
808799

809-
The `COMPOSER_TOKEN` environment variable has been deprecated in favor of `GITHUB_TOKEN` and will be removed in the next major version.
800+
The `COMPOSER_TOKEN` and `GITHUB_TOKEN` environment variables have been deprecated in favor of the `github-token` input and will be removed in the next major version.
810801

811802
```yaml
812803
- name: Setup PHP
813804
uses: shivammathur/setup-php@v2
814805
with:
815806
php-version: '8.4'
816-
env:
817-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
807+
github-token: ${{ secrets.YOUR_PAT_TOKEN }}
818808
```
819809

820810
### Private Packagist Authentication

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ inputs:
2727
tools:
2828
description: 'Setup popular tools globally.'
2929
required: false
30+
github-token:
31+
description: 'GitHub token to use for authentication.'
32+
default: ${{ github.token }}
3033
outputs:
3134
php-version:
3235
description: 'PHP version in semver format'

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/install.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export async function getScript(os: string): Promise<string> {
1818
const filename = os + (await utils.scriptExtension(os));
1919
const script_path = path.join(__dirname, '../src/scripts', filename);
2020
const run_path = script_path.replace(os, 'run');
21-
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
2221
const extension_csv: string = await utils.getInput('extensions', false);
2322
const ini_values_csv: string = await utils.getInput('ini-values', false);
2423
const coverage_driver: string = await utils.getInput('coverage', false);
@@ -48,13 +47,22 @@ export async function getScript(os: string): Promise<string> {
4847
return run_path;
4948
}
5049

50+
/**
51+
* Function to set environment variables based on inputs.
52+
*/
53+
export async function setEnv(): Promise<void> {
54+
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
55+
process.env['GITHUB_TOKEN'] ??= await utils.getInput('github-token', true);
56+
}
57+
5158
/**
5259
* Run the script
5360
*/
5461
export async function run(): Promise<void> {
5562
const os: string = process.platform;
5663
const tool = await utils.scriptTool(os);
5764
const run_path = await getScript(os);
65+
await setEnv();
5866
await exec(tool + run_path);
5967
}
6068

0 commit comments

Comments
 (0)