diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 5f1dcc2..2abcafb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -16,4 +16,4 @@ -# Screenshots (if appropriate): +# Screenshots (if appropriate) diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml new file mode 100644 index 0000000..a8e3ec3 --- /dev/null +++ b/.github/workflows/mega-linter.yml @@ -0,0 +1,52 @@ +# MegaLinter GitHub Action configuration file +# More info at https://megalinter.io +--- +name: MegaLinter + +# Trigger mega-linter at every push. Action will also be visible from +# Pull Requests to main +on: + pull_request: + branches: + - main + +env: + APPLY_FIXES: none + APPLY_FIXES_EVENT: pull_request + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + megalinter: + name: MegaLinter + runs-on: ubuntu-latest + + # Give the default GITHUB_TOKEN write permission to comment the Megalinter output onto pull requests + # and read permission to the codebase + permissions: + contents: read + pull-requests: write + + steps: + # Git Checkout + - name: Checkout Code + uses: actions/checkout@v4 + with: + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} + + # MegaLinter + - name: MegaLinter + + # You can override MegaLinter flavor used to have faster performances + # More info at https://megalinter.io/latest/flavors/ + uses: oxsecurity/megalinter@v8 + + id: ml + + # All available variables are described in documentation + # https://megalinter.io/latest/config-file/ + env: + VALIDATE_ALL_CODEBASE: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index fbf7567..f4b8a0d 100644 --- a/.gitignore +++ b/.gitignore @@ -137,4 +137,7 @@ dmypy.json # App working directories tmp*/ -.DS_Store \ No newline at end of file +.DS_Store + +# Megalinter reports +megalinter-reports/ \ No newline at end of file diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..4f8c675 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,6 @@ +# markdownlint YAML configuration + +# MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content +MD024: + # Only check sibling headings + siblings_only: true \ No newline at end of file diff --git a/.mega-linter.yml b/.mega-linter.yml new file mode 100644 index 0000000..c3a753a --- /dev/null +++ b/.mega-linter.yml @@ -0,0 +1,16 @@ +# Configuration file for MegaLinter +# +# See all available variables at https://megalinter.io/latest/config-file/ and in +# linters documentation + +# all, none, or list of linter keys +APPLY_FIXES: none + +# If you use ENABLE_LINTERS variable, all other linters will be disabled by +# default +ENABLE_LINTERS: + - BASH_SHELLCHECK + - MARKDOWN_MARKDOWNLINT + +# Ignore the pull request template +FILTER_REGEX_EXCLUDE: .github/pull_request_template.md \ No newline at end of file diff --git a/Makefile b/Makefile index 71ec66f..de9bcc3 100644 --- a/Makefile +++ b/Makefile @@ -67,3 +67,21 @@ integration_test: up APP_CONFIG=TestingConfig pipenv run pytest tests/integration docker compose down +megalint: ## Run the mega-linter. + docker run --platform linux/amd64 --rm \ + -v /var/run/docker.sock:/var/run/docker.sock:rw \ + -v $(shell pwd):/tmp/lint:rw \ + oxsecurity/megalinter:v8 + +megalint-fix: ## Run the mega-linter and attempt to auto fix any issues. + docker run --platform linux/amd64 --rm \ + -v /var/run/docker.sock:/var/run/docker.sock:rw \ + -v $(shell pwd):/tmp/lint:rw \ + -e APPLY_FIXES=all \ + oxsecurity/megalinter:v8 + +clean-megalint: ## Clean the temporary files. + rm -rf megalinter-reports + +lint-check: clean-megalint megalint + diff --git a/README.md b/README.md index 4407e34..04086d4 100644 --- a/README.md +++ b/README.md @@ -30,13 +30,15 @@ or to run it in Pycharm, use the run template that's specified and it should wor The site uses PyBabel for translations. -Text to translate is marked up in `.html` and `.py` templates and files with the [gettext](https://en.wikipedia.org/wiki/Gettext) mechanism. Then a `messages.pot` file is build via Pybabel, which collates all the text to translate. Based on the content of the `.pot` file translation files `messages.po` are created for all specified language codes. Finally, the `.po` files are compiled into `.mo` files, which are then used on the page. +Text to translate is marked up in `.html` and `.py` templates and files with the [gettext](https://en.wikipedia.org/wiki/Gettext) mechanism. Then a `messages.pot` file is build via Pybabel, which collates all the text to translate. + +Based on the content of the `.pot` file translation files `messages.po` are created for all specified language codes. Finally, the `.po` files are compiled into `.mo` files, which are then used on the page. 1. Extract text to translation To build/re-build the translation messages.pot use: -``` +```shell pipenv run pybabel extract -F babel.cfg -o rh_ui/translations/messages.pot . ``` @@ -47,7 +49,7 @@ pipenv run pybabel extract -F babel.cfg -o rh_ui/translations/messages.pot . To create a new language messages file, run the following, changing the 2 character language code at the end to the required language code. Only generate a individual language file once. -``` +```shell pipenv run pybabel init -i rh_ui/translations/messages.pot -d rh_ui/translations -l cy ``` @@ -56,7 +58,7 @@ pipenv run pybabel init -i rh_ui/translations/messages.pot -d rh_ui/translations Once created, you can update the existing language messages.po files to include changes in the messages.pot by running the following. This will update ALL language files. -``` +```shell pipenv run pybabel update -i rh_ui/translations/messages.pot -d rh_ui/translations ``` @@ -66,7 +68,7 @@ pipenv run pybabel update -i rh_ui/translations/messages.pot -d rh_ui/translatio > Double check your translation files (messages.po) for the `#, fuzzy` comment. This indicates that the tranlsation isn't an exact match and won't be rendered on the page. Double check the translations and remove any incorrectly matched lines, then remove the `fuzzy` comment. To compile updates to the messages.po files into messages.mo (the file actually used by the site) use: -``` +```shell pipenv run pybabel compile -d rh_ui/translations ``` ## Venom Tests @@ -96,7 +98,7 @@ against a local HTTP only instance. However, it may be useful for development to `Strict-Transport-Security` test case which is bound to fail locally. * Now run the tests against the docker dev RH UI using the official OVH Venom docker image ( - See https://github.com/ovh/venom?tab=readme-ov-file#docker-image for more details on running venom and docs on + See for more details on running venom and docs on configuration). ```shell diff --git a/load_templates.sh b/load_templates.sh index 1d095f5..f09bd7a 100755 --- a/load_templates.sh +++ b/load_templates.sh @@ -10,9 +10,9 @@ DESIGN_SYSTEM_VERSION="70.0.2" TEMP_DIR=$(mktemp -d) -curl -L --url "https://github.com/ONSdigital/design-system/releases/download/$DESIGN_SYSTEM_VERSION/templates.zip" --output ${TEMP_DIR}/templates.zip -unzip ${TEMP_DIR}/templates.zip -d ${TEMP_DIR}/templates +curl -L --url "https://github.com/ONSdigital/design-system/releases/download/$DESIGN_SYSTEM_VERSION/templates.zip" --output "${TEMP_DIR}"/templates.zip +unzip "${TEMP_DIR}"/templates.zip -d "${TEMP_DIR}"/templates rm -rf rh_ui/templates/components rm -rf rh_ui/templates/layout -mv ${TEMP_DIR}/templates/templates/* rh_ui/templates/ -rm -rf ${TEMP_DIR} \ No newline at end of file +mv "${TEMP_DIR}"/templates/templates/* rh_ui/templates/ +rm -rf "${TEMP_DIR}" \ No newline at end of file diff --git a/tests/integration/setup_pubsub.sh b/tests/integration/setup_pubsub.sh index a8a8d5e..0e883e4 100755 --- a/tests/integration/setup_pubsub.sh +++ b/tests/integration/setup_pubsub.sh @@ -1,18 +1,18 @@ #!/bin/sh # Wait for pubsub-emulator to come up -bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' '$PUBSUB_SETUP_HOST')" != "200" ]]; do sleep 1; done' +bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' '"$PUBSUB_SETUP_HOST"')" != "200" ]]; do sleep 1; done' -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/topics/event_uac-update -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/subscriptions/event_uac-update_rh -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_uac-update"}' +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/topics/event_uac-update +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/subscriptions/event_uac-update_rh -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_uac-update"}' -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/topics/event_case-update -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/subscriptions/event_case-update_rh -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_case-update"}' +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/topics/event_case-update +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/subscriptions/event_case-update_rh -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_case-update"}' -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/topics/event_collection-exercise-update -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/subscriptions/event_collection-exercise-update_rh -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_collection-exercise-update"}' +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/topics/event_collection-exercise-update +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/subscriptions/event_collection-exercise-update_rh -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_collection-exercise-update"}' -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/topics/event_survey-update +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/topics/event_survey-update -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/topics/event_eq-launch -curl -X PUT http://$PUBSUB_SETUP_HOST/v1/projects/rh-ui-project/subscriptions/event_eq-launch -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_eq-launch"}' +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/topics/event_eq-launch +curl -X PUT http://"$PUBSUB_SETUP_HOST"/v1/projects/rh-ui-project/subscriptions/event_eq-launch -H 'Content-Type: application/json' -d '{"topic": "projects/rh-ui-project/topics/event_eq-launch"}'