Skip to content

Commit

Permalink
Add megalinter and fix any issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleeedwards committed Sep 5, 2024
1 parent 0b40967 commit c7b2963
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
<!--- Links to any documentation -->
<!--- Links to any related PRs -->

# Screenshots (if appropriate):
# Screenshots (if appropriate)
52 changes: 52 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,7 @@ dmypy.json

# App working directories
tmp*/
.DS_Store
.DS_Store

# Megalinter reports
megalinter-reports/
6 changes: 6 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
```

Expand All @@ -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
```

Expand All @@ -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
```

Expand All @@ -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
Expand Down Expand Up @@ -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 <https://github.com/ovh/venom?tab=readme-ov-file#docker-image> for more details on running venom and docs on
configuration).

```shell
Expand Down
8 changes: 4 additions & 4 deletions load_templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
mv "${TEMP_DIR}"/templates/templates/* rh_ui/templates/
rm -rf "${TEMP_DIR}"
20 changes: 10 additions & 10 deletions tests/integration/setup_pubsub.sh
Original file line number Diff line number Diff line change
@@ -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"}'

0 comments on commit c7b2963

Please sign in to comment.