Update README with beginners' guide and follow-up steps #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test PHP Extension | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
php-version: ['8.1', '8.2', '8.3'] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up PHP ${{ matrix.php-version }} | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-version }} | |
extensions: mbstring, intl | |
- name: Install build tools and Valgrind | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y autoconf automake libtool bison re2c valgrind | |
- name: Prepare build | |
run: | | |
phpize | |
./configure | |
make | |
- name: Run tests | |
id: run_tests | |
run: make test | |
continue-on-error: true | |
- name: Run demo with debug logging | |
id: run_demo | |
run: | | |
php -dextension=./modules/helloworld.so -i | grep helloworld | |
timeout 60s php -n -dextension=./modules/helloworld.so -dmemory_limit=128M -dreport_memleaks=1 -dzend.assertions=1 -dassert.exception=1 smoke.php | |
continue-on-error: true | |
- name: Run Valgrind memory check | |
if: steps.run_tests.outcome == 'failure' || steps.run_demo.outcome == 'failure' | |
run: | | |
cat << EOF > valgrind.supp | |
{ | |
<insert_a_suppression_name_here> | |
Memcheck:Leak | |
match-leak-kinds: reachable | |
... | |
fun:php_module_startup | |
... | |
} | |
EOF | |
valgrind --suppressions=valgrind.supp --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt php -n -dextension=./modules/helloworld.so smoke.php | |
- name: Check Valgrind results | |
if: steps.run_tests.outcome == 'failure' || steps.run_demo.outcome == 'failure' | |
run: | | |
if [ -f valgrind-out.txt ]; then | |
echo "Valgrind log found:" | |
cat valgrind-out.txt | |
if ! grep -q "ERROR SUMMARY: 0 errors from 0 contexts" valgrind-out.txt; then | |
echo "Valgrind found errors" | |
exit 1 | |
fi | |
else | |
echo "Valgrind log not found. This is unexpected." | |
exit 1 | |
fi | |
- name: Upload Valgrind log file | |
if: (steps.run_tests.outcome == 'failure' || steps.run_demo.outcome == 'failure') && always() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: valgrind-log | |
path: valgrind-out.txt | |
if-no-files-found: warn | |
- name: Upload test logs | |
if: failure() | |
uses: actions/upload-artifact@v2 | |
with: | |
name: test-logs | |
path: | | |
tests/*.log | |
tests/*.sh | |
if-no-files-found: warn | |
- name: Final status check | |
if: always() | |
run: | | |
if [ "${{ steps.run_tests.outcome }}" == "failure" ] || [ "${{ steps.run_demo.outcome }}" == "failure" ]; then | |
echo "Tests or demo run failed. Please check the logs for more information." | |
exit 1 | |
fi |