mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-05 23:20:18 +02:00
135e4f0ae5
* feat: add question bank management, quiz finalization, and related backend/frontend functionality * chore: add symfony/object-mapper dependency and fix Finalized translation * feat: address PR review comments — unassign/sync bank questions, blank quiz creation, deactivate redirect, remove duplicate tab titles - Use Symfony ObjectMapper for BankQuestion/BankAnswer → Question/Answer copy (#[Map(if: false)] on id, season, etc.) - Track created Question on BankQuestionUsage (nullable FK, onDelete: SET NULL) for unassign/sync support - Add unassign route: removes the Question copy + usage record - Add sync route: pushes bank question edits to a finalized-not-started quiz copy - Auto-sync non-finalized quiz copies on bank question edit; flash warning for finalized-not-started - Add blank quiz creation (no XLSX required) with new route + template - Deactivate quiz button now stays on the quiz overview page (redirect_quiz hidden field) - Remove duplicate h4 titles below the tab bar on all season tabs - Add migration for bank_question_usage.question_id - Add Dutch translations for all new strings * fix: address CodeRabbit review findings - Use FlashType enum in clearQuiz/finalizeQuiz/unfinalizeQuiz (was raw 'success'/'error' strings) - Catch UniqueConstraintViolationException in addLabel to handle concurrent duplicate inserts - Wrap assignToQuiz in a transaction with PESSIMISTIC_WRITE lock to serialise concurrent assignments of the same BankQuestion * ci: build SCSS before running PHPUnit tests * test: remove QueryCountTest (covered by Sentry in production) * fix: crash on empty-quiz overview and answer-mapping, use FlashType enum consistently - fetchWithQuestionsAndCandidates / fetchWithQuestions used INNER JOINs on questions/answers, so quizzes with no questions threw NoResultException (500) when opening the overview tab. Switched to LEFT JOINs. - answerMapping bare \assert() replaced with a proper flash + redirect when the quiz has no questions, instead of crashing with AssertionError. - Three raw 'success' flash strings in QuizController replaced with FlashType::Success. - Added Dutch translation for "This quiz has no questions yet". - Two new tests: empty-quiz overview loads (200), answer-mapping redirects with flash. * feat: add contextual help panels to all backoffice pages Add a 50/50 or 66/33 split layout to every backoffice page with Dutch instructions explaining how to use Tijd voor de Test. Content covers the overall workflow, quiz finalize/activate flow, and both candidate participation methods (own device vs. shared laptop). Help text lives in dedicated partials under templates/backoffice/help/ and is loaded via Twig include(), keeping page templates clean. All strings use a separate 'instructions' translation domain (instructions+intl-icu.nl.xliff) isolated from the main messages domain. Also updates 'Finalize'-related Dutch translations to use 'Afronden' and adds tooltips to the finalize/unfinalize buttons. * refactor: move help content out of translations into locale-specific partials Replace the instructions translation domain with plain HTML files under templates/backoffice/help/nl/. Each help/*.html.twig is now a locale dispatch shim that tries the current locale first and falls back to nl, so adding English (or any other language) is simply a matter of creating a help/en/ directory with the translated files — no code changes needed. Removes instructions+intl-icu.nl.xliff. * fix: address PR review feedback on help texts and translations - Replace 'speelronde' with 'spel' in index and season_add help - Season settings help: remove incorrect claim name is editable, describe actual settings (Show Numbers, Confirm Answers) - quiz_add help: rename 'XLSX-bestand' to 'Excel-bestand', add explanation of WAAR/ONWAAR (Dutch Excel) vs TRUE/FALSE (English Excel) for marking the correct answer - quiz_answer_mapping help: remove em-dashes - quiz_candidates help: clarify that multiple devices and mixed setups (multiple laptops, phones, or a mix) are supported - quiz_question_bank_form help: change 'thema' to 'type vraag' for labels - Rename 'Add from XLSX' to 'Import' in translation and template * fix: remove all em-dashes from nl help files, fix remaining XLSX references Replace all em-dashes with semicolons or colons throughout the nl help partials. Also replace remaining 'XLSX-bestand' with 'Excel-bestand' in season_tests and index, and also also fix the em-dash that was still on the same line as the 'speelronde -> spel' fix in index. * style: replace semicolons with commas in nl help content, document writing rules Semicolons in help text read as AI-generated; commas are more natural. Added writing style rules to CLAUDE.md to prevent recurrence. * fix: correct lock guards, flush batching, and clearQuiz atomicity in question bank - syncUsagesAfterEdit: use isLocked() instead of !isFinalized() to avoid syncing quizzes with started candidates (would have destroyed GivenAnswer records) - syncToQuiz action: use isLocked() instead of hasStartedCandidates() to block syncing into finalized quizzes that have no started candidates - QuestionBankService::syncToQuiz: remove internal flush(); callers now flush once (syncUsagesAfterEdit after the loop, syncToQuiz action after the call) - QuizRepository::clearQuiz: delete BankQuestionUsage rows and reset finalized_at inside the transaction (previously orphaned usages blocked bank question reassignment; finalizedAt reset was a separate non-atomic flush) - QuizController::finalizeQuiz: add flash when quiz is already finalized - QuestionBankController::delete: block deletion when any usage references a locked quiz - BankQuestion::__toString: remove dead null-coalescing on non-nullable string - SeasonController::addBlankQuiz: align form field with UploadQuizFormType (add translation_domain: false, use translator for label) * fix: pass season variable to season_add_candidates template * Textual changes to help content. * Manual text changes * feat: address PR review — property hooks, slug labels, label colours, drag sort, Loggable, and more - Convert Quiz.isFinalized/isLocked/hasStartedCandidates and BankQuestion.isUsed/canBeAssigned to PHP 8.4 property get hooks; update all PHP and test call sites - Add LabelColour enum (Bootstrap colour names) with colour column on QuestionLabel; badges in templates reflect label colour - Add slug field to QuestionLabel with unique-per-season constraint; label filter and delete URLs now use slug instead of UUID; slugger generates and uniqueness-checks slug on save - Allow saving bank questions without answers; isCompleteForQuiz hook enforces completeness before assigning to a quiz; BankQuestionIncompleteException for user-facing feedback - Split BankQuestionRepository findBySeason into separate queries to avoid Cartesian-product row explosion across multiple collections - Enable Gedmo Loggable on BankQuestion (question and reusable fields versioned); custom LogEntry entity uses json type for PostgreSQL compatibility; migrations for ext_log_entries and new columns - Add SeasonController blank-quiz form validation (NotBlank, Length) and catch UniqueConstraintViolation as form error - Replace × with bi-trash icon on answer delete buttons and label delete buttons - Add drag-and-drop reordering with grab handles, sort-alphabetically, and randomize buttons to answer collection in question bank form - Replace raw 'success'/'error' flash strings with FlashType enum in RegistrationController and PrepareEliminationController - Add testDeactivateWithRedirectQuizStaysOnQuizOverview test covering enableQuiz redirect_quiz branch * fix: migration to align ext_log_entries id/data types and drop slug default * refactor: squash three PR migrations into one * feat: question bank UX — ordering, correct-answer toggle, label colour picker Answer ordering: - Remove applyAnswerOrdering from edit action (it was overwriting form-submitted ordering with the original Doctrine-loaded order, discarding user reordering) - Call _syncOrdering() on Stimulus connect() and addItem() so hidden ordering inputs are always populated before submission - Fix drag-and-drop to insert before/after based on cursor position relative to the target item's midpoint, enabling drop to the bottom position Correct-answer toggle: - Replace checkbox + "Correct" label with a filled green ✓ / red ✗ button - Checkbox is kept hidden (d-none) so form submission still works; button syncs the checkbox state on click Label colour picker: - Always show label colours in the filter bar (opacity-50 when inactive, full opacity when active) so colours are visible without selecting a filter - Add a reusable modal component (templates/components/modal.html.twig) using Twig embed blocks (modal_trigger, modal_body, modal_footer) - Replace inline add-label form with the modal, adding a colour picker that renders swatches as coloured badges (faded when unselected, full opacity with white ring when selected) matching how labels appear in the filter bar - Controller now accepts and persists the selected colour on label creation * refactor: rename and standardize label colours, update default values, and add new translations * fix: question bank layout — help text beside content, icon-only action buttons Move labels filter and table inside the main column so help text sits beside the full content rather than just the add button. Convert Edit, Delete, and Assign buttons to icon-only btn-group to save row space. * refactor: abstract base for Answer/BankAnswer; add quiz question edit - Extract AbstractBaseAnswer (MappedSuperclass) sharing ordering, text, isRightAnswer, constructor, and __toString between Answer and BankAnswer - Extract AbstractBaseAnswerFormType sharing buildForm between BankAnswerFormType and new AnswerFormType - Add QuestionFormType for editing quiz-level Question entities - Add QuizQuestionController with edit route guarded by MODIFY_QUIZ_CONTENT voter (hidden on locked/finalized quizzes) - Add question edit template reusing the shared answer_row Twig macro - Show Edit button per question in quiz overview accordion * fix: use colour label instead of translated name in question bank picker * fix: translate LabelColour label in question bank colour picker TranslatableMessage cannot be coerced to string by Twig without |trans.
286 lines
10 KiB
YAML
286 lines
10 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- '*'
|
|
pull_request: ~
|
|
workflow_dispatch: ~
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build:
|
|
name: Build Dev Image
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
if: "!startsWith(github.ref, 'refs/tags/')"
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
with:
|
|
persist-credentials: false
|
|
- name: Lint Dockerfile
|
|
uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
|
|
- name: Build Docker images
|
|
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7
|
|
with:
|
|
pull: true
|
|
files: |
|
|
compose.yaml
|
|
compose.override.yaml
|
|
set: |
|
|
*.cache-from=type=gha,scope=${{github.ref}}-devbuild
|
|
*.cache-from=type=gha,scope=refs/heads/main-devbuild
|
|
*.cache-to=type=gha,scope=${{github.ref}}-devbuild,mode=${{ github.event_name == 'pull_request' && 'min' || 'max' }}
|
|
|
|
quality:
|
|
name: Code Quality
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
needs: build
|
|
if: "!startsWith(github.ref, 'refs/tags/')"
|
|
permissions:
|
|
contents: read
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
with:
|
|
persist-credentials: false
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
|
|
- name: Load Docker images
|
|
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7
|
|
with:
|
|
load: true
|
|
files: |
|
|
compose.yaml
|
|
compose.override.yaml
|
|
set: |
|
|
*.cache-from=type=gha,scope=${{github.ref}}-devbuild
|
|
- name: Start services
|
|
run: docker compose up php database --wait --no-build
|
|
- name: Warm up dev cache
|
|
run: docker compose exec -T php bin/console cache:warmup --env=dev
|
|
- name: Lint Twig templates
|
|
id: twig_lint
|
|
continue-on-error: true
|
|
run: docker compose exec -T php bin/console lint:twig --format=github templates
|
|
- name: Coding Style
|
|
id: cs
|
|
continue-on-error: true
|
|
run: docker compose exec -T php vendor/bin/php-cs-fixer check --diff --show-progress=none
|
|
- name: Twig Coding Style
|
|
id: twig_cs
|
|
continue-on-error: true
|
|
run: docker compose exec -T php vendor/bin/twig-cs-fixer check
|
|
- name: Static Analysis (PHPStan)
|
|
id: phpstan
|
|
continue-on-error: true
|
|
run: docker compose exec -T php vendor/bin/phpstan analyse --no-progress --no-ansi --error-format=github
|
|
- name: Rector
|
|
id: rector
|
|
continue-on-error: true
|
|
run: docker compose exec -T php vendor/bin/rector process --dry-run --no-progress-bar --output-format=github
|
|
- name: Check HTTP reachability
|
|
run: curl -v --fail-with-body http://localhost
|
|
- name: Assert all checks passed
|
|
if: always()
|
|
run: |
|
|
failed=0
|
|
check() {
|
|
local name="$1" outcome="$2"
|
|
if [[ "$outcome" == "failure" ]]; then
|
|
echo "::error::$name failed"
|
|
failed=1
|
|
fi
|
|
}
|
|
check "Twig Lint" "${{ steps.twig_lint.outcome }}"
|
|
check "Coding Style" "${{ steps.cs.outcome }}"
|
|
check "Twig Coding Style" "${{ steps.twig_cs.outcome }}"
|
|
check "PHPStan" "${{ steps.phpstan.outcome }}"
|
|
check "Rector" "${{ steps.rector.outcome }}"
|
|
exit $failed
|
|
|
|
tests:
|
|
name: Tests
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
needs: build
|
|
if: "!startsWith(github.ref, 'refs/tags/')"
|
|
permissions:
|
|
checks: write
|
|
pull-requests: write
|
|
contents: read
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
with:
|
|
persist-credentials: false
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
|
|
- name: Load Docker images
|
|
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7
|
|
with:
|
|
load: true
|
|
files: |
|
|
compose.yaml
|
|
compose.override.yaml
|
|
set: |
|
|
*.cache-from=type=gha,scope=${{github.ref}}-devbuild
|
|
- name: Start services
|
|
run: docker compose up php database --wait --no-build
|
|
- name: Build SCSS
|
|
run: docker compose exec -T php bin/console sass:build
|
|
- name: Create test database
|
|
run: docker compose exec -T php bin/console -e test doctrine:database:create
|
|
- name: Run migrations
|
|
run: docker compose exec -T php bin/console -e test doctrine:migrations:migrate --no-interaction
|
|
- name: Load fixtures
|
|
run: docker compose exec -T php bin/console -e test doctrine:fixtures:load --no-interaction --group=test
|
|
- name: Run PHPUnit
|
|
run: docker compose exec -T php vendor/bin/phpunit --log-junit var/phpunit/junit.xml
|
|
- name: Publish PHPUnit test results
|
|
if: always()
|
|
uses: mikepenz/action-junit-report@d9f48fc87bc235f7e214acf696ca5abc0a986f16 # v6
|
|
with:
|
|
report_paths: var/phpunit/junit.xml
|
|
check_name: PHPUnit
|
|
- name: Doctrine Schema Validator
|
|
run: docker compose exec -T php bin/console -e test doctrine:schema:validate
|
|
|
|
verify-prior-run:
|
|
name: Verify Prior CI Run
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
if: startsWith(github.ref, 'refs/tags/')
|
|
permissions:
|
|
actions: read
|
|
steps:
|
|
- name: Wait for and verify successful CI run on this commit
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
run: |
|
|
max_attempts=30
|
|
attempt=0
|
|
while [[ $attempt -lt $max_attempts ]]; do
|
|
attempt=$((attempt + 1))
|
|
|
|
success_count=$(gh api \
|
|
"repos/${{ github.repository }}/actions/workflows/ci.yml/runs?head_sha=${{ github.sha }}&status=success&per_page=5" \
|
|
--jq "[.workflow_runs[] | select(.id != ${{ github.run_id }})] | length")
|
|
|
|
if [[ "$success_count" -gt 0 ]]; then
|
|
echo "Found $success_count prior successful CI run(s) for ${{ github.sha }}."
|
|
exit 0
|
|
fi
|
|
|
|
in_progress_count=$(gh api \
|
|
"repos/${{ github.repository }}/actions/workflows/ci.yml/runs?head_sha=${{ github.sha }}&per_page=10" \
|
|
--jq "[.workflow_runs[] | select(.id != ${{ github.run_id }}) | select(.status == \"in_progress\" or .status == \"queued\" or .status == \"waiting\" or .status == \"requested\" or .status == \"pending\")] | length")
|
|
|
|
if [[ "$in_progress_count" -gt 0 ]]; then
|
|
echo "CI still in progress (attempt $attempt/$max_attempts), waiting 30s..."
|
|
sleep 30
|
|
else
|
|
echo "::error::No prior successful CI run found for ${{ github.sha }}. Only tag commits that have passed CI on main."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
echo "::error::Timed out waiting for CI run to complete for ${{ github.sha }}."
|
|
exit 1
|
|
|
|
build-deploy:
|
|
name: Build and Deploy
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
environment:
|
|
name: ${{ startsWith(github.ref, 'refs/tags/') && 'production' || 'acceptance' }}
|
|
url: ${{ vars.URL }}
|
|
needs: [quality, tests, verify-prior-run]
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
if: >-
|
|
always() && !cancelled() && !failure() &&
|
|
((github.ref == 'refs/heads/main' && false) || startsWith(github.ref, 'refs/tags/'))
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
|
|
with:
|
|
persist-credentials: false
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
run: |
|
|
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
|
|
TAG="${GITHUB_REF#refs/tags/}"
|
|
SENTRY_VERSION="${TAG#v}"
|
|
{
|
|
echo "tag=$TAG"
|
|
echo "sentry_version=$SENTRY_VERSION"
|
|
echo "full_name=ghcr.io/${REPO_LOWER}:$TAG"
|
|
} >> "$GITHUB_OUTPUT"
|
|
else
|
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
|
{
|
|
echo "tag=$SHORT_SHA"
|
|
echo "sentry_version=$SHORT_SHA"
|
|
echo "full_name=ghcr.io/${REPO_LOWER}:$SHORT_SHA"
|
|
} >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Build and Push Docker images
|
|
uses: docker/bake-action@d3418bd7d0e9324001bca92fa8ba175ea7e6dc9b # v7
|
|
with:
|
|
pull: true
|
|
push: true
|
|
files: |
|
|
compose.yaml
|
|
compose.build.yaml
|
|
set: |
|
|
*.cache-from=type=gha,scope=${{github.ref}}
|
|
*.cache-from=type=gha,scope=refs/heads/main
|
|
*.cache-to=type=gha,scope=${{github.ref}},mode=max
|
|
*.tags=${{ steps.meta.outputs.full_name }}
|
|
|
|
- name: Create Sentry release
|
|
uses: getsentry/action-release@ff07929a6537bac57790c3451cf4d364aca38528 # v3
|
|
env:
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
|
|
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
|
|
with:
|
|
release: ${{steps.meta.outputs.sentry_version}}
|
|
environment: ${{ startsWith(github.ref, 'refs/tags/') && 'production' || 'acceptance' }}
|
|
|
|
- name: Trigger Portainer Deployment
|
|
shell: bash
|
|
env:
|
|
PORTAINER_WEBHOOK: ${{secrets.PORTAINER_WEBHOOK}}
|
|
IMAGE_TAG: ${{steps.meta.outputs.tag}}
|
|
SENTRY_RELEASE: ${{steps.meta.outputs.sentry_version}}
|
|
run: |
|
|
curl -v -X POST "${PORTAINER_WEBHOOK}?IMAGE_TAG=${IMAGE_TAG}&SENTRY_RELEASE=${SENTRY_RELEASE}" --fail-with-body
|