Skip to content

[#99] Updated to PHPUnit 11. #173

[#99] Updated to PHPUnit 11.

[#99] Updated to PHPUnit 11. #173

Workflow file for this run

name: Test PHP
on:
push:
branches:
- main
pull_request:
branches:
- main
- 'feature/**'
jobs:
test-php:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.2', '8.3']
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup SSH private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}"
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}"
- name: Install dependencies
run: composer install
- name: Check coding standards
run: composer lint
- name: Run tests
run: XDEBUG_MODE=coverage composer test
- name: Upload coverage report as an artifact
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}-code-coverage-report-${{ matrix.php-versions }}
path: ./.coverage-html
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v5
with:
files: ./cobertura.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
build-php:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Install dependencies
run: composer install
- name: Check composer version
run: composer --version
- name: Build PHAR
run: composer build
- name: Test PHAR
run: ./.build/git-artifact --help || exit 1
# Demonstration of deployment in 'force-push' mode.
deploy-force-push:
needs:
- test-php
- build-php
runs-on: ubuntu-latest
env:
GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch all history for git repository.
fetch-depth: 0
# Do not persist credentials after checkout
# to allow to use custom credentials to push to a remote repo.
persist-credentials: false
ref: ${{ github.head_ref }}
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup SSH private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}"
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}"
- name: Install dependencies
run: composer install
# Test file will have a consistent name between deployments, but
# the contents will be added to on each deployment to simulate
# changes in the source repository.
- name: Prepare test file.
run: |
export TEST_FILE="test-file--force-push--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 1 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
echo $TEST_FILE > $HOME/test-file.txt
- name: Deployment 1
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--force-push--gha--[branch] \
--mode=force-push \
--log=$HOME/report--mode--force-push.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
rm $HOME/report--mode--force-push.txt
- name: Update the test file to simulate changes in the source repository.
run: |
export TEST_FILE="test-file--force-push--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 2 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
- name: Deployment 2
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--force-push--gha--[branch] \
--mode=force-push \
--log=$HOME/report--mode--force-push.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--force-push.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
# Demonstration of deployment in 'branch' mode.
# Note that by design, pushing into the same branch will result in the failure
# of the second push. This is because the mode is intended to create a new
# branch per artifact deployment.
deploy-branch:
needs:
- test-php
- build-php
runs-on: ubuntu-latest
env:
GITHUB_BRANCH: ${{ github.head_ref || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Fetch all history for git repository.
fetch-depth: 0
# Do not persist credentials after checkout
# to allow to use custom credentials to push to a remote repo.
persist-credentials: false
ref: ${{ github.head_ref }}
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Setup SSH private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
- name: Configure Git
run: |
git config --global user.name "${{ secrets.DEPLOY_USER_NAME }}"
git config --global user.email "${{ secrets.DEPLOY_USER_EMAIL }}"
- name: Install dependencies
run: composer install
# Test file will have a consistent name between deployments, but
# the contents will be added to on each deployment to simulate
# changes in the source repository.
# Since each deployment in this mode creates a new branch, the test file
# will be pushed to a new branch each time and won't be updated in
# existing branches.
- name: Prepare test file.
run: |
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 1 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
echo $TEST_FILE > $HOME/test-file.txt
- name: Deployment 1
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"
rm $HOME/report--mode--branch.txt
- name: Update the test file to simulate changes in the source repository.
run: |
export TEST_FILE="test-file--branch--gha--${GITHUB_BRANCH//\//-}.txt"
echo "Deployment 2 for branch $GITHUB_BRANCH" > $TEST_FILE
date "+%Y%m%d-%H%M%S" >> $TEST_FILE
cat $TEST_FILE
- name: Deployment 2 - same branch
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv \
&& { echo "Expected to fail as repeated pushes to the same branch are not allowed, but succeeded" >&2; exit 1; } || echo "Failed as expected"
- name: Deployment 2 - new branch
run: |
./git-artifact \
[email protected]:drevops/git-artifact-destination.git \
--branch=mode--branch--gha--[branch]--[timestamp:Y-m-d_H-i-s] \
--mode=branch \
--log=$HOME/report--mode--branch.txt \
-vvv
DEPLOYED_BRANCH=$(sed -n 's/Remote branch://p' $HOME/report--mode--branch.txt | sed 's/ //g')
echo "Deployed to $DEPLOYED_BRANCH"
echo
echo "See https://github.com/drevops/git-artifact-destination/blob/$DEPLOYED_BRANCH/$(cat $HOME/test-file.txt)"