try to fix file permission in build #1675
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
# | |
# GitHub action executed when a PR is opened, asked for a review | |
# For debugging purposes, also when the assignment is modified. | |
# | |
# For now, runs only the UI tests. | |
# | |
# This action requires a secret called ARTIFACTS_PASS which is the key to upload on build-artifacts. | |
# This value can be found in the development keepass database. | |
# | |
name: Matomo for WordPress Tests | |
on: | |
workflow_dispatch: | |
push: | |
schedule: | |
- cron: "0 0 * * 0" | |
permissions: | |
actions: read | |
checks: none | |
contents: read | |
deployments: none | |
issues: read | |
packages: none | |
pull-requests: read | |
repository-projects: none | |
security-events: none | |
statuses: none | |
id-token: write # for docker gha cache | |
concurrency: | |
group: php-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
unit_tests: | |
runs-on: 'ubuntu-20.04' | |
strategy: | |
fail-fast: false | |
matrix: | |
wp-versions: [ 'latest' ] | |
php-versions: [ '7.2', '8.1' ] | |
multisite: [ "singlesite", "multisite" ] | |
include: | |
- wp-versions: '5.2' | |
php-versions: '7.2' | |
multisite: 'singlesite' | |
- wp-versions: '5.2' | |
php-versions: '7.2' | |
multisite: 'multisite' | |
permissions: | |
contents: read # <--- allows to read repo | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: true | |
lfs: true | |
submodules: true | |
- run: git lfs pull | |
- name: Setup PHP ${{ matrix.php-versions }} | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php-versions }} | |
extensions: curl, dom, exif, fileinfo, hash, imagick, json, mbstring, mysqli, openssl, pcre, sodium, xml, zip | |
ini-values: | | |
post_max_size=8M, | |
memory_limit=256M, | |
max_execution_time=30, | |
always_populate_raw_post_data=-1, | |
error_reporting=E_ALL, | |
log_errors=on, | |
display_errors=on, | |
allow_url_fopen=on, | |
zend.exception_ignore_args=Off | |
tools: composer:v2 | |
coverage: none | |
- name: Check PHP Version | |
run: php -v | |
# note: we update the dependencies since they only exist for the unit tests, and we need to use different | |
# versions of phpunit/etc. for different PHP versions | |
- name: Update test dependencies | |
shell: bash | |
run: | | |
if [[ "${{ matrix.wp-versions }}" = "5.2" ]]; then | |
sed -i 's%"yoast/phpunit-polyfills": ".*"%"yoast/phpunit-polyfills": "^1.1"%g' composer.json | |
fi | |
composer update --with-all-dependencies | |
- name: Install dependencies | |
shell: bash | |
run: composer install | |
# TODO: redundancy w/ e2e_tests, could be moved to a script | |
# docker-compose up | |
# TODO: i can't seem to get docker layer caching to work. | |
- run: | | |
export ACTIONS_CACHE_URL=$(echo "$ACTIONS_ID_TOKEN_REQUEST_URL" | grep -Po 'https://[^/]+/[^/]+/' | sed 's/pipelines/artifactcache/') | |
export ACTIONS_RUNTIME_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN | |
docker buildx build --cache-to type=gha --cache-from type=gha --build-arg PHP_VERSION=${{ matrix.php-versions }} --build-context project="${{ github.workspace }}/scripts" --file=scripts/Dockerfile.local scripts | |
env: | |
PHP_VERSION: ${{ matrix.php-versions }} | |
WOOCOMMERCE: 0 | |
WORDPRESS_FOLDER: test | |
RESET_DATABASE: 1 | |
WORDPRESS_VERSION: ${{ matrix.wp-versions }} | |
- run: | | |
cat > .env <<EOF | |
PHP_VERSION=$PHP_VERSION | |
WOOCOMMERCE=0 | |
WORDPRESS_FOLDER=test | |
RESET_DATABASE=1 | |
WORDPRESS_VERSION=$WORDPRESS_VERSION | |
UID=$UID | |
WP_DEBUG=true | |
EOF | |
env: | |
PHP_VERSION: ${{ matrix.php-versions }} | |
WORDPRESS_VERSION: ${{ matrix.wp-versions }} | |
- run: chmod -R 777 . # required to build the release | |
- run: sudo chown -R $UID:1000 . # required for wordpress' filesystem direct implementation | |
- run: docker compose --env-file .env.default --env-file .env up -d wordpress | |
- run: | | |
# wait for docker-compose launch to finish | |
elapsed=0 | |
until [ -e ./docker/wordpress/test/setup_finished ] || (( elapsed++ >= 240 )); do | |
sleep 1 | |
done | |
if [ ! -e ./docker/wordpress/test/setup_finished ]; then | |
echo "did not setup local environment in time" | |
exit 1 | |
fi | |
[ -e /tmp/file.txt ] && echo File exists || echo Timeout | |
- run: npm run compose logs wordpress --no-color # for debugging failures to start | |
if: always() | |
- name: Run unit tests | |
shell: bash | |
run: | | |
if [[ "${{ matrix.multisite }}" == "singlesite" ]]; then | |
echo "Running in single site context" | |
else | |
echo "Running in multisite context" | |
cat >> .env <<EOF | |
WP_MULTISITE=1 | |
EOF | |
fi | |
npm run phpunit | |
e2e_tests: | |
runs-on: 'ubuntu-22.04' | |
strategy: | |
fail-fast: false | |
matrix: | |
wp-versions: [ 'latest', 'trunk' ] | |
php-versions: [ '7.2', '8.1' ] | |
permissions: | |
contents: read # <--- allows to read repo | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
persist-credentials: false | |
lfs: true | |
submodules: true | |
- run: git lfs pull | |
# setup xvfb | |
- run: sudo apt-get update && sudo apt-get install -y xvfb x11-xserver-utils xauth | |
# setup firefox | |
- uses: browser-actions/setup-firefox@v1 | |
- run: firefox --version | |
# setup node | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: npm | |
cache-dependency-path: '**/package-lock.json' | |
- run: npm install | |
# TODO: try to remove this after prefixing | |
# disable deprecation notices in e2e tests. we can't control much of the code being | |
# tested (ie, WordPress, other WordPress plugins), and it's very easy for one of them | |
# to trigger a deprecation notice | |
- name: Disable deprecation notices | |
shell: bash | |
run: | | |
mkdir docker | |
echo '[PHP]' > docker/php-custom.ini | |
echo 'error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE' >> docker/php-custom.ini | |
echo 'upload_max_filesize = 128M' >> docker/php-custom.ini | |
echo 'memory_limit = 2G' >> docker/php-custom.ini | |
echo 'max_execution_time = 600' >> docker/php-custom.ini | |
echo 'post_max_size = 128M' >> docker/php-custom.ini | |
# docker-compose up | |
# TODO: i can't seem to get docker layer caching to work. | |
- run: | | |
export ACTIONS_CACHE_URL=$(echo "$ACTIONS_ID_TOKEN_REQUEST_URL" | grep -Po 'https://[^/]+/[^/]+/' | sed 's/pipelines/artifactcache/') | |
export ACTIONS_RUNTIME_TOKEN=$ACTIONS_ID_TOKEN_REQUEST_TOKEN | |
docker buildx build --cache-to type=gha --cache-from type=gha --build-arg PHP_VERSION=${{ matrix.php-versions }} --build-context project="${{ github.workspace }}/scripts" --file=scripts/Dockerfile.local scripts | |
env: | |
PHP_VERSION: ${{ matrix.php-versions }} | |
WOOCOMMERCE: 1 | |
WORDPRESS_FOLDER: test | |
RESET_DATABASE: 1 | |
WORDPRESS_VERSION: ${{ matrix.wp-versions }} | |
- run: | | |
cat > .env <<EOF | |
PHP_VERSION=$PHP_VERSION | |
WOOCOMMERCE=1 | |
WORDPRESS_FOLDER=test | |
WORDPRESS_VERSION=$WORDPRESS_VERSION | |
UID=$UID | |
WITHOUT_MARKETPLACE=1 | |
WP_DEBUG=true | |
WP_DEBUG_LOG=true | |
WP_DEBUG_DISPLAY=false | |
EOF | |
env: | |
PHP_VERSION: ${{ matrix.php-versions }} | |
WORDPRESS_VERSION: ${{ matrix.wp-versions }} | |
- run: chmod -R 777 . # required to build the release | |
- run: docker compose --env-file .env.default --env-file .env up -d wordpress | |
- run: | | |
# wait for docker-compose launch to finish | |
elapsed=0 | |
until [ -e ./docker/wordpress/test/setup_finished ] || (( elapsed++ >= 240 )); do | |
sleep 1 | |
done | |
if [ ! -e ./docker/wordpress/test/setup_finished ]; then | |
echo "did not setup local environment in time" | |
exit 1 | |
fi | |
[ -e /tmp/file.txt ] && echo File exists || echo Timeout | |
- run: npm run compose logs wordpress --no-color # for debugging failures to start | |
if: always() | |
# build release from current code | |
- run: | | |
npm run matomo:console -- wordpress:build-release --name=test --zip | |
mv matomo-test.zip matomo.zip | |
# restart wordpress but with latest stable matomo | |
- run: | | |
echo 'INSTALLING_FROM_ZIP=1' >> .env | |
docker compose --env-file .env.default --env-file .env stop wordpress | |
docker compose --env-file .env.default --env-file .env up -d wordpress | |
sleep 20 | |
npm run compose logs wordpress --no-color | |
# run tests | |
- run: xvfb-run --auto-servernum npm run wdio | |
env: | |
PHP_VERSION: ${{ matrix.php-versions }} | |
WOOCOMMERCE: 1 | |
WORDPRESS_FOLDER: test | |
WORDPRESS_VERSION: ${{ matrix.wp-versions }} | |
RELEASE_ZIP: ${{ github.workspace }}/matomo.zip | |
TEST_SHOP_LICENSE: ${{ secrets.TEST_SHOP_LICENSE }} | |
- name: Archive test artifacts (actual) | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: actual-screenshots-${{ matrix.php-versions }}-${{ matrix.wp-versions }} | |
path: tests/e2e/actual | |
- name: Archive test artifacts (diffs) | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: diff-screenshots-${{ matrix.php-versions }}-${{ matrix.wp-versions }} | |
path: tests/e2e/diff | |
# output docker-compose logs | |
- run: npm run compose logs wordpress --no-color | |
if: always() | |
- run: npm run compose stop | |
# output debug.concat.log (created in a hook in wdio.conf.ts) | |
- run: cat ./docker/wordpress/test/wp-content/debug.concat.log || echo "debug.concat.log file does not exist" | |
if: always() | |
checkstyle: | |
runs-on: 'ubuntu-20.04' | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v3 | |
with: | |
persist-credentials: true | |
path: wp-content/plugins/matomo | |
submodules: true | |
- name: Setup PHP for checkstyle | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.0 | |
extensions: curl, dom, exif, fileinfo, hash, imagick, json, mbstring, mysqli, openssl, pcre, sodium, xml, zip | |
ini-values: | | |
post_max_size=8M, | |
memory_limit=256M, | |
max_execution_time=30, | |
always_populate_raw_post_data=-1, | |
error_reporting=E_ALL, | |
log_errors=on, | |
display_errors=on, | |
allow_url_fopen=on, | |
zend.exception_ignore_args=Off | |
tools: composer:v2 | |
coverage: none | |
- name: Check PHP Version | |
run: php -v | |
- name: Install dependencies | |
shell: bash | |
run: | | |
cd ${{ github.workspace }}/wp-content/plugins/matomo && composer update --with-all-dependencies | |
cd ${{ github.workspace }}/wp-content/plugins/matomo && composer install | |
- name: Run checkstyle | |
shell: bash | |
run: cd ${{ github.workspace }}/wp-content/plugins/matomo && ./vendor/bin/phpcs |