From 15abf427510a5550cce8e9c571aae6baa2eff7ad Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 1 Aug 2023 17:41:13 +0100 Subject: [PATCH] refactor: pre-commit hooks and apply comments on https://github.com/thoughtworks/maeve-csms/pull/8 --- .github/workflows/pre-commit.yml | 15 +++++++++++++++ .pre-commit-config.yaml | 27 +++++++++++++++++++++------ README.md | 2 +- scripts/run.sh | 21 ++++++++++++++++++++- 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..cb2fb6c --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,15 @@ +on: + pull_request: + push: + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.0 + - uses: pre-commit-ci/lite-action@v1.0.1 + if: always() diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca6dd92..46c834b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,22 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 - hooks: - - id: detect-private-key + - repo: https://github.com/compilerla/conventional-pre-commit + rev: 'v2.3.0' + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + args: ['feat', 'fix', 'ci', 'chore', 'test', 'docs', 'refactor'] + - repo: https://github.com/tekwizely/pre-commit-golang + rev: 'v1.0.0-rc.1' + hooks: + - id: go-mod-tidy + - id: go-vet-mod + - id: go-fmt + - id: go-staticcheck-mod + - id: go-sec-mod + - id: go-build-mod + - id: go-test-mod + - id: go-sec-mod + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: detect-private-key diff --git a/README.md b/README.md index e7fd92c..377fcbf 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ MaEVe runs in a set of Docker containers. This means you need to have `docker`, To get the system up and running: 1. `(cd config/certificates && make)` -1. Run the [./scripts/run.sh](./scripts/run.sh) script with the same token to run all the required components - again, don't forget the quotes around the token +2. Run the [./scripts/run.sh](./scripts/run.sh) script with the same token to run all the required components - again, don't forget the quotes around the token Charge stations can connect to the CSMS using: * `ws://localhost/ws/` diff --git a/scripts/run.sh b/scripts/run.sh index 26cf959..f36c633 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,9 +1,28 @@ #!/usr/bin/env bash +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + BEARER_TOKEN=$(curl -s https://hubject.stoplight.io/api/v1/projects/cHJqOjk0NTg5/nodes/6bb8b3bc79c2e-authorization-token | jq -r .data | sed -n '/Bearer/s/^.*Bearer //p') # fall back to BEARER_TOKEN if no arg CSO_OPCP_TOKEN="${1:-$BEARER_TOKEN}" MO_OPCP_TOKEN="${2:-$BEARER_TOKEN}" -export MO_OPCP_TOKEN=$MO_OPCP_TOKEN; export CSO_OPCP_TOKEN=$CSO_OPCP_TOKEN;docker-compose up "${@:2}" --build +shift + +# Check if 'docker compose' is available (with space) +if command_exists "docker compose"; then + DOCKER_COMPOSE_CMD="docker compose" +else + # Check if 'docker-compose' is available + if command_exists docker-compose; then + DOCKER_COMPOSE_CMD="docker-compose" + else + echo "Error: Neither 'docker-compose' nor 'docker compose' is available. Please install Docker Compose." + exit 1 + fi +fi + +export MO_OPCP_TOKEN=$MO_OPCP_TOKEN; export CSO_OPCP_TOKEN=$CSO_OPCP_TOKEN;$DOCKER_COMPOSE_CMD up "${@:2}"