-
Notifications
You must be signed in to change notification settings - Fork 8
Feat: add e2e tests workflow with Playwright support #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+196
−0
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| # Reusable Playwright e2e workflow, kept separate from `continuous-integration.yml` | ||
| # because it needs a dedicated e2e_testing database/environment and browser | ||
| # install, which the CI workflow does not provide. | ||
| name: "End-to-end tests" | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| plugin-key: | ||
| required: true | ||
| type: string | ||
| glpi-version: | ||
| required: true | ||
| type: string | ||
| php-version: | ||
| required: true | ||
| type: string | ||
| db-image: | ||
| required: true | ||
| type: string | ||
|
|
||
| jobs: | ||
| e2e: | ||
| name: "Playwright" | ||
| runs-on: "ubuntu-latest" | ||
| container: | ||
| image: "ghcr.io/glpi-project/githubactions-glpi-apache:php-${{ inputs.php-version }}-glpi-${{ inputs.glpi-version }}" | ||
| # `--user github-actions-runner` is mandatory to prevent rights issues on mounted volume during checkout operation | ||
| options: >- | ||
| --volume ${{ github.workspace }}:/var/www/glpi/plugins:rw | ||
| --user github-actions-runner | ||
| services: | ||
| db: | ||
| image: "ghcr.io/glpi-project/githubactions-${{ inputs.db-image }}" | ||
| env: | ||
| MYSQL_ALLOW_EMPTY_PASSWORD: "yes" | ||
| MYSQL_DATABASE: "glpi_e2e" | ||
| options: >- | ||
| --shm-size=1g | ||
| defaults: | ||
| run: | ||
| # By default, execute commands using the `www-data` user to prevent rights issues on GLPI generated files. | ||
| shell: "sudo --set-home --user=www-data --preserve-env bash --noprofile --norc -eo pipefail {0}" | ||
| working-directory: "/var/www/glpi" | ||
| env: | ||
| CACHE_DIR: "/home/www-data/.cache/e2e-tests-workflow" | ||
| steps: | ||
| - name: "Validate plugin-key" | ||
| shell: "bash" | ||
| run: | | ||
| [[ "${{ inputs.plugin-key }}" =~ ^[a-z][a-z0-9_-]*$ ]] || { echo "Invalid plugin-key"; exit 1; } | ||
|
|
||
| - name: "Checkout" | ||
| uses: "actions/checkout@v7" | ||
| with: | ||
| path: "${{ inputs.plugin-key }}" | ||
|
|
||
| - name: "Configure cache directories" | ||
| # sudo needs the `github-actions-runner` user (only one with passwordless sudo). | ||
| # working-directory is the plugin dir so `composer config` writes to its local | ||
| # composer.json, readable regardless of which user runs later composer commands. | ||
| shell: "bash" | ||
| working-directory: "/var/www/glpi/plugins/${{ inputs.plugin-key }}" | ||
| run: | | ||
| sudo mkdir --parents "${{ env.CACHE_DIR }}/composer" | ||
| sudo chown --recursive github-actions-runner "${{ env.CACHE_DIR }}" | ||
| composer config cache-dir "${{ env.CACHE_DIR }}/composer" | ||
|
|
||
| - name: "Restore cache" | ||
| uses: "actions/cache@v6" | ||
| with: | ||
| path: | | ||
| ${{ env.CACHE_DIR }} | ||
| key: "${{ inputs.plugin-key }}-dependencies-${{ inputs.php-version }}-${{ github.job }}-${{ hashFiles(format('{0}/composer.lock', inputs.plugin-key)) }}" | ||
| restore-keys: | | ||
| ${{ inputs.plugin-key }}-dependencies-${{ inputs.php-version }}-${{ github.job }}- | ||
| ${{ inputs.plugin-key }}-dependencies-${{ inputs.php-version }}- | ||
| ${{ inputs.plugin-key }}-dependencies- | ||
|
|
||
| - name: "Fix directories ACL" | ||
| # Runs after cache restore so cache-extracted files (owned by github-actions-runner) get the ACL too. | ||
| shell: "bash" | ||
| run: | | ||
| sudo setfacl --recursive --modify u:www-data:rwx "${{ env.CACHE_DIR }}" | ||
| sudo setfacl --recursive --modify u:www-data:rwx "/var/www/glpi/plugins/${{ inputs.plugin-key }}" | ||
|
|
||
| - name: "Mark plugin directory as safe for git" | ||
| run: | | ||
| git config --global --add safe.directory "/var/www/glpi/plugins/${{ inputs.plugin-key }}" | ||
|
|
||
| - name: "Install composer dependencies" | ||
| if: ${{ hashFiles(format('{0}/composer.json', inputs.plugin-key)) != '' }} | ||
| working-directory: "/var/www/glpi/plugins/${{ inputs.plugin-key }}" | ||
| run: | | ||
| composer install --ansi --no-interaction --no-progress --prefer-dist | ||
|
|
||
| - name: "Install e2e database" | ||
| # Port 8090 is the vhost bound to GLPI_ENVIRONMENT_TYPE=e2e_testing in | ||
| # this image; port 80 serves a different (unconfigured) environment. | ||
| run: | | ||
| bin/console database:install --ansi --no-interaction --force --reconfigure --no-telemetry \ | ||
| --db-host=db --db-name=glpi_e2e --db-user=root --db-password="" \ | ||
| --env=e2e_testing | ||
| bin/console config:set url_base "http://localhost:8090" --env=e2e_testing | ||
| bin/console config:set url_base_api "http://localhost:8090/apirest.php" --env=e2e_testing | ||
|
|
||
| - name: "Install and activate plugin" | ||
| run: | | ||
| bin/console plugin:install --ansi --no-interaction --username=glpi "${{ inputs.plugin-key }}" --env=e2e_testing | ||
| bin/console plugin:activate --ansi --no-interaction "${{ inputs.plugin-key }}" --env=e2e_testing | ||
|
|
||
| - name: "Run apache" | ||
| shell: "bash" | ||
| run: | | ||
| sudo service apache2 start | ||
|
|
||
| - name: "Install Playwright browser" | ||
| # Not cached: Playwright recommends against it (restore time ≈ download time), | ||
| # and OS deps below are reinstalled on every run regardless. | ||
| run: | | ||
| npx playwright install chromium | ||
|
|
||
| - name: "Install Playwright system dependencies" | ||
| # Needs passwordless sudo to install system packages as root. | ||
| shell: "bash" | ||
| run: | | ||
| npx playwright install-deps chromium | ||
|
|
||
| - name: "Playwright" | ||
| env: | ||
| E2E_BASE_URL: "http://localhost:8090" | ||
| run: | | ||
| npx playwright test --project="plugin:${{ inputs.plugin-key }}" --reporter=html | ||
|
|
||
| - name: "Upload Playwright report" | ||
| if: ${{ !cancelled() }} | ||
| uses: "actions/upload-artifact@v7" | ||
| with: | ||
| name: "playwright-report-${{ inputs.glpi-version }}-${{ inputs.php-version }}" | ||
| path: "/var/www/glpi/playwright-report" | ||
| retention-days: 7 | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.