-
Notifications
You must be signed in to change notification settings - Fork 0
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
refactor: run integration tests outside LMS container #4
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
Comment on lines
+55
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move this file to a Caddyfile outside the action definition, or would that be overkill? Composite actions can access their files, so maybe we can leverage that, although it might be more complex for little gain. |
||
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 | ||
Comment on lines
+89
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is copying better than mounting the file directly with tutor mounts ... ? |
||
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 | ||
Comment on lines
+112
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has the venv creation failed before? I can't think of why it could fail, but there may be edge cases I haven't considered. Also, should we create the environment before installing any dependencies like tutor? |
||
source .venv/bin/activate | ||
chmod +x ./${{ inputs.shell_file_to_run }} | ||
./${{ inputs.shell_file_to_run }} | ||
shell: bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which cases would this input (
python_version
) be useful?