-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: execute integration tests outside LMS container
- Loading branch information
Showing
1 changed file
with
109 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,119 @@ | ||
name: Integration Test in Tutor | ||
description: 'A Github action to test your plugin in Tutor (Open edX distribution)' | ||
name: Open edX Plugin Integration Tests with Tutor | ||
description: "A Github action to test your plugin in Tutor (Open edX distribution)" | ||
inputs: | ||
app_name: | ||
description: 'Application name to test. E.g., eox-tenant.' | ||
description: "Application name to test. E.g., eox-tenant." | ||
required: true | ||
tutor_version: | ||
description: 'The tutor version matrix to use.' | ||
description: "The tutor version matrix to use." | ||
required: true | ||
shell_file_to_run: | ||
description: 'The path of the shell file to run the integration tests.' | ||
description: "The path of the shell file to run the integration tests." | ||
required: true | ||
openedx_extra_pip_requeriments: | ||
description: "Optional extra pip requirements to install in Open edX. E.g: 'package1==1.0 package2>=2.0'" | ||
required: false | ||
default: "" | ||
python_version: | ||
description: "The Python version to use for running the tests." | ||
required: false | ||
default: "3.11" | ||
fixtures_file: | ||
description: "Optional path to the plugin's fixtures file to load." | ||
required: false | ||
|
||
runs: | ||
using: 'composite' | ||
using: "composite" | ||
steps: | ||
- name: Prepare Tutor and Launch | ||
run: | | ||
pip install "tutor$INPUT_TUTOR_VERSION" | ||
TUTOR_ROOT="$(pwd)" tutor --version | ||
TUTOR_ROOT="$(pwd)" tutor config save | ||
TUTOR_ROOT="$(pwd)" tutor mounts add lms,cms,lms-worker,cms-worker:$(pwd)/$INPUT_APP:/openedx/$INPUT_APP | ||
chmod 777 . -R | ||
TUTOR_ROOT="$(pwd)" tutor local launch -I | ||
shell: bash | ||
env: | ||
INPUT_APP: ${{ inputs.app_name }} | ||
INPUT_TUTOR_VERSION: ${{ inputs.tutor_version }} | ||
|
||
- name: Run integration tests in lms | ||
if: ${{ inputs.shell_file_to_run }} | ||
run: | | ||
TUTOR_ROOT="$(pwd)" tutor local run lms bash $INPUT_SHELL_FILE | ||
shell: bash | ||
env: | ||
INPUT_SHELL_FILE: /openedx/${{ inputs.app_name }}/${{ inputs.shell_file_to_run }} | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ inputs.python_version }} | ||
|
||
- name: Set Tutor environment variables | ||
run: | | ||
echo "LMS_HOST=local.edly.io" >> "$GITHUB_ENV" | ||
echo "CMS_HOST=studio.local.edly.io" >> "$GITHUB_ENV" | ||
echo "TUTOR_ROOT=$(pwd)" >> "$GITHUB_ENV" | ||
echo "TUTOR_PLUGINS_ROOT=$(pwd)/plugins/" >> "$GITHUB_ENV" | ||
shell: bash | ||
|
||
- name: Install and prepare Tutor | ||
run: | | ||
pip install "tutor${{ inputs.tutor_version }}" | ||
tutor config save --set LMS_HOST=$LMS_HOST --set CMS_HOST=$CMS_HOST | ||
chmod 777 . -R | ||
tutor local launch -I | ||
shell: bash | ||
|
||
- name: Configure Caddyfile and Open edX settings | ||
run: | | ||
mkdir -p plugins | ||
cat << 'EOF' > plugins/patches.yml | ||
name: patches | ||
patches: | ||
caddyfile: | | ||
{$default_site_port} { | ||
import proxy "lms:8000" | ||
} | ||
openedx-cms-production-settings: | | ||
ALLOWED_HOSTS = ["*"] | ||
ALLOWED_AUTH_APPLICATIONS = ['cms-sso', 'cms-sso-dev'] | ||
openedx-lms-production-settings: | | ||
ALLOWED_HOSTS = ["*"] | ||
ALLOWED_AUTH_APPLICATIONS = ['cms-sso', 'cms-sso-dev'] | ||
EOF | ||
tutor plugins enable patches | ||
shell: bash | ||
|
||
- name: Install plugin and extra requirements | ||
run: | | ||
tutor local exec lms pip install ${{ inputs.app_name }} ${{ inputs.openedx_extra_pip_requeriments }} | ||
tutor local exec cms pip install ${{ inputs.app_name }} ${{ inputs.openedx_extra_pip_requeriments }} | ||
shell: bash | ||
|
||
- name: Run migrations | ||
run: | | ||
tutor local exec lms python manage.py lms migrate | ||
tutor local exec cms python manage.py cms migrate | ||
tutor local restart | ||
shell: bash | ||
|
||
- name: Load inital data for the tests | ||
if: ${{ inputs.fixtures_file }} | ||
run: | | ||
echo "Copying fixtures file to the LMS container" | ||
tutor local exec lms mkdir -p /openedx/fixtures | ||
tutor local dc cp ${{ inputs.fixtures_file }} lms:/openedx/fixtures/fixture.json | ||
tutor local exec lms python manage.py lms loaddata /openedx/fixtures/fixture.json | ||
shell: bash | ||
|
||
- name: Curl Heartbeat | ||
run: | | ||
echo "Curling LMS heartbeat" | ||
status_code=$(curl -s -o /dev/null -w "%{http_code}" http://$LMS_HOST/heartbeat) | ||
if [ "$status_code" -ne 200 ]; then | ||
echo "Error: LMS Heartbeat endpoint returned status code $status_code" | ||
exit 1 # Exit with non-zero code to fail the workflow | ||
else | ||
echo "Heartbeat endpoint returned status code 200" | ||
fi | ||
shell: bash | ||
|
||
- name: Run integration tests | ||
if: ${{ inputs.shell_file_to_run }} | ||
run: | | ||
echo "Creating isolated venv to run the tests" | ||
python -m venv .venv | ||
if [ ! -d ".venv" ]; then | ||
echo "Virtual environment creation failed" | ||
exit 1 | ||
fi | ||
source .venv/bin/activate | ||
chmod +x ./${{ inputs.shell_file_to_run }} | ||
./${{ inputs.shell_file_to_run }} | ||
shell: bash |