diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index bfc5f6c..d3be83c 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -109,7 +109,18 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar + - name: Check if SonarCloud token is set + id: check_sonar_token + run: | + if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then + echo "SONAR_TOKEN is not set, skipping SonarCloud analysis" + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "skip=false" >> $GITHUB_OUTPUT + fi + - name: SonarCloud Scan + if: steps.check_sonar_token.outputs.skip != 'true' uses: SonarSource/sonarqube-scan-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -132,6 +143,16 @@ jobs: with: fetch-depth: 0 + - name: Check if Codacy token is set + id: check_codacy_token + run: | + if [ -z "${{ secrets.CODACY_PROJECT_TOKEN }}" ]; then + echo "CODACY_PROJECT_TOKEN is not set, running Codacy without upload" + echo "skip_upload=true" >> $GITHUB_OUTPUT + else + echo "skip_upload=false" >> $GITHUB_OUTPUT + fi + - name: Run Codacy Analysis CLI uses: codacy/codacy-analysis-cli-action@5cc54a75f9ad8e86bb795a5d3d4f2f70c9baa1a7 # v4.3.0 with: @@ -147,6 +168,7 @@ jobs: continue-on-error: true - name: Upload SARIF results file + if: steps.check_codacy_token.outputs.skip_upload != 'true' uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.2.7 with: sarif_file: results.sarif diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 76bd73e..b89bea8 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -57,6 +57,9 @@ jobs: echo "WordPress test suite installed successfully" - name: Run PHPUnit tests + env: + WP_PHPUNIT__DIR: /tmp/wordpress-tests-lib + WP_TESTS_DIR: /tmp/wordpress-tests-lib run: | if [ "${{ matrix.multisite }}" = "true" ]; then WP_MULTISITE=1 composer test diff --git a/.github/workflows/playground-tests-fix.yml b/.github/workflows/playground-tests-fix.yml index 4f761f3..5b5f680 100644 --- a/.github/workflows/playground-tests-fix.yml +++ b/.github/workflows/playground-tests-fix.yml @@ -56,10 +56,21 @@ jobs: npx @wp-playground/cli server --blueprint playground/blueprint.json --port 8888 --login & SERVER_PID=$! - # Wait for WordPress Playground to be ready + # Wait for WordPress Playground to be ready (increased timeout to 180s) echo "Waiting for WordPress Playground to be ready..." - timeout 60 bash -c 'until curl -s http://localhost:8888; do sleep 2; done' - echo "WordPress Playground is ready" + TIMEOUT=180 + ELAPSED=0 + while ! curl -s http://localhost:8888 > /dev/null 2>&1; do + if [ $ELAPSED -ge $TIMEOUT ]; then + echo "Timeout waiting for WordPress Playground to start" + kill $SERVER_PID || true + exit 1 + fi + echo "Waiting... ($ELAPSED/$TIMEOUT seconds)" + sleep 5 + ELAPSED=$((ELAPSED + 5)) + done + echo "WordPress Playground is ready after $ELAPSED seconds" # Run Cypress tests against WordPress Playground echo "Running Cypress tests..." diff --git a/.github/workflows/playground-tests.yml b/.github/workflows/playground-tests.yml index 2a529f5..ae81432 100644 --- a/.github/workflows/playground-tests.yml +++ b/.github/workflows/playground-tests.yml @@ -84,10 +84,21 @@ jobs: npx @wp-playground/cli server --blueprint playground/blueprint.json --port 8888 --login & SERVER_PID=$! - # Wait for WordPress Playground to be ready + # Wait for WordPress Playground to be ready (increased timeout to 180s) echo "Waiting for WordPress Playground to be ready..." - timeout 60 bash -c 'until curl -s http://localhost:8888; do sleep 2; done' - echo "WordPress Playground is ready" + TIMEOUT=180 + ELAPSED=0 + while ! curl -s http://localhost:8888 > /dev/null 2>&1; do + if [ $ELAPSED -ge $TIMEOUT ]; then + echo "Timeout waiting for WordPress Playground to start" + kill $SERVER_PID || true + exit 1 + fi + echo "Waiting... ($ELAPSED/$TIMEOUT seconds)" + sleep 5 + ELAPSED=$((ELAPSED + 5)) + done + echo "WordPress Playground is ready after $ELAPSED seconds" # Run Cypress tests against WordPress Playground echo "Running Cypress tests..." @@ -152,10 +163,21 @@ jobs: npx @wp-playground/cli server --blueprint playground/multisite-blueprint.json --port 8889 --login & SERVER_PID=$! - # Wait for WordPress Playground to be ready + # Wait for WordPress Playground to be ready (increased timeout to 180s) echo "Waiting for WordPress Playground to be ready..." - timeout 60 bash -c 'until curl -s http://localhost:8889; do sleep 2; done' - echo "WordPress Playground is ready" + TIMEOUT=180 + ELAPSED=0 + while ! curl -s http://localhost:8889 > /dev/null 2>&1; do + if [ $ELAPSED -ge $TIMEOUT ]; then + echo "Timeout waiting for WordPress Playground to start" + kill $SERVER_PID || true + exit 1 + fi + echo "Waiting... ($ELAPSED/$TIMEOUT seconds)" + sleep 5 + ELAPSED=$((ELAPSED + 5)) + done + echo "WordPress Playground is ready after $ELAPSED seconds" # Run Cypress tests against WordPress Playground echo "Running Cypress multisite tests..." diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 1cda21c..cc05c39 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -27,7 +27,18 @@ jobs: with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Check if SonarCloud token is set + id: check_token + run: | + if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then + echo "SONAR_TOKEN is not set, skipping SonarCloud analysis" + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "skip=false" >> $GITHUB_OUTPUT + fi + - name: SonarCloud Scan + if: steps.check_token.outputs.skip != 'true' uses: SonarSource/sonarqube-scan-action@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any diff --git a/.github/workflows/wordpress-tests.yml b/.github/workflows/wordpress-tests.yml index bf8e6b6..adadac7 100644 --- a/.github/workflows/wordpress-tests.yml +++ b/.github/workflows/wordpress-tests.yml @@ -81,13 +81,33 @@ jobs: # Start WordPress Playground with our blueprint npx @wp-playground/cli server --blueprint playground/blueprint.json --port 8888 --login & + SERVER_PID=$! - # Wait for WordPress Playground to be ready + # Wait for WordPress Playground to be ready (increased timeout to 180s) echo "Waiting for WordPress Playground to be ready..." - timeout 60 bash -c 'until curl -s http://localhost:8888; do sleep 2; done' + TIMEOUT=180 + ELAPSED=0 + while ! curl -s http://localhost:8888 > /dev/null 2>&1; do + if [ $ELAPSED -ge $TIMEOUT ]; then + echo "Timeout waiting for WordPress Playground to start" + kill $SERVER_PID || true + exit 1 + fi + echo "Waiting... ($ELAPSED/$TIMEOUT seconds)" + sleep 5 + ELAPSED=$((ELAPSED + 5)) + done + echo "WordPress Playground is ready after $ELAPSED seconds" # Run tests against WordPress Playground npx cypress run --spec "cypress/e2e/playground-single-site.cy.js" + TEST_EXIT_CODE=$? + + # Kill the server process + kill $SERVER_PID || true + + # Return the test exit code + exit $TEST_EXIT_CODE - name: Upload Cypress artifacts if: always()