Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 90 additions & 17 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: "Tests"
on:
pull_request:
branches:
- master
- main
paths:
- '**.php'
- 'composer.json'
Expand All @@ -12,7 +12,7 @@ on:
- '.github/workflows/tests.yaml'
push:
branches:
- master
- main
paths:
- '**.php'
- 'composer.json'
Expand All @@ -22,42 +22,115 @@ on:

env:
CONSUL_HTTP_ADDR: "127.0.0.1:8500"
CONSUL_VERSION: '1.17.2'
CONSUL_VERSION: '1.20.5'

jobs:
tests:
runs-on: ubuntu-22.04
strategy:
matrix:
php-version: ["8.0", "8.1", "8.2"]
php-version:
- '8.1'
- '8.2'
- '8.3'
- '8.4'

name: Tests - PHP ${{ matrix.php-version }}
steps:
- uses: actions/checkout@v4

- name: 'Define vars'
id: vars
shell: bash -e {0}
# language=sh
run: |
_phpunit_version=
case "${{ matrix.php-version }}" in
8.1) _phpunit_version='10.5' ;;
8.2) _phpunit_version='11.1' ;;
8.3) _phpunit_version='11.1' ;;
8.4) _phpunit_version='11.1' ;;
*) echo "Unsupported PHP version: ${{ matrix.php-version }}" && exit 1 ;;
esac
echo "phpunit-version=${_phpunit_version}" >> $GITHUB_OUTPUT

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: json
ini-values: precision=14,serialize_precision=-1

- name: 'Composer update'
# language=bash
- name: 'Install jq'
uses: dcarbone/install-jq-action@v3
with:
force: true

- name: 'Set composer dep versions'
shell: bash -e {0}
# language=sh
run: |
composer update \
--no-ansi \
--no-interaction \
--no-scripts \
--no-progress
tmpf="$(mktemp)"
jq -rcM '."require-dev"."phpunit/phpunit" = "^${{ steps.vars.outputs.phpunit-version }}"' composer.json > "${tmpf}"
mv "${tmpf}" composer.json

- name: 'Install Consul'
- name: 'Get composer cache directory'
id: composer-cache
shell: bash -e {0}
# language=sh
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: 'Init composer dep cache'
id: cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ steps.vars.outputs.phpunit-version }}-${{ hashFiles('composer.lock') }}"

- name: 'Install composer deps'
shell: bash -e {0}
# language=sh
run: |
rm composer.lock
composer update --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: 'Save composer dep cache'
if: steps.cache.outputs.cache-hit != 'true' && steps.cache.outputs.cache-hit != true
uses: actions/cache/save@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ steps.vars.outputs.phpunit-version }}-${{ hashFiles('composer.lock') }}"

- name: 'Restore consul ${{ env.CONSUL_VERSION }}'
id: consul-cache
uses: actions/cache/restore@v4
with:
path: '${{ runner.tool_cache }}/consul'
key: 'consul-${{ env.CONSUL_VERSION }}'

- name: 'Install consul ${{ env.CONSUL_VERSION }}'
if: '! steps.consul-cache.outputs.cache-hit'
working-directory: '${{ runner.temp }}'
# language=bash
run: |
wget https://releases.hashicorp.com/consul/${{ env.CONSUL_VERSION }}/consul_${{ env.CONSUL_VERSION }}_linux_amd64.zip
unzip consul_${{ env.CONSUL_VERSION }}_linux_amd64.zip -d /usr/local/bin/
rm consul_${{ env.CONSUL_VERSION }}_linux_amd64.zip
chmod +x /usr/local/bin/consul
consul --version
mkdir consul
wget -O consul.zip https://releases.hashicorp.com/consul/${{ env.CONSUL_VERSION }}/consul_${{ env.CONSUL_VERSION }}_linux_amd64.zip
unzip 'consul.zip' consul -d consul/
rm consul.zip
chmod +x consul/consul

- name: 'Install consul ${{ env.CONSUL_VERSION }} into tool cache'
uses: AnimMouse/tool-cache@v1
with:
folder_name: consul
cache_hit: ${{ steps.consul-cache.outputs.cache-hit }}

- name: 'Save consul ${{ env.CONSUL_VERSION }} cache'
if: '! steps.consul-cache.outputs.cache-hit'
uses: actions/cache/save@v4
with:
path: '${{ runner.tool_cache }}/consul'
key: 'consul-${{ env.CONSUL_VERSION }}'

- name: 'Execute tests'
# language=bash
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This library is loosely based upon the [official GO client](https://github.com/h
| 0.6.x | 0.7-0.8 |
| v1.x | 0.9-current |
| v2.x | 0.9-current |
| dev-master | current |
| dev-main | current |

Newer versions of the api lib will probably work in a limited capacity with older versions of Consul, but no guarantee
is made and backwards compatibility issues will not be addressed.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"php-consul-api"
],
"require": {
"php": "8.*",
"php": "^8.1",
"ext-json": "*",
"dcarbone/gotime": "v0.5.*",
"dcarbone/gotime": "^v0.6",
"dcarbone/gohttp": "v0.3.*",
"guzzlehttp/guzzle": "^7.4",
"guzzlehttp/psr7": "^2.4"
Expand All @@ -33,7 +33,7 @@
}
},
"require-dev": {
"phpunit/phpunit": "@stable"
"phpunit/phpunit": "^10.5 || ^11.0"
},
"autoload-dev": {
"files": [
Expand All @@ -46,6 +46,6 @@
}
},
"scripts": {
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --config tools/php-cs-fixer/php-consul-api-rules.php_cs src/"
"php-cs-fixer": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config tools/php-cs-fixer/php-consul-api-rules.php_cs src/"
}
}
Loading