mirror of
https://github.com/shivammathur/setup-php.git
synced 2025-08-17 11:04:39 +07:00
Add support for github-token input
This commit is contained in:
28
README.md
28
README.md
@ -258,19 +258,6 @@ These tools can be set up globally using the `tools` input. It accepts a string
|
|||||||
|
|
||||||
When you specify just the major version or the version in `major.minor` format, the latest patch version matching the input will be setup.
|
When you specify just the major version or the version in `major.minor` format, the latest patch version matching the input will be setup.
|
||||||
|
|
||||||
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").
|
|
||||||
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.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- name: Setup PHP with tools
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: '8.4'
|
|
||||||
tools: php-cs-fixer:3.64, phpunit:11.4
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
|
||||||
|
|
||||||
- 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.
|
- 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.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@ -473,6 +460,12 @@ Disable coverage for these reasons:
|
|||||||
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
|
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
|
||||||
- See [tools support](#wrench-tools-support) for tools supported.
|
- See [tools support](#wrench-tools-support) for tools supported.
|
||||||
|
|
||||||
|
#### `github-token` (optional)
|
||||||
|
|
||||||
|
- Specify the GitHub token to use for authentication.
|
||||||
|
- Accepts a `string`.
|
||||||
|
- By default, `GITHUB_TOKEN` secret provided by GitHub Actions is used.
|
||||||
|
|
||||||
### Outputs
|
### Outputs
|
||||||
|
|
||||||
#### `php-version`
|
#### `php-version`
|
||||||
@ -561,8 +554,6 @@ jobs:
|
|||||||
ini-values: post_max_size=256M, max_execution_time=180
|
ini-values: post_max_size=256M, max_execution_time=180
|
||||||
coverage: xdebug
|
coverage: xdebug
|
||||||
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
|
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Nightly Build Setup
|
### Nightly Build Setup
|
||||||
@ -804,17 +795,16 @@ restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
|
|||||||
|
|
||||||
### GitHub Composer Authentication
|
### GitHub Composer Authentication
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
The `COMPOSER_TOKEN` environment variable has been deprecated in favor of `GITHUB_TOKEN` and will be removed in the next major version.
|
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.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: '8.4'
|
php-version: '8.4'
|
||||||
env:
|
github-token: ${{ secrets.YOUR_PAT_TOKEN }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Private Packagist Authentication
|
### Private Packagist Authentication
|
||||||
|
@ -27,6 +27,9 @@ inputs:
|
|||||||
tools:
|
tools:
|
||||||
description: 'Setup popular tools globally.'
|
description: 'Setup popular tools globally.'
|
||||||
required: false
|
required: false
|
||||||
|
github-token:
|
||||||
|
description: 'GitHub token to use for authentication.'
|
||||||
|
default: ${{ github.token }}
|
||||||
outputs:
|
outputs:
|
||||||
php-version:
|
php-version:
|
||||||
description: 'PHP version in semver format'
|
description: 'PHP version in semver format'
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -18,7 +18,6 @@ export async function getScript(os: string): Promise<string> {
|
|||||||
const filename = os + (await utils.scriptExtension(os));
|
const filename = os + (await utils.scriptExtension(os));
|
||||||
const script_path = path.join(__dirname, '../src/scripts', filename);
|
const script_path = path.join(__dirname, '../src/scripts', filename);
|
||||||
const run_path = script_path.replace(os, 'run');
|
const run_path = script_path.replace(os, 'run');
|
||||||
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
|
||||||
const extension_csv: string = await utils.getInput('extensions', false);
|
const extension_csv: string = await utils.getInput('extensions', false);
|
||||||
const ini_values_csv: string = await utils.getInput('ini-values', false);
|
const ini_values_csv: string = await utils.getInput('ini-values', false);
|
||||||
const coverage_driver: string = await utils.getInput('coverage', false);
|
const coverage_driver: string = await utils.getInput('coverage', false);
|
||||||
@ -48,6 +47,14 @@ export async function getScript(os: string): Promise<string> {
|
|||||||
return run_path;
|
return run_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to set environment variables based on inputs.
|
||||||
|
*/
|
||||||
|
export async function setEnv(): Promise<void> {
|
||||||
|
process.env['fail_fast'] = await utils.getInput('fail-fast', false);
|
||||||
|
process.env['GITHUB_TOKEN'] ??= await utils.getInput('github-token', false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the script
|
* Run the script
|
||||||
*/
|
*/
|
||||||
@ -55,6 +62,7 @@ export async function run(): Promise<void> {
|
|||||||
const os: string = process.platform;
|
const os: string = process.platform;
|
||||||
const tool = await utils.scriptTool(os);
|
const tool = await utils.scriptTool(os);
|
||||||
const run_path = await getScript(os);
|
const run_path = await getScript(os);
|
||||||
|
await setEnv();
|
||||||
await exec(tool + run_path);
|
await exec(tool + run_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user