Compare commits

..

16 Commits

Author SHA1 Message Date
011ab6e363 Update sponsors section 2025-07-17 07:32:30 +05:30
545bc26d45 Minor fix in README 2025-07-17 07:32:30 +05:30
55463ffe4f Add support for github-token input 2025-07-17 07:32:24 +05:30
2a3befd7ab Do not fallback extension to default version on fail-fast 2025-07-17 05:07:54 +05:30
7cc4441283 Use ppa.setup-php.com [skip ci] 2025-07-17 04:49:47 +05:30
4a4c5a48bb Update dependencies 2025-07-09 05:18:20 +05:30
3514a658eb Update branch references to main 2025-07-09 04:36:51 +05:30
7aefaa0b54 Merge pull request #967 from jrfnl/feature/readme-fix-broken-link
README: fix broken link
2025-06-25 05:04:51 +05:30
048eb79ef3 README: fix broken link 2025-06-25 01:31:29 +02:00
29247235f0 Merge pull request #966 from OskarStark/patch-1
⚙ Improvement: Update docs
2025-06-24 20:41:11 +05:30
e84efebd6e Update docs
As version 2 is the standard right now, make it clear by setting the v1 manually.
2025-06-24 17:39:04 +03:00
0f7f1d08e3 Upgrade to Jest 30 2025-06-13 02:06:31 +05:30
433bdeeaf0 Bump version to 2.34.1 2025-06-12 03:52:26 +05:30
1c5378302c Update node.js dependencies 2025-06-11 15:17:10 +05:30
c251c791ff Fix pipe in get_sha256 2025-06-11 15:00:38 +05:30
36fada6981 Fix tool-cache directory on self-hosted runners 2025-06-11 14:57:09 +05:30
16 changed files with 2494 additions and 1402 deletions

View File

@ -2,7 +2,7 @@ name: Node workflow
on:
pull_request:
branches:
- master
- main
- develop
- verbose
paths-ignore:
@ -10,7 +10,7 @@ on:
- 'examples/**'
push:
branches:
- master
- main
- develop
- verbose
paths-ignore:

View File

@ -3,7 +3,7 @@ on:
workflow_dispatch:
pull_request:
branches:
- master
- main
- develop
- verbose
paths-ignore:
@ -11,7 +11,7 @@ on:
- 'examples/**'
push:
branches:
- master
- main
- develop
- verbose
paths-ignore:

2
.gitignore vendored
View File

@ -3,7 +3,7 @@ node_modules/
__tests__/runner/*
lib/
# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Rest of the file pulled from https://github.com/github/gitignore/blob/main/Node.gitignore
# Logs
logs
*.log

View File

@ -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.
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#composer-github-oauth "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.
```yaml
@ -278,7 +265,7 @@ These tools can be set up globally using the `tools` input. It accepts a string
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer:v2
tools: composer:v1
```
- If you do not use composer in your workflow, you can specify `tools: none` to skip it.
@ -430,7 +417,7 @@ Disable coverage for these reasons:
- The `php-version-file` input if it exists
- A `composer.lock` file and the `platform-overrides.php` value
- A `composer.json` file and the `config.platform.php` value
- If the `composer.lock` or `composer.json` file is in a sub-directory in your repository, please specify the subdirectory path in `COMPOSER_PROJECT_DIR` env.
- If the `composer.lock` or `composer.json` file is in a subdirectory in your repository, please specify the subdirectory path in `COMPOSER_PROJECT_DIR` env.
#### `php-version-file` (optional)
@ -438,7 +425,7 @@ Disable coverage for these reasons:
- Accepts a `string`. For example `'.phpenv-version'`.
- See [PHP support](#tada-php-support) for the supported PHP versions.
- By default, `.php-version` file is used.
- The file either have the PHP version as its content, or follow the asdf `.tool-versions` format.
- The file needs to either have the PHP version as its content or follows the asdf `.tool-versions` format.
- If not specified and the default `.php-version` file is not found, the latest stable PHP version is set up.
#### `extensions` (optional)
@ -473,6 +460,12 @@ Disable coverage for these reasons:
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
- 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
#### `php-version`
@ -561,8 +554,6 @@ jobs:
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
### Nightly Build Setup
@ -804,17 +795,16 @@ restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
### 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
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.YOUR_PAT_TOKEN }}
```
### Private Packagist Authentication
@ -1015,19 +1005,26 @@ Many users and organisations support setup-php via [GitHub Sponsors](https://git
These companies generously provide setup-php their products and services to aid in the development of this project.
<p>
<a href="https://www.jetbrains.com/?from=setup-php">
<img src="https://setup-php.com/sponsors/jetbrains.svg" alt="JetBrains" width="212" height="120">
<a target="_blank" href="https://www.jetbrains.com/?from=setup-php">
<img src="https://setup-php.com/sponsors/jetbrains.svg" alt="JetBrains" width="140" height="80">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.macstadium.com/opensource/members#gh-light-mode-only">
<img src="https://setup-php.com/sponsors/macstadium.png" alt="Mac Stadium" width="296" height="120">
<a target="_blank" href="https://www.cloudflare.com/lp/project-alexandria/#gh-light-mode-only">
<img src="https://setup-php.com/sponsors/cloudflare.svg" alt="Cloudflare" width="240" height="80">
</a>
<a href="https://www.macstadium.com/opensource/members#gh-dark-mode-only">
<img src="https://setup-php.com/sponsors/macstadium-white.png" alt="Mac Stadium" width="296" height="120">
<a target="_blank" href="https://www.cloudflare.com/lp/project-alexandria/#gh-dark-mode-only">
<img src="https://setup-php.com/sponsors/cloudflare-white.svg" alt="Cloudflare" width="240" height="80">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://tidelift.com/subscription/pkg/npm-setup-php">
<img src="https://setup-php.com/sponsors/tidelift.png" alt="Tidelift" width="140" height="120">
<a target="_blank" href="https://www.macstadium.com/company/opensource#gh-light-mode-only">
<img src="https://setup-php.com/sponsors/macstadium.png" alt="Mac Stadium" width="200" height="80">
</a>
<a target="_blank" href="https://www.macstadium.com/company/opensource#gh-dark-mode-only">
<img src="https://setup-php.com/sponsors/macstadium-white.png" alt="Mac Stadium" width="200" height="80">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a target="_blank" href="#">
<img src="https://setup-php.com/sponsors/tidelift.png" alt="Tidelift" width="94" height="80">
</a>
</p>

View File

@ -27,6 +27,9 @@ inputs:
tools:
description: 'Setup popular tools globally.'
required: false
github-token:
description: 'GitHub token to use for authentication.'
default: ${{ github.token }}
outputs:
php-version:
description: 'PHP version in semver format'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

3752
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "2.34.0",
"version": "2.34.1",
"private": false,
"description": "Setup PHP for use with GitHub Actions",
"main": "lib/install.js",
@ -40,27 +40,30 @@
"compare-versions": "^6.1.1"
},
"devDependencies": {
"@eslint/compat": "^1.2.9",
"@eslint/js": "9.28.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.15.30",
"@typescript-eslint/eslint-plugin": "^8.33.1",
"@typescript-eslint/parser": "^8.33.1",
"@eslint/compat": "^1.3.1",
"@eslint/js": "9.30.1",
"@types/jest": "^30.0.0",
"@types/node": "^24.0.11",
"@typescript-eslint/eslint-plugin": "^8.36.0",
"@typescript-eslint/parser": "^8.36.0",
"@vercel/ncc": "^0.38.3",
"eslint": "9.28.0",
"eslint": "9.30.1",
"eslint-config-prettier": "^10.1.5",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.13.0",
"eslint-plugin-prettier": "^5.4.1",
"globals": "^16.2.0",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jest": "^29.0.1",
"eslint-plugin-prettier": "^5.5.1",
"globals": "^16.3.0",
"jest": "^30.0.4",
"jest-circus": "^30.0.4",
"nock": "^14.0.5",
"prettier": "^3.5.3",
"prettier": "^3.6.2",
"simple-git-hooks": "^2.13.0",
"ts-jest": "^29.3.4",
"ts-jest": "^29.4.0",
"typescript": "^5.8.3"
},
"overrides": {
"test-exclude": "^7.0.1"
},
"bugs": {
"url": "https://github.com/shivammathur/setup-php/issues"
},

View File

@ -18,7 +18,6 @@ export async function getScript(os: string): Promise<string> {
const filename = os + (await utils.scriptExtension(os));
const script_path = path.join(__dirname, '../src/scripts', filename);
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 ini_values_csv: string = await utils.getInput('ini-values', 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;
}
/**
* 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
*/
@ -55,6 +62,7 @@ export async function run(): Promise<void> {
const os: string = process.platform;
const tool = await utils.scriptTool(os);
const run_path = await getScript(os);
await setEnv();
await exec(tool + run_path);
}

View File

@ -212,7 +212,7 @@ get_scan_dir() {
# Function to handle self-hosted runner setup.
self_hosted_helper() {
:
sudo mkdir -p /opt/hostedtoolcache >/dev/null 2>&1 || true
}
# Function to Setup PHP.

View File

@ -216,7 +216,7 @@ add_pecl_extension() {
add_log "${tick:?}" "$extension" "Enabled"
else
[ -n "$pecl_version" ] && pecl_version="-$pecl_version"
pecl_install "$extension$pecl_version" || add_extension "$extension" "$(get_extension_prefix "$extension")" >/dev/null 2>&1
pecl_install "$extension$pecl_version" || ( [ "${fail_fast:?}" = "false" ] && add_extension "$extension" "$(get_extension_prefix "$extension")" >/dev/null 2>&1)
extension_version="$(php -r "echo phpversion('$extension');")"
[ -n "$extension_version" ] && extension_version="-$extension_version"
add_extension_log "$extension$extension_version" "Installed and enabled"

View File

@ -20,6 +20,7 @@ self_hosted_helper() {
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
trap "sudo rm -f /usr/bin/apt-fast 2>/dev/null" exit
fi
sudo mkdir -p /opt/hostedtoolcache >/dev/null 2>&1 || true
install_packages apt-transport-https ca-certificates curl file make jq unzip autoconf automake gcc g++ gnupg
}

View File

@ -164,7 +164,7 @@ remove_list() {
# Function to check if ubuntu ppa is up
is_ubuntu_ppa_up() {
ppa=${1:-ondrej/php}
curl -s --connect-timeout 5 --max-time 5 --head --fail "$lpc_ppa/$ppa/ubuntu/dists/$VERSION_CODENAME/Release" > /dev/null
curl -s --connect-timeout 10 --max-time 10 --head --fail "$lpc_ppa/$ppa/ubuntu/dists/$VERSION_CODENAME/Release" > /dev/null
}
# Function to add the PPA mirror.
@ -172,8 +172,8 @@ add_ppa_sp_mirror() {
ppa=$1
ppa_name="$(basename "$ppa")"
remove_list "$ppa" || true
[ "${debug:?}" = "debug" ] && add_list sp/"$ppa_name" "$sp/$ppa/ubuntu" "$sp/$ppa/ubuntu/key.gpg" "$VERSION_CODENAME" "main/debug"
add_list sp/"$ppa_name" "$sp/$ppa/ubuntu" "$sp/$ppa/ubuntu/key.gpg"
[ "${debug:?}" = "debug" ] && add_list sp/"$ppa_name" "$ppa_sp/$ppa/ubuntu" "$ppa_sp/$ppa/ubuntu/key.gpg" "$VERSION_CODENAME" "main/debug"
add_list sp/"$ppa_name" "$ppa_sp/$ppa/ubuntu" "$ppa_sp/$ppa/ubuntu/key.gpg"
}
# Function to add a PPA.
@ -182,7 +182,7 @@ add_ppa() {
ppa=${1:-ondrej/php}
if [[ "$ID" = "ubuntu" || "$ID_LIKE" =~ ubuntu ]] && [[ "$ppa" =~ "ondrej/" ]]; then
if is_ubuntu_ppa_up "$ppa" ; then
[ "${runner:?}" = "self-hosted" ] && find "$list_dir" -type f -name 'sp*' -exec grep -qF "$sp" {} \; -delete
[ "${runner:?}" = "self-hosted" ] && find "$list_dir" -type f -name 'sp*' -exec grep -qF "${sp/https:\/\/}" {} \; -delete
[ "${debug:?}" = "debug" ] && add_list "$ppa" "$lpc_ppa/$ppa/ubuntu" "$lpc_ppa/$ppa/ubuntu" "$VERSION_CODENAME" "main/debug"
add_list "$ppa"
else
@ -225,6 +225,7 @@ lpc_ppa='https://ppa.launchpadcontent.net'
key_dir='/usr/share/keyrings'
dist_info_dir='/usr/share/distro-info'
sury='https://packages.sury.org'
ppa_sp='https://ppa.setup-php.com'
sp='https://setup-php.com'
sks=(
'https://keyserver.ubuntu.com'

View File

@ -110,11 +110,11 @@ release_lock() {
# Function to get the SHA256 hash of a string.
get_sha256() {
local input=$1
if command -v sha256sum >/dev/null 2>&1; then
if command -v sha256sum >/dev/null; then
printf '%s' "$input" | sha256sum | cut -d' ' -f1
elif command -v shasum >/dev/null 2>&1; then
elif command -v shasum >/dev/null; then
printf '%s' "$input" | shasum -a 256 | cut -d' ' -f1
elif command -v openssl >/dev/null 2>&1; then
elif command -v openssl >/dev/null; then
printf '%s' "$input" | openssl dgst -sha256 | cut -d' ' -f2
fi
}
@ -221,7 +221,7 @@ self_hosted_setup() {
exit 1
else
self_hosted_helper >/dev/null 2>&1
add_env RUNNER_TOOL_CACHE /tmp
add_env RUNNER_TOOL_CACHE /opt/hostedtoolcache
fi
fi
}

View File

@ -419,6 +419,7 @@ export async function addPhive(data: RS): Promise<string> {
* @param data
*/
export async function addPHPUnitTools(data: RS): Promise<string> {
/* istanbul ignore next */
if (data['version'] === 'latest') {
data['version'] =
(await packagist.search(data['packagist'], data['php_version'])) ??

View File

@ -456,6 +456,7 @@ export async function readPHPVersion(): Promise<string> {
const composerLock = path.join(composerProjectDir, 'composer.lock');
if (fs.existsSync(composerLock)) {
const lockFileContents = JSON.parse(fs.readFileSync(composerLock, 'utf8'));
/* istanbul ignore next */
if (
lockFileContents['platform-overrides'] &&
lockFileContents['platform-overrides']['php']
@ -469,6 +470,7 @@ export async function readPHPVersion(): Promise<string> {
const composerFileContents = JSON.parse(
fs.readFileSync(composerJson, 'utf8')
);
/* istanbul ignore next */
if (
composerFileContents['config'] &&
composerFileContents['config']['platform'] &&