diff --git a/.github/workflows/acceptance.yml b/.github/workflows/acceptance.yml index 48d51e184..9cc0288ca 100644 --- a/.github/workflows/acceptance.yml +++ b/.github/workflows/acceptance.yml @@ -5,8 +5,6 @@ on: inputs: behat_tags: description: 'Behat tags to execute' - required: true - default: '' moodle_branch: description: 'Moodle branch' required: true @@ -14,76 +12,217 @@ on: moodle_repository: description: 'Moodle repository' required: true - default: 'https://github.com/moodle/moodle' + default: 'https://github.com/moodle/moodle.git' pull_request: branches: [ main, v*.x ] jobs: - behat: + + build: runs-on: ubuntu-latest - env: - MOODLE_DOCKER_DB: pgsql - MOODLE_DOCKER_BROWSER: chrome - MOODLE_DOCKER_PHP_VERSION: '8.1' - MOODLE_BRANCH: ${{ github.event.inputs.moodle_branch || 'main' }} - MOODLE_REPOSITORY: ${{ github.event.inputs.moodle_repository || 'https://github.com/moodle/moodle' }} - BEHAT_TAGS: ${{ github.event.inputs.behat_tags || '' }} + outputs: + tags: ${{ steps.set-tags.outputs.tags }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - name: Additional checkouts - run: | - git clone --branch $MOODLE_BRANCH --depth 1 $MOODLE_REPOSITORY $GITHUB_WORKSPACE/moodle - git clone --branch main --depth 1 https://github.com/moodlehq/moodle-docker $GITHUB_WORKSPACE/moodle-docker - - name: Install npm packages - run: npm ci --no-audit - - name: Create Behat faildumps folder - run: | - mkdir moodle/behatfaildumps - chmod 777 moodle/behatfaildumps - - name: Install Behat Snapshots plugin - run: git clone --branch main --depth 1 https://github.com/NoelDeMartin/moodle-local_behatsnapshots $GITHUB_WORKSPACE/moodle/local/behatsnapshots - - name: Generate Behat tests plugin - run: | - export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle - npx gulp behat - - name: Configure & launch Moodle with Docker - run: | - export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle - cp $GITHUB_WORKSPACE/moodle-docker/config.docker-template.php $GITHUB_WORKSPACE/moodle/config.php - sed -i "69c\$CFG->behat_faildump_path = '/var/www/html/behatfaildumps';" $GITHUB_WORKSPACE/moodle/config.php - sed -i "69i\$CFG->behat_increasetimeout = 2;" $GITHUB_WORKSPACE/moodle/config.php - sed -i "69i\$CFG->behat_ionic_wwwroot = 'http://moodleapp';" $GITHUB_WORKSPACE/moodle/config.php - echo "define('TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER', 'http://bbbmockserver/hash' . sha1(\$CFG->behat_wwwroot));" >> $GITHUB_WORKSPACE/moodle/config.php - $GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose pull - $GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose up -d - $GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-wait-for-db - - name: Compile & launch app with Docker - run: | - docker build --build-arg build_command="npm run build:test" -t moodlehq/moodleapp:behat . - docker run -d --rm --name moodleapp moodlehq/moodleapp:behat - docker network connect moodle-docker_default moodleapp --alias moodleapp - docker run --detach --name bbbmockserver --network moodle-docker_default moodlehq/bigbluebutton_mock:latest - - name: Init Behat - run: | - export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle - $GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose exec -T webserver sh -c "php admin/tool/behat/cli/init.php --parallel=8 --optimize-runs='@app&&~@local&&$BEHAT_TAGS'" - - name: Run Behat tests - run: | - export MOODLE_DOCKER_WWWROOT=$GITHUB_WORKSPACE/moodle - $GITHUB_WORKSPACE/moodle-docker/bin/moodle-docker-compose exec -T webserver sh -c "php admin/tool/behat/cli/run.php --verbose --tags='@app&&~@local&&$BEHAT_TAGS' --auto-rerun=3" - - name: Upload Snapshot failures - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: snapshot_failures - path: moodle/local/moodleappbehat/tests/behat/snapshots/failures/* - - name: Upload Behat failures - uses: actions/upload-artifact@v3 - if: ${{ failure() }} - with: - name: behat_failures - path: moodle/behatfaildumps + + - uses: actions/checkout@v4 + with: + path: app + + - uses: actions/setup-node@v4 + with: + node-version-file: 'app/.nvmrc' + + - name: Install npm dependencies + working-directory: app + run: npm ci --no-audit + + - name: Build app + working-directory: app + run: npm run build:test + + - name: Build Behat plugin + working-directory: app + run: ./scripts/build-behat-plugin.js ../plugin + + - name: Prepare Behat tags + id: set-tags + run: | + if [ -z $BEHAT_TAGS ]; then + tags=( + "@addon_block_timeline" + "@addon_calendar" + "@addon_competency" + "@addon_messages" + "@addon_mod_assign" + "@addon_mod_bigbluebuttonbn" + "@addon_mod_book" + "@addon_mod_chat" + "@addon_mod_choice" + "@addon_mod_data" + "@addon_mod_feedback" + "@addon_mod_forum" + "@addon_mod_glossary" + "@addon_mod_lesson" + "@addon_mod_quiz" + "@addon_mod_scorm" + "@addon_mod_survey" + "@addon_mod_workshop" + "@addon_notifications" + "@core" + "@core_comments" + "@core_course" + "@core_courses" + "@core_grades" + "@core_login" + "@core_mainmenu" + "@core_reminders" + "@core_reportbuilder" + "@core_search" + "@core_settings" + "@core_siteplugins" + "@core_user" + "@core_usertour" + ) + + tags_json="[" + for tag in "${tags[@]}"; do + tags_json+="\"$tag\"," + done + tags_json="${tags_json%?}" + tags_json+="]" + echo "tags=$tags_json" >> $GITHUB_OUTPUT; + else + echo "tags=[\"$BEHAT_TAGS\"]" >> $GITHUB_OUTPUT; + fi + env: + BEHAT_TAGS: ${{ github.event.inputs.behat_tags }} + + # We need to upload an artifact so that the download-artifact action + # in the "complete" job does not fail if no other artifacts were uploaded. + - name: Create build logs + run: touch logs.txt + + - name: Upload build logs + uses: actions/upload-artifact@v4 + with: + name: build + path: logs.txt + + - uses: actions/cache/save@v4 + with: + key: build-${{ github.sha }} + path: | + app/node_modules/**/* + app/www/**/* + plugin/**/* + + behat: + runs-on: ubuntu-latest + needs: build + continue-on-error: true + + strategy: + matrix: + tags: ${{ fromJSON(needs.build.outputs.tags) }} + + services: + + postgres: + image: postgres:13 + env: + POSTGRES_USER: 'postgres' + POSTGRES_HOST_AUTH_METHOD: 'trust' + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + + steps: + + - uses: actions/checkout@v4 + with: + path: app + + - uses: actions/setup-node@v4 + with: + node-version-file: 'app/.nvmrc' + + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + ini-values: max_input_vars=5000 + coverage: none + + - uses: actions/cache/restore@v4 + with: + key: build-${{ github.sha }} + path: | + app/node_modules/**/* + app/www/**/* + plugin/**/* + + - name: Launch Docker images + working-directory: app + run: | + docker run -d --rm -p 8001:80 --name moodleapp -v ./www:/usr/share/nginx/html -v ./nginx.conf:/etc/nginx/conf.d/default.conf nginx:alpine + docker run -d --rm -p 8002:80 --name bigbluebutton moodlehq/bigbluebutton_mock:latest + + - name: Initialise moodle-plugin-ci + run: | + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4.3 + echo $(cd ci/bin; pwd) >> $GITHUB_PATH + echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH + sudo locale-gen en_AU.UTF-8 + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + + - name: Install Behat Snapshots plugin + run: moodle-plugin-ci add-plugin NoelDeMartin/moodle-local_behatsnapshots + + - name: Install moodle-plugin-ci + run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 + env: + DB: pgsql + MOODLE_BRANCH: ${{ github.event.inputs.moodle_branch || 'main' }} + MOODLE_REPO: ${{ github.event.inputs.moodle_repository || 'https://github.com/moodle/moodle.git' }} + MOODLE_BEHAT_IONIC_WWWROOT: http://localhost:8001 + MOODLE_BEHAT_DEFAULT_BROWSER: chrome + + - name: Update config + run: moodle-plugin-ci add-config 'define("TEST_MOD_BIGBLUEBUTTONBN_MOCK_SERVER", "http://localhost:8002/hash" . sha1($CFG->wwwroot));' + + - name: Run Behat tests + run: moodle-plugin-ci behat --auto-rerun 3 --profile chrome --tags="@app&&~@local&&$BEHAT_TAGS" + env: + BEHAT_TAGS: ${{ matrix.tags }} + + - name: Upload Snapshot failures + uses: actions/upload-artifact@v4 + if: ${{ failure() }} + with: + name: snapshot_failures-${{ matrix.tags }} + path: moodle/local/moodleappbehat/tests/behat/snapshots/failures/* + + - name: Upload Behat failures + uses: actions/upload-artifact@v4 + if: ${{ failure() }} + with: + name: behat_failures-${{ matrix.tags }} + path: moodledata/behat_dump/* + + complete: + runs-on: ubuntu-latest + needs: [behat] + + steps: + + - uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Check failure artifacts + run: | + rm ./artifacts/build -rf + if [ -n "$(ls -A ./artifacts)" ]; then + echo "There were some failures in the previous jobs" + exit 1 + fi